https://sourceware.org/bugzilla/show_bug.cgi?id=34777

            Bug ID: 34777
           Summary: objdump -t / nm: Mach-O symbol with n_strx 0 gets the
                    string at string table offset 0 as its name
           Product: binutils
           Version: 2.47
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: binutils
          Assignee: unassigned at sourceware dot org
          Reporter: i at mi11ion dot io
  Target Milestone: ---
              Host: aarch64-apple-darwin

Created attachment 17101
  --> https://sourceware.org/bugzilla/attachment.cgi?id=17101&action=edit
strx0-x.o: Mach-O object, one nlist_64 with n_strx 0

Environment: GNU objdump (GNU Binutils) 2.47.20260726 and 2.46.0.20260210,
Homebrew binutils on macOS 27.0 (arm64). The code is unchanged on master at
21cffe7c0955c6bdb0c14ded96939d409f3c21f0.

Reproducer: the attached strx0-x.o (74 bytes) is a Mach-O arm64 MH_OBJECT with
one LC_SYMTAB (symoff 56, nsyms 1, stroff 72, strsize 2), one nlist_64 (n_strx
0, n_type N_ABS, n_value 0x42) and the string table "58 00" ("X\0"):

00000000: cffa edfe 0c00 0001 0000 0000 0100 0000
00000010: 0100 0000 1800 0000 0000 0000 0000 0000
00000020: 0200 0000 1800 0000 3800 0000 0100 0000
00000030: 4800 0000 0200 0000 0000 0000 0200 0000
00000040: 4200 0000 0000 0000 5800

Command: objdump -t strx0-x.o (and nm -p -a strx0-x.o)

Actual:

0000000000000042 l       02 ABS    00 0000 X

Expected: the symbol's name is empty:

0000000000000042 l       02 ABS    00 0000

With the string table Apple's ld writes ("20 00", " \0") the symbol is named "
", and objcopy then writes " " into the output's string table as the symbol's
name.

Analysis: <mach-o/nlist.h> says "Symbols with a index into the string table of
zero (n_un.n_strx == 0) are defined to have a null, "", name."
bfd_mach_o_read_symtab_symbol (bfd/mach-o.c line 3775) sets s->symbol.name =
sym->strtab + stroff; for every index, 0 included. The writer in the same file,
bfd_mach_o_build_symtab (around line 2030), already writes index 0 for an empty
name ("An index of 0 always means the empty string"), so reading and writing
disagree; the reader should treat index 0 as the empty name, as the writer
does.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to