This is an archive of the discontinued LLVM Phabricator instance.

Use portable flag with nm in extract_symbols.py
ClosedPublic

Authored by daltenty on Oct 15 2019, 1:42 PM.

Details

Summary

nm is one of the tools that extract_symbols.py can use to extract
symbols from llvm libraries as part of the build process. This patch
updates the invocation of nm to use the -P POSIX option for "portable
output" so we get a consistently parsable output format on all
platforms.

A link to the relevant nm format: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/nm.html

Diff Detail

Event Timeline

daltenty created this revision.Oct 15 2019, 1:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 15 2019, 1:42 PM
daltenty edited the summary of this revision. (Show Details)Oct 15 2019, 1:50 PM
stevewan added inline comments.Oct 23 2019, 12:05 PM
llvm/utils/extract_symbols.py
51

So I see we are changing the target of group in the regex match, but I don't see clearly the rationale behind it. Is it based on some testing outputs?

daltenty marked 2 inline comments as done.Oct 23 2019, 1:02 PM
daltenty added inline comments.
llvm/utils/extract_symbols.py
51

The nm portable output format is:

"%s%s %s %x %x\n", 
<library/object name>, <name>, <type>, <value>, <size>

(where <library/object name> will be empty in our usage)

So we change the target group to deal with the new position of the symbol name.

daltenty marked an inline comment as done.Oct 23 2019, 1:02 PM
This revision is now accepted and ready to land.Oct 23 2019, 1:39 PM
This revision was automatically updated to reflect the committed changes.
emaste added a subscriber: emaste.Oct 23 2019, 2:13 PM

Is this using the system nm? ELF Tool Chain nm does not (currently) support the -P flag.

Is this using the system nm? ELF Tool Chain nm does not (currently) support the -P flag.

extract_symbol.py does normally invoke the system nm (which is why we wanted to apply the portability flag).

I was under the impression that -P was supported on FreeBSD. If not, perhaps there is an equivalent posix format option?

I was under the impression that -P was supported on FreeBSD.

Hrm, I was mistaken and nm -P is supported on FreeBSD (with the ELF Tool Chain nm in the base system); I'm not sure what I ended up trying earlier. Sorry for the noise.