[llvm] r285841 - [lli/COFF] Set the correct alignment for common symbols

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 2 10:32:19 PDT 2016


Author: davide
Date: Wed Nov  2 12:32:19 2016
New Revision: 285841

URL: http://llvm.org/viewvc/llvm-project?rev=285841&view=rev
Log:
[lli/COFF] Set the correct alignment for common symbols

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

Added:
    llvm/trunk/test/ExecutionEngine/MCJIT/coff-alignment.ll
Modified:
    llvm/trunk/include/llvm/Object/COFF.h
    llvm/trunk/lib/Object/COFFObjectFile.cpp

Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=285841&r1=285840&r2=285841&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Wed Nov  2 12:32:19 2016
@@ -715,6 +715,7 @@ protected:
   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;

Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=285841&r1=285840&r2=285841&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Wed Nov  2 12:32:19 2016
@@ -157,6 +157,15 @@ uint64_t COFFObjectFile::getSymbolValueI
   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);

Added: llvm/trunk/test/ExecutionEngine/MCJIT/coff-alignment.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/coff-alignment.ll?rev=285841&view=auto
==============================================================================
--- llvm/trunk/test/ExecutionEngine/MCJIT/coff-alignment.ll (added)
+++ llvm/trunk/test/ExecutionEngine/MCJIT/coff-alignment.ll Wed Nov  2 12:32:19 2016
@@ -0,0 +1,8 @@
+; RUN: opt -mtriple=x86_64-pc-win32-coff %s -o - | lli
+
+ at o = common global i32 0, align 4
+
+define i32 @main() {
+  %patatino = load i32, i32* @o, align 4
+  ret i32 %patatino
+}




More information about the llvm-commits mailing list