[PATCH] D26173: [lli/COFF] Set the correct alignment for common symbols

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 31 16:33:01 PDT 2016


davide created this revision.
davide added reviewers: ruiu, majnemer, rnk, lhames.
davide added a subscriber: llvm-commits.

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."). Makes lli slightly better on Windows, at least for me =)


https://reviews.llvm.org/D26173

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


Index: test/ExecutionEngine/MCJIT/coff-alignment.ll
===================================================================
--- /dev/null
+++ test/ExecutionEngine/MCJIT/coff-alignment.ll
@@ -0,0 +1,8 @@
+; RUN: opt -mtriple=x86_64-pc-win32-coff %s -o - | lli
+
+ at o = common global i32 0, align 4
+
+define void @main() {
+  %tmp23 = load i32, i32* @o, align 4
+  ret void
+}
Index: lib/Object/COFFObjectFile.cpp
===================================================================
--- lib/Object/COFFObjectFile.cpp
+++ lib/Object/COFFObjectFile.cpp
@@ -157,6 +157,15 @@
   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);
Index: include/llvm/Object/COFF.h
===================================================================
--- include/llvm/Object/COFF.h
+++ include/llvm/Object/COFF.h
@@ -715,6 +715,7 @@
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26173.76504.patch
Type: text/x-patch
Size: 1771 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161031/09a126a9/attachment.bin>


More information about the llvm-commits mailing list