[PATCH] D95569: [llvm-objcopy] -O binary: consider SHT_NOBITS sections to be empty
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 1 15:01:38 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG93345e825a07: [llvm-objcopy] -O binary: consider SHT_NOBITS sections to be empty (authored by pattop, committed by MaskRay).
Changed prior to commit:
https://reviews.llvm.org/D95569?vs=320613&id=320614#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D95569/new/
https://reviews.llvm.org/D95569
Files:
llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test
llvm/tools/llvm-objcopy/ELF/Object.cpp
Index: llvm/tools/llvm-objcopy/ELF/Object.cpp
===================================================================
--- llvm/tools/llvm-objcopy/ELF/Object.cpp
+++ llvm/tools/llvm-objcopy/ELF/Object.cpp
@@ -2553,7 +2553,7 @@
if (Sec.ParentSegment != nullptr)
Sec.Addr =
Sec.Offset - Sec.ParentSegment->Offset + Sec.ParentSegment->PAddr;
- if (Sec.Size > 0)
+ if (Sec.Type != SHT_NOBITS && Sec.Size > 0)
MinAddr = std::min(MinAddr, Sec.Addr);
}
Index: llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test
===================================================================
--- llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test
+++ llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test
@@ -183,3 +183,34 @@
- Name: .data
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_WRITE ]
+
+## NOBITS sections should not appear in output.
+# RUN: yaml2obj --docnum=6 %s -o %t6
+# RUN: llvm-objcopy -O binary %t6 %t6.out
+# RUN: od -A x -t x2 %t6.out | FileCheck %s --check-prefix=SKIPNOBITS --ignore-case
+
+# SKIPNOBITS: 000000 c3c3 c3c3
+# SKIPNOBITS-NEXT: 000004
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .bss
+ Type: SHT_NOBITS
+ Flags: [ SHF_ALLOC ]
+ Address: 0x1000
+ AddressAlign: 0x1000
+ Size: 0x123
+ - Name: gap
+ Type: Fill
+ Size: 0xffd
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x4000
+ AddressAlign: 0x1000
+ Content: "c3c3c3c3"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95569.320614.patch
Type: text/x-patch
Size: 1671 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210201/3d540b2f/attachment.bin>
More information about the llvm-commits
mailing list