Page MenuHomePhabricator

llvm-nm: Print correct symbol types for init and fini sections

Authored by meadori on Nov 21 2016, 2:09 PM.



This patch fixes a small bug where symbols defined in the INIT
and FINI sections were incorrectly getting a type of 'n'.

Diff Detail


Event Timeline

meadori updated this revision to Diff 78782.Nov 21 2016, 2:09 PM
meadori retitled this revision from to llvm-nm: Print correct symbol types for init and fini sections.
meadori updated this object.
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2019, 6:06 PM
Herald added a subscriber: dexonsmith. · View Herald Transcript
MaskRay added a subscriber: MaskRay.EditedMay 2 2019, 6:08 PM

This copied a bug from GNU nm.

static const struct section_to_type stt[] =
  {".bss", 'b'},
  {"code", 't'},		/* MRI .text */
  {".data", 'd'},
  {"*DEBUG*", 'N'},
  {".debug", 'N'},		/* MSVC's .debug (non-standard debug syms) */
  {".drectve", 'i'},		/* MSVC's .drective section */
  {".edata", 'e'},		/* MSVC's .edata (export) section */
  {".fini", 't'},		/* ELF fini section */
  {".idata", 'i'},		/* MSVC's .idata (import) section */
  {".init", 't'},		/* ELF init section */
  {".pdata", 'p'},		/* MSVC's .pdata (stack unwind) section */
  {".rdata", 'r'},		/* Read only data.  */
  {".rodata", 'r'},		/* Read only data.  */
  {".sbss", 's'},		/* Small BSS (uninitialized data).  */
  {".scommon", 'c'},		/* Small common.  */
  {".sdata", 'g'},		/* Small initialized data.  */
  {".text", 't'},
  {"vars", 'd'},		/* MRI .data */
  {"zerovars", 'b'},		/* MRI .bss */
  {0, 0}

/* Return the single-character symbol type corresponding to
   section S, or '?' for an unknown COFF section.

   Check for any leading string which matches, so .text5 returns
   't' as well as .text */

static char
coff_section_type (const char *s)
  const struct section_to_type *t;

  for (t = &stt[0]; t->section; t++)
    if (!strncmp (s, t->section, strlen (t->section))) ///////// symbols in ".init_array" are incorrectly marked "t"
      return t->type;

  return '?';

The behavior is not consistent with a symbol defined in .preinit_array, e.g.

d __preinit_array_start
t __init_array_start

The more sensible choice is probably to mark both as d.