This is an archive of the discontinued LLVM Phabricator instance.

[llvm-nm][ELF] - Make -D display symbol versions.
ClosedPublic

Authored by grimar on Jan 18 2021, 4:29 AM.

Details

Summary

This fixes https://bugs.llvm.org/show_bug.cgi?id=48670.

Since binutils 2.35, nm -D displays symbol versions by default.
This patch teaches llvm-nm to do the same.

Diff Detail

Event Timeline

grimar created this revision.Jan 18 2021, 4:29 AM
grimar requested review of this revision.Jan 18 2021, 4:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 18 2021, 4:29 AM
grimar added inline comments.Jan 18 2021, 4:31 AM
llvm/test/tools/llvm-nm/dynamic.test
75

Note: I think we should print @@ for default versions and @ for hidden versions.
It is not what GNU nm does, but it would be more consistent with other tools that print versioned symbols.
I am going to post a follow-up patch for this.

grimar updated this revision to Diff 317328.Jan 18 2021, 4:33 AM
grimar set the repository for this revision to rG LLVM Github Monorepo.
  • Format.

As our downstream toolchain doesn't use symbol versioning, I'm not really familiar enough with this to review the details (and don't have the time to read back up on it currently), so you'll need @MaskRay or someone else to give input too.

llvm/test/tools/llvm-nm/dynamic.test
131
134
154

Adding "wrong" here felt wrong :-)

161
llvm/tools/llvm-nm/llvm-nm.cpp
1718–1719

Seems like if you're not using Sym, this should be an older style for loop?

1788

Is the case actually necessary? I'm sure I've seen size_t X = -1 in other places before without warnings.

grimar updated this revision to Diff 317499.Jan 19 2021, 2:26 AM
grimar marked 6 inline comments as done.
  • Addressed review comments.
llvm/tools/llvm-nm/llvm-nm.cpp
1718–1719

Done. Unfortunately I can't take size(), because Symbols is ELFObjectFileBase::elf_symbol_iterator_range.

1788

Yeah, looks like it is not needed.

jhenderson added inline comments.Jan 19 2021, 5:45 AM
llvm/test/tools/llvm-nm/dynamic.test
153

Here the thing you can't read is the section, not the section entry, right? If so, delete the "entry" in this sentence.

grimar added inline comments.Jan 19 2021, 5:51 AM
llvm/test/tools/llvm-nm/dynamic.test
153

The reported warning is:

# VERSION-ERR2: warning: unable to read symbol versions: unable to read an entry with index 1 from SHT_GNU_versym section with index 1: section [index 1] has an invalid sh_size (255) which is not a multiple of its sh_entsize (2)

I.e. I can't read a particular entry because there is an issue with extracting all section entries.

The test case tries to trigger the following code in readSymbolVersionsELF:

if (!VerEntryOrErr)
  return createError("unable to read an entry with index " + Twine(I) +
                     " from " + describe(Obj, *SymVerSec) + ": " +
                     toString(VerEntryOrErr.takeError()));
jhenderson added inline comments.Jan 19 2021, 5:55 AM
llvm/test/tools/llvm-nm/dynamic.test
153

The next line of this comment refers to "it" which would mean the unreadable "section entry" mentioned at the end of the previous comment, so you either need to change the first line to talk about the section, not the section entry, or the second line to not use "it" (e.g. "In this case, the section has...")

grimar updated this revision to Diff 317543.Jan 19 2021, 6:06 AM
grimar marked 2 inline comments as done.
  • Addressed review comment.
This revision is now accepted and ready to land.Jan 20 2021, 12:31 AM

@MaskRay, are you OK with it?

MaskRay accepted this revision.Jan 20 2021, 9:35 AM

LGTM.

llvm/test/tools/llvm-nm/dynamic.test
146

Perhaps append {{$}} or use FileCheck --match-full-lines

llvm/tools/llvm-nm/llvm-nm.cpp
1789–1790

Perhaps llvm::enumerate

This revision was automatically updated to reflect the committed changes.
grimar marked 2 inline comments as done.
MaskRay added inline comments.Jan 21 2021, 9:48 PM
llvm/tools/llvm-nm/llvm-nm.cpp
1831

Sorry, I did not read carefully.

This is wrong. D94912 should just be folded into D94907. We should not have pushed D94907 leaving @ in the output where the correct output uses @@ and the legacy output does not use @ at all.

MaskRay added inline comments.
llvm/tools/llvm-nm/llvm-nm.cpp
1831

This caused https://github.com/ClangBuiltLinux/linux/issues/1266 @nathanchance

Though it is probably not too urgent.

grimar added inline comments.Jan 21 2021, 11:13 PM
llvm/tools/llvm-nm/llvm-nm.cpp
1831

I was under impression that GNU nm never prints @@. But seems it just doesn't do it for undefined symbols, and I guess I didn't try other cases previously.
Anyways I am going to look into this issue today.