[PATCH] D68249: [llvm-objdump] Don't throw error for empty dynamic section
Yi Kong via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 30 15:52:12 PDT 2019
kongyi created this revision.
kongyi added reviewers: rupprecht, paulsemel, MaskRay.
Herald added subscribers: llvm-commits, seiya, hiraditya.
Herald added a reviewer: alexshap.
Herald added a project: LLVM.
objcopy --only-keep-debug flag creates files with empty dynamic section. llvm-objdump should not throw error for these files.
Repository:
rL LLVM
https://reviews.llvm.org/D68249
Files:
llvm/lib/Object/ELF.cpp
llvm/test/tools/llvm-objdump/elf-keep-debug-only.test
Index: llvm/test/tools/llvm-objdump/elf-keep-debug-only.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/elf-keep-debug-only.test
@@ -0,0 +1,27 @@
+# 'objcopy --only-keep-debug' will create objects with empty dynamic section,
+# llvm-objcopy should not crash for these files.
+# RUN: yaml2obj %s > %t
+# RUN: llvm-objdump -p %t | FileCheck %s
+
+# CHECK: Dynamic Section:
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .dynamic
+ Type: SHT_DYNAMIC
+ Address: 0x1010
+ProgramHeaders:
+ - Type: PT_LOAD
+ VAddr: 0x1000
+ Sections:
+ - Section: .dynstr
+ - Section: .dynamic
+ - Type: PT_DYNAMIC
+ VAddr: 0x1010
+ Sections:
+ - Section: .dynamic
Index: llvm/lib/Object/ELF.cpp
===================================================================
--- llvm/lib/Object/ELF.cpp
+++ llvm/lib/Object/ELF.cpp
@@ -538,17 +538,15 @@
return ArrayRef<Elf_Dyn>();
}
- if (Dyn.empty())
- // TODO: this error is untested.
- return createError("invalid empty dynamic section");
-
- if (DynSecSize % sizeof(Elf_Dyn) != 0)
- // TODO: this error is untested.
- return createError("malformed dynamic section");
-
- if (Dyn.back().d_tag != ELF::DT_NULL)
- // TODO: this error is untested.
- return createError("dynamic sections must be DT_NULL terminated");
+ if (!Dyn.empty()) {
+ if (DynSecSize % sizeof(Elf_Dyn) != 0)
+ // TODO: this error is untested.
+ return createError("malformed dynamic section");
+
+ if (Dyn.back().d_tag != ELF::DT_NULL)
+ // TODO: this error is untested.
+ return createError("dynamic sections must be DT_NULL terminated");
+ }
return Dyn;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68249.222507.patch
Type: text/x-patch
Size: 1820 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190930/455a7632/attachment.bin>
More information about the llvm-commits
mailing list