This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj] Allow syms from all sections to match stack size entries
ClosedPublic

Authored by jhenderson on Mar 19 2020, 4:04 AM.

Details

Summary

Prior to this change, for non-relocatable objects llvm-readobj would assume that all symbols that corresponded to a stack size section's entries were in the section specified by the section's sh_link field. However, in the event that there are multiple sections, the sh_link field cannot be respected, as it only indicates one of those sections (LLD sets the value to the first such section but see D76410 for a possible solution).

This patch changes llvm-readobj to ignore the section of symbols in a non-relocatable object (except for undefined symbols which are ignored). One behaviour change is that function symbols that share a value, but in different sections (typically these would appear at the end of a section) will result in the first being picked, even if the second is in the section for the sh_link value. As such symbols will almost never exist (it would require a zero-byte function or a symbol with an incorrect type), I think this is okay.

Fixes https://bugs.llvm.org/show_bug.cgi?id=45228.

Diff Detail

Event Timeline

jhenderson created this revision.Mar 19 2020, 4:04 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: emaste. · View Herald Transcript
grimar added inline comments.Mar 19 2020, 6:04 AM
llvm/test/tools/llvm-readobj/ELF/stack-sizes.test
156

Perhaps say which sh_link?

sh_link of `.stack_sizes` is ...

executables

and DSOs?

163

BTW, does would it be better to print all of candidates?
e.g:

Size   Function
16     other
32     other_end/foo/bar
llvm/tools/llvm-readobj/ELFDumper.cpp
5324–5325

/*FunctionSec=*/None

jhenderson marked 3 inline comments as done.

Address review comments.

MaskRay accepted this revision.Mar 19 2020, 12:46 PM
MaskRay added inline comments.
llvm/test/tools/llvm-readobj/ELF/stack-sizes.test
101

--implicit-check-not=warning: may be slightly better.

It is unlikely that the absolute path of %s contains warning:

This revision is now accepted and ready to land.Mar 19 2020, 12:46 PM

However, in the event that there are multiple sections, the sh_link field cannot be respected, as it only indicates one of those sections (LLD sets the value to the first such section but see D76410 for a possible solution).

In the presence of an output section description combining SHF_LINK_ORDER sections linking different output sections, this cannot be respected. A linker script section pattern is "by name" by nature.

grimar accepted this revision.Mar 20 2020, 1:54 AM

LGTM.

(Looking on the code I am a bit unsure why we preferred to consumeError
in functions that print stack sizes, but this consern is unrelated to this patch.)

jhenderson marked an inline comment as done.

Make --implicit-check-not patterns tighter.

(Woops, one comment didn't get added yesterday).

llvm/test/tools/llvm-readobj/ELF/stack-sizes.test
163

I don't think like that is a good idea, since there may be people parsing the output and the current version is quite easy to parse.

There's probably a case for marking them on separate lines though, sharing the same value, although that would require trawling the entire symbol table for every entry (O(n^2)) rather than up to the first symbol, which would therefore be somewhat slower.

That would be more general too, and ensure that ICF-ed functions and other aliases are handled nicely. Consequently, I think that's outside the scope of this change.

This revision was automatically updated to reflect the committed changes.