Fix #54456: `objcopy --only-keep-debug` produces a linked image with invalid empty dynamic section. llvm-objdump -p currently reports an error which seems excessive. ``` % llvm-readelf -l a.out llvm-readelf: warning: 'a.out': no valid dynamic table was found ... ``` Follow the spirit of llvm-readelf -l (D64472) and report a warning instead. This allows later files to be dumped despite warnings for an input file, and improves objdump compatibility in that the exit code is now 0 instead of 1. ``` % llvm-objdump -p a.out # new behavior ... Program Header: llvm-objdump: warning: 'a.out': invalid empty dynamic section % objdump -p a.out ... Dynamic Section: ``` Reviewed By: jhenderson, raj.khem Differential Revision: https://reviews.llvm.org/D122505
39 lines
1019 B
Plaintext
39 lines
1019 B
Plaintext
## An empty dynamic section is invalid. Test we report a warning instead of an
|
|
## error, so that dumping can continue with other objects.
|
|
# RUN: yaml2obj %s --docnum=1 -o %t.empty
|
|
# RUN: llvm-objdump -p %t.empty 2>&1 | FileCheck %s -DFILE=%t.empty --check-prefix=EMPTY
|
|
|
|
# EMPTY: Program Header:
|
|
# EMPTY-NEXT: warning: '[[FILE]]': invalid empty dynamic section
|
|
# EMPTY-EMPTY:
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_EXEC
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Name: .dynamic
|
|
Type: SHT_DYNAMIC
|
|
|
|
# RUN: yaml2obj %s --docnum=2 -o %t.nonull
|
|
# RUN: llvm-objdump -p %t.nonull 2>&1 | FileCheck %s -DFILE=%t.nonull --check-prefix=NONULL
|
|
|
|
# NONULL: Program Header:
|
|
# NONULL-NEXT: warning: '[[FILE]]': dynamic sections must be DT_NULL terminated
|
|
# NONULL-EMPTY:
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_EXEC
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Name: .dynamic
|
|
Type: SHT_DYNAMIC
|
|
Entries:
|
|
- Tag: DT_SONAME
|
|
Value: 1
|