This is an archive of the discontinued LLVM Phabricator instance.

[llvm-nm] Use same symbol types as gnu nm when --format=sysv
Needs ReviewPublic

Authored by mmpozulp on Jul 28 2019, 12:15 AM.

Event Timeline

mmpozulp created this revision.Jul 28 2019, 12:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 28 2019, 12:15 AM

Should we match gnu nm exactly or is this enough?
If we check all 16 possible bit-patterns of the 4-bit-wide symbol type (as in format-sysv-type.test) we can see that gnu nm prints the symbol_section and symbol_common symbols differently than we do. See (4) below for the differences.

(1) llvm-nm output before applying this patch

Name                  Value           Class        Type         Size             Line  Section
symbol_notype       |                |   U  |            NOTYPE|                |     |*UND*
symbol_obj          |                |   U  |            OBJECT|                |     |*UND*
symbol_function     |                |   U  |              FUNC|                |     |*UND*
symbol_section      |                |   U  |           SECTION|                |     |*UND*
symbol_file         |                |   U  |              FILE|                |     |*UND*
symbol_common       |                |   U  |            COMMON|                |     |*COM*
symbol_tls          |                |   U  |               TLS|                |     |*UND*
symbol_unknown7     |                |   U  |                  |                |     |*UND*
symbol_unknown8     |                |   U  |                  |                |     |*UND*
symbol_unknown9     |                |   U  |                  |                |     |*UND*
symbol_ifunc        |                |   U  |             IFUNC|                |     |*UND*
os_specific10       |                |   U  |             IFUNC|                |     |*UND*
os_specific11       |                |   U  |                  |                |     |*UND*
os_specific12       |                |   U  |                  |                |     |*UND*
proc_specific13     |                |   U  |                  |                |     |*UND*
proc_specific14     |                |   U  |                  |                |     |*UND*
proc_specific15     |                |   U  |                  |                |     |*UND*

(2) llvm-nm output after applying this patch

Name                  Value           Class        Type         Size             Line  Section
symbol_notype       |                |   U  |            NOTYPE|                |     |*UND*
symbol_obj          |                |   U  |            OBJECT|                |     |*UND*
symbol_function     |                |   U  |              FUNC|                |     |*UND*
symbol_section      |                |   U  |           SECTION|                |     |*UND*
symbol_file         |                |   U  |              FILE|                |     |*UND*
symbol_common       |                |   U  |            COMMON|                |     |*COM*
symbol_tls          |                |   U  |               TLS|                |     |*UND*
symbol_unknown7     |                |   U  |      <unknown>: 7|                |     |*UND*
symbol_unknown8     |                |   U  |      <unknown>: 8|                |     |*UND*
symbol_unknown9     |                |   U  |      <unknown>: 9|                |     |*UND*
symbol_ifunc        |                |   U  | <OS specific>: 10|                |     |*UND*
os_specific10       |                |   U  | <OS specific>: 10|                |     |*UND*
os_specific11       |                |   U  | <OS specific>: 11|                |     |*UND*
os_specific12       |                |   U  | <OS specific>: 12|                |     |*UND*
proc_specific13     |                |   U  |<processor specific>: 13|                |     |*UND*
proc_specific14     |                |   U  |<processor specific>: 14|                |     |*UND*
proc_specific15     |                |   U  |<processor specific>: 15|                |     |*UND*

(3) gnu nm (version 2.32) output

Name                  Value           Class        Type         Size             Line  Section

symbol_notype       |                |   U  |            NOTYPE|                |     |*UND*
symbol_obj          |                |   U  |            OBJECT|                |     |*UND*
symbol_function     |                |   U  |              FUNC|                |     |*UND*
symbol_section      |                |   U  |                  |                |     |
symbol_file         |                |   U  |              FILE|                |     |*UND*
symbol_common       |                |   U  |            COMMON|                |     |*UND*
symbol_tls          |                |   U  |               TLS|                |     |*UND*
symbol_unknown7     |                |   U  |      <unknown>: 7|                |     |*UND*
symbol_unknown8     |                |   U  |      <unknown>: 8|                |     |*UND*
symbol_unknown9     |                |   U  |      <unknown>: 9|                |     |*UND*
symbol_ifunc        |                |   U  | <OS specific>: 10|                |     |*UND*
os_specific10       |                |   U  | <OS specific>: 10|                |     |*UND*
os_specific11       |                |   U  | <OS specific>: 11|                |     |*UND*
os_specific12       |                |   U  | <OS specific>: 12|                |     |*UND*
proc_specific13     |                |   U  |<processor specific>: 13|                |     |*UND*
proc_specific14     |                |   U  |<processor specific>: 14|                |     |*UND*
proc_specific15     |                |   U  |<processor specific>: 15|                |     |*UND*

(4) diff llvm-nm gnu-nm

$ diff llvmnm.out gnunm.out 
5a6
> 
9c10
< symbol_section      |                |   U  |           SECTION|                |     |*UND*
---
> symbol_section      |                |   U  |                  |                |     |
11c12
< symbol_common       |                |   U  |            COMMON|                |     |*COM*
---
> symbol_common       |                |   U  |            COMMON|                |     |*UND*

Hi @mmpozulp. Thanks for looking at this. One of my colleagues (@Sunil_Srivastava) has been working on the same fix, but we forgot to update the LLVM bug. His approach also solves a bug in llvm-readelf, so would you mind holding off on this patch until he's got a chance to finish off his version ready for review?

Hi @mmpozulp. Thanks for looking at this. One of my colleagues (@Sunil_Srivastava) has been working on the same fix, but we forgot to update the LLVM bug. His approach also solves a bug in llvm-readelf, so would you mind holding off on this patch until he's got a chance to finish off his version ready for review?

Sure, no problem. I'll leave this revision open but stop working on it, and when @Sunil_Srivastava commits his patch I'll "abandon and close" this revision. Feel free to add me as a reviewer on Sunil's patch.