[llvm] 32b1933 - [llvm-objcopy][ELF] Allow --dump-section to dump an empty non-SHT_NOBITS section
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue May 5 08:26:46 PDT 2020
Author: Fangrui Song
Date: 2020-05-05T08:26:34-07:00
New Revision: 32b19334da14bfa7ab30fe683a0e6a2d2a35e0dc
URL: https://github.com/llvm/llvm-project/commit/32b19334da14bfa7ab30fe683a0e6a2d2a35e0dc
DIFF: https://github.com/llvm/llvm-project/commit/32b19334da14bfa7ab30fe683a0e6a2d2a35e0dc.diff
LOG: [llvm-objcopy][ELF] Allow --dump-section to dump an empty non-SHT_NOBITS section
This is the ELF part of D75949.
GNU objcopy from binutils 2.35 onwards will support an empty non-SHT_NOBITS section as
well
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=e052e2ba295a65b6ea80cbc3f90495beca299c42
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D79339
Added:
Modified:
llvm/test/tools/llvm-objcopy/ELF/dump-section.test
llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-objcopy/ELF/dump-section.test b/llvm/test/tools/llvm-objcopy/ELF/dump-section.test
index 9e8cd0747ceb..fadd955a0f93 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/dump-section.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/dump-section.test
@@ -4,9 +4,11 @@
# RUN: llvm-objcopy --dump-section .text=%t4 %t %t5
# RUN: llvm-objcopy --dump-section .foo=%t6 %t %t7
# RUN: not llvm-objcopy --dump-section .bar=%t8 %t %t9 2>&1 | FileCheck %s --check-prefix=NOBITS -DINPUT=%t
+# RUN: llvm-objcopy --dump-section .empty=%t.empty %t /dev/null
# RUN: od -t x1 %t2 | FileCheck %s --ignore-case
# RUN: od -t x1 %t6 | FileCheck %s --ignore-case --check-prefix=NON-ALLOC
# RUN: wc -c %t2 | FileCheck %s --check-prefix=SIZE
+# RUN: wc -c %t.empty | FileCheck %s --check-prefix=EMPTY
# RUN:
diff %t2 %t3
# RUN:
diff %t4 %t3
@@ -26,6 +28,9 @@ Sections:
Type: SHT_PROGBITS
Flags: [ SHF_WRITE ]
Content: "CAFE"
+ - Name: .empty
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
- Name: .bar
Type: SHT_NOBITS
Flags: [ SHF_WRITE ]
@@ -42,3 +47,5 @@ ProgramHeaders:
# SIZE: 4
# NOBITS: error: '[[INPUT]]': cannot dump section '.bar': it has no contents
+
+# EMPTY: 0
diff --git a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
index c1d8c1fa979c..f7332b7f66fe 100644
--- a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
+++ b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
@@ -288,7 +288,7 @@ static Error dumpSectionToFile(StringRef SecName, StringRef Filename,
Object &Obj) {
for (auto &Sec : Obj.sections()) {
if (Sec.Name == SecName) {
- if (Sec.OriginalData.empty())
+ if (Sec.Type == SHT_NOBITS)
return createStringError(object_error::parse_failed,
"cannot dump section '%s': it has no contents",
SecName.str().c_str());
More information about the llvm-commits
mailing list