[llvm] bdc3c73 - [MachO] Pad section data to pointer size bytes

Aditya Nandakumar via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 11 14:52:38 PST 2020


Author: Aditya Nandakumar
Date: 2020-02-11T14:52:21-08:00
New Revision: bdc3c73454aa04eda74dff2e5061482e13ed4ee7

URL: https://github.com/llvm/llvm-project/commit/bdc3c73454aa04eda74dff2e5061482e13ed4ee7
DIFF: https://github.com/llvm/llvm-project/commit/bdc3c73454aa04eda74dff2e5061482e13ed4ee7.diff

LOG: [MachO] Pad section data to pointer size bytes

https://reviews.llvm.org/D74273

Pad macho section data to pointer size bytes, so that relocation
table and symbol table following section data will be pointer size
aligned.

Patch by pguo.

Added: 
    

Modified: 
    llvm/lib/MC/MachObjectWriter.cpp
    llvm/test/MC/MachO/darwin-x86_64-diff-relocs.s
    llvm/test/MC/MachO/variable-exprs.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp
index 9f6af981aca1..65a282002ccf 100644
--- a/llvm/lib/MC/MachObjectWriter.cpp
+++ b/llvm/lib/MC/MachObjectWriter.cpp
@@ -831,11 +831,11 @@ uint64_t MachObjectWriter::writeObject(MCAssembler &Asm,
     SectionDataFileSize = std::max(SectionDataFileSize, Address + FileSize);
   }
 
-  // The section data is padded to 4 bytes.
+  // The section data is padded to pointer size bytes.
   //
   // FIXME: Is this machine dependent?
   unsigned SectionDataPadding =
-      offsetToAlignment(SectionDataFileSize, Align(4));
+      offsetToAlignment(SectionDataFileSize, is64Bit() ? Align(8) : Align(4));
   SectionDataFileSize += SectionDataPadding;
 
   // Write the prolog, starting with the header and load command...

diff  --git a/llvm/test/MC/MachO/darwin-x86_64-
diff -relocs.s b/llvm/test/MC/MachO/darwin-x86_64-
diff -relocs.s
index 3a25999c2b8c..c5e022671dce 100644
--- a/llvm/test/MC/MachO/darwin-x86_64-
diff -relocs.s
+++ b/llvm/test/MC/MachO/darwin-x86_64-
diff -relocs.s
@@ -147,7 +147,7 @@ L3:
 // CHECK:     Size: 0x5E
 // CHECK:     Offset: 384
 // CHECK:     Alignment: 0
-// CHECK:     RelocationOffset: 0x26C
+// CHECK:     RelocationOffset: 0x270
 // CHECK:     RelocationCount: 12
 // CHECK:     Type: Regular (0x0)
 // CHECK:     Attributes [ (0x800004)
@@ -174,7 +174,7 @@ L3:
 // CHECK:     Size: 0x8E
 // CHECK:     Offset: 478
 // CHECK:     Alignment: 0
-// CHECK:     RelocationOffset: 0x2CC
+// CHECK:     RelocationOffset: 0x2D0
 // CHECK:     RelocationCount: 16
 // CHECK:     Type: Regular (0x0)
 // CHECK:     Attributes [ (0x4)

diff  --git a/llvm/test/MC/MachO/variable-exprs.s b/llvm/test/MC/MachO/variable-exprs.s
index c2eb05dceaee..b4b57811529d 100644
--- a/llvm/test/MC/MachO/variable-exprs.s
+++ b/llvm/test/MC/MachO/variable-exprs.s
@@ -298,7 +298,7 @@ Lt0_x = Lt0_a - Lt0_b
 // CHECK-X86_64:     Size: 0x38
 // CHECK-X86_64:     Offset: 385
 // CHECK-X86_64:     Alignment: 0
-// CHECK-X86_64:     RelocationOffset: 0x1BC
+// CHECK-X86_64:     RelocationOffset: 0x1C0
 // CHECK-X86_64:     RelocationCount: 9
 // CHECK-X86_64:     Type: Regular (0x0)
 // CHECK-X86_64:     Attributes [ (0x0)


        


More information about the llvm-commits mailing list