[llvm-readobj] Print <null> for relocation target with an empty name
authorFangrui Song <i@maskray.me>
Thu, 20 Jul 2023 07:42:38 +0000 (00:42 -0700)
committerFangrui Song <i@maskray.me>
Thu, 20 Jul 2023 07:42:38 +0000 (00:42 -0700)
commit82b4368f7f89e2b16b9eb09787b7a7af07e3b7cd
treeb06258ab3bc7e14a6d09d9cb365414f5b3c95fb1
parent7cbcc599063f75305e2063be81f656c4982ab228
[llvm-readobj] Print <null> for relocation target with an empty name

For a relocation, we don't differentiate the two cases:

* the symbol index is 0
* the symbol index is non zero, the type is not STT_SECTION, and the name is empty. Clang generates such local symbols for RISC-V linker relaxation.

So we may print
```
    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
000000000000001c  0000000100000039 R_RISCV_32_PCREL       0000000000000000 0

// llvm-readobj
0x1C R_RISCV_32_PCREL - 0x0
```

while GNU readelf prints "<null>", which is clearer. Let's match the GNU behavior.
Related to https://reviews.llvm.org/D81842

```
000000000000001c  0000000100000039 R_RISCV_32_PCREL       0000000000000000 <null> + 0

// llvm-readobj
0x1C R_RISCV_32_PCREL <null> 0x0
```

Reviewed By: jhenderson, kito-cheng

Differential Revision: https://reviews.llvm.org/D155353
lld/test/ELF/mips-eh_frame-pic.s
llvm/test/CodeGen/RISCV/fixups-diff.ll
llvm/test/DebugInfo/RISCV/dwarf-riscv-relocs.ll
llvm/test/DebugInfo/RISCV/relax-debug-frame.ll
llvm/test/MC/ELF/RISCV/gen-dwarf.s
llvm/test/MC/RISCV/cfi-advance.s
llvm/test/MC/RISCV/fde-reloc.s
llvm/test/MC/RISCV/scoped-relaxation.s
llvm/test/tools/llvm-readobj/ELF/reloc-zero-name-or-value.test
llvm/test/tools/yaml2obj/ELF/symbol-name.yaml
llvm/tools/llvm-readobj/ELFDumper.cpp