This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readelf/obj] - Stop printing invalid names for unnamed section symbols.
ClosedPublic

Authored by grimar on Sep 16 2020, 7:43 AM.

Details

Summary

We have an issue with ELFDumper<ELFT>::getSymbolSectionName:

  1. It is used deeply for both LLVM/GNU styles and might return LLVM-style only values to describe symbols: "Undefined", "Processor Specific", "Absolute", etc.
  1. getSymbolSectionName is used by getFullSymbolName and these special values might appear instead of symbol names in many places. This occurs for unnamed section symbols currently.

This patch extracts the LLVM specific logic to LLVMStyle<ELFT>::printSymbolSection,
which seems to be the only place where we want to print the special values mentioned.

Depends on D87763

Diff Detail

Event Timeline

grimar created this revision.Sep 16 2020, 7:43 AM
Herald added a project: Restricted Project. · View Herald Transcript
jhenderson added inline comments.Sep 17 2020, 1:47 AM
llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
338–340

Am I right in thinking these warnings are coming out because SHN_ABS isn't a valid section index? That doesn't seem right to me - a st_shndx of SHN_ABS is perfectly normal. You just wouldn't normally have a section symbol to them. What happens if there are many sections and section index 65521 is actually a valid section?

I'd be inclined to produce a warning saying "section symbols shouldn't be absolute" (or whatever), and then print <?>, in this case.

MaskRay added inline comments.Sep 17 2020, 11:45 PM
llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
338–340

"shouldn't be absolute" is too specific. Having a generic message for all these special indices should suffice.

grimar updated this revision to Diff 292711.Sep 18 2020, 12:15 AM
grimar marked 2 inline comments as done.
  • Addressed review comments.
llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
338–340

Am I right in thinking these warnings are coming out because SHN_ABS isn't a valid section index? That doesn't seem right to me - a st_shndx of SHN_ABS is perfectly normal

You are right, implementation was wrong. So, we should not be able to take a section index for symbols which have sh_shndx >= SHN_LORESERVE (SHN_XINDEX is an exception).

I've updated the logic and now reporting a better message.

jhenderson added inline comments.Sep 18 2020, 1:42 AM
llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
342

I'm thinking the warning/<?> output would probably make sense for undefined STT_SECTION symbols too. Those shouldn't really be a thing after all.

grimar updated this revision to Diff 292732.Sep 18 2020, 2:46 AM
grimar marked an inline comment as done.
  • Addressed review comment about SHN_UNDEF section symbols.
llvm/test/tools/llvm-readobj/ELF/dyn-symbols.test
342

Probably reasonable. Done.

jhenderson accepted this revision.Sep 21 2020, 12:45 AM

LGTM, thanks!

This revision is now accepted and ready to land.Sep 21 2020, 12:45 AM