[llvm-objdump] --private-headers: change errors to warnings for dynamic section dumping
authorFangrui Song <i@maskray.me>
Mon, 28 Mar 2022 08:00:43 +0000 (01:00 -0700)
committerFangrui Song <i@maskray.me>
Mon, 28 Mar 2022 08:00:43 +0000 (01:00 -0700)
commit11a8fc685692f56b011f851d974f0cac534f2cb8
treee9ed3cc2efe51c30410a2c711263ce00c7d22454
parent423af54cbef7b90199e01162dcea6d3e62539e8c
[llvm-objdump] --private-headers: change errors to warnings for dynamic section dumping

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
llvm/lib/Object/ELF.cpp
llvm/test/tools/llvm-objdump/ELF/dynamic-malformed.test [new file with mode: 0644]
llvm/test/tools/llvm-objdump/ELF/invalid-phdr.test
llvm/test/tools/llvm-objdump/ELF/program-headers.test
llvm/tools/llvm-objdump/ELFDump.cpp