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

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rL285841: [lli/COFF] Set the correct alignment for common symbols (authored by davide).

Changed prior to commit:
  https://reviews.llvm.org/D26173?vs=76504&id=76739#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26173

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


Index: llvm/trunk/include/llvm/Object/COFF.h
===================================================================
--- llvm/trunk/include/llvm/Object/COFF.h
+++ llvm/trunk/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;
Index: llvm/trunk/test/ExecutionEngine/MCJIT/coff-alignment.ll
===================================================================
--- llvm/trunk/test/ExecutionEngine/MCJIT/coff-alignment.ll
+++ llvm/trunk/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 i32 @main() {
+  %patatino = load i32, i32* @o, align 4
+  ret i32 %patatino
+}
Index: llvm/trunk/lib/Object/COFFObjectFile.cpp
===================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp
+++ llvm/trunk/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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26173.76739.patch
Type: text/x-patch
Size: 1916 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161102/f1a9ab2e/attachment.bin>


More information about the llvm-commits mailing list