This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj] Print <null> for relocation target with an empty name
ClosedPublic

Authored by MaskRay on Jul 14 2023, 8:06 PM.

Details

Summary

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

Diff Detail

Event Timeline

MaskRay created this revision.Jul 14 2023, 8:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2023, 8:06 PM
MaskRay requested review of this revision.Jul 14 2023, 8:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2023, 8:07 PM
This revision is now accepted and ready to land.Jul 18 2023, 5:26 PM
jhenderson added inline comments.Jul 19 2023, 1:05 AM
llvm/tools/llvm-readobj/ELFDumper.cpp
6953–6954

If I'm not mistaken, we don't actually have a dedicated test case for this bit of the logic? (It's covered by other tests, but more by accident than design, I feel - there's no purpose-written llvm-readobj LLVM style test).

MaskRay marked an inline comment as done.Jul 19 2023, 8:29 AM
MaskRay added inline comments.
llvm/tools/llvm-readobj/ELFDumper.cpp
6953–6954

There is a dedicated test: reloc-zero-name-or-value.test from D81842

MaskRay marked an inline comment as done.Jul 19 2023, 8:30 AM
jhenderson added inline comments.Jul 20 2023, 12:04 AM
llvm/tools/llvm-readobj/ELFDumper.cpp
6953–6954

That only covers GNU style though, if I'm not mistaken (it uses llvm-readelf with no --elf-output-style option). We should have an LLVM style version, no? I.e. something equivalent to the reloc-zero-name-or-value.test that uses LLVM style that shows the behaviour change highlighted by "llvm/test/tools/yaml2obj/ELF/symbol-name.yaml".

MaskRay updated this revision to Diff 542329.Jul 20 2023, 12:12 AM
MaskRay marked an inline comment as done.

Add dedicate llvm-readobj tests. When landing, the test will be pre-committed.

jhenderson accepted this revision.Jul 20 2023, 12:23 AM

Add dedicate llvm-readobj tests. When landing, the test will be pre-committed.

Thanks. Presumably the pre-committed test won't use <null>, since that wasn't the old behaviour.

LGTM.

This revision was landed with ongoing or failed builds.Jul 20 2023, 12:42 AM
This revision was automatically updated to reflect the committed changes.