Skip to content

Commit

Permalink
[lli/COFF] Set the correct alignment for common symbols
Browse files Browse the repository at this point in the history
Otherwise we set it always to zero, which is not correct,
and we assert inside alignTo (Assertion failed:
Align != 0u && "Align can't be 0.").

Differential Revision:  https://reviews.llvm.org/D26173

llvm-svn: 285841
  • Loading branch information
dcci committed Nov 2, 2016
1 parent bf9ee26 commit 6b2bba1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions llvm/include/llvm/Object/COFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ class COFFObjectFile : public ObjectFile {
void moveSymbolNext(DataRefImpl &Symb) const override;
Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/Object/COFFObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ uint64_t COFFObjectFile::getSymbolValueImpl(DataRefImpl Ref) const {
return getCOFFSymbol(Ref).getValue();
}

uint32_t COFFObjectFile::getSymbolAlignment(DataRefImpl Ref) const {
// MSVC/link.exe seems to align symbols to the next-power-of-2
// up to 32 bytes.
COFFSymbolRef Symb = getCOFFSymbol(Ref);
uint32_t Value = Symb.getValue();
return std::min(uint64_t(32),
isPowerOf2_64(Value) ? Value : NextPowerOf2(Value));
}

Expected<uint64_t> COFFObjectFile::getSymbolAddress(DataRefImpl Ref) const {
uint64_t Result = getSymbolValue(Ref);
COFFSymbolRef Symb = getCOFFSymbol(Ref);
Expand Down
8 changes: 8 additions & 0 deletions llvm/test/ExecutionEngine/MCJIT/coff-alignment.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; RUN: opt -mtriple=x86_64-pc-win32-coff %s -o - | lli

@o = common global i32 0, align 4

define i32 @main() {
%patatino = load i32, i32* @o, align 4
ret i32 %patatino
}

0 comments on commit 6b2bba1

Please sign in to comment.