[PATCH] D41619: [llvm-objcopy] Use physical instead of virtual address when aligning and placing sections in binary

Owen Shaw via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 28 15:30:44 PST 2017


owenpshaw created this revision.
owenpshaw added a reviewer: jakehehrlich.
Herald added subscribers: kristof.beyls, aemerson.

For sections with different virtual and physical addresses, alignment and placement in the output binary should be based on the physical address.

Ran into this problem with a bare metal ARM project where llvm-objcopy added a lot of zero-padding before the .data section that had differing addresses.  GNU objcopy did not add the padding, and after this fix, neither does llvm-objcopy.

Update a test case so a section has different physical and virtual addresses.

Fixes B35708


https://reviews.llvm.org/D41619

Files:
  test/tools/llvm-objcopy/check-addr-offset-align-binary.test
  tools/llvm-objcopy/Object.cpp


Index: tools/llvm-objcopy/Object.cpp
===================================================================
--- tools/llvm-objcopy/Object.cpp
+++ tools/llvm-objcopy/Object.cpp
@@ -738,7 +738,7 @@
       Segment->Offset =
           Parent->Offset + Segment->OriginalOffset - Parent->OriginalOffset;
     } else {
-      Offset = alignToAddr(Offset, Segment->VAddr, Segment->Align);
+      Offset = alignToAddr(Offset, Segment->PAddr, Segment->Align);
       Segment->Offset = Offset;
     }
     Offset = std::max(Offset, Segment->Offset + Segment->FileSize);
Index: test/tools/llvm-objcopy/check-addr-offset-align-binary.test
===================================================================
--- test/tools/llvm-objcopy/check-addr-offset-align-binary.test
+++ test/tools/llvm-objcopy/check-addr-offset-align-binary.test
@@ -18,7 +18,7 @@
   - Name:            .data
     Type:            SHT_PROGBITS
     Flags:           [ SHF_ALLOC ]
-    Address:         0x1008
+    Address:         0x1010
     AddressAlign:    0x0000000000000008
     Content:         "3232"
 ProgramHeaders:
@@ -31,7 +31,7 @@
       - Section: .text
   - Type: PT_LOAD
     Flags: [ PF_R, PF_W ]
-    VAddr: 0x1008
+    VAddr: 0x1010
     PAddr: 0x1008
     Align: 0x1000
     Sections:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41619.128309.patch
Type: text/x-patch
Size: 1261 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171228/f7b3d5de/attachment.bin>


More information about the llvm-commits mailing list