public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [Bug default/24733] New: [dwz] Verify/update symbol table
@ 2019-01-01  0:00 vries at gcc dot gnu.org
  0 siblings, 0 replies; only message in thread
From: vries at gcc dot gnu.org @ 2019-01-01  0:00 UTC (permalink / raw)
  To: dwz

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

            Bug ID: 24733
           Summary: [dwz] Verify/update symbol table
           Product: dwz
           Version: unspecified
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: default
          Assignee: nobody at sourceware dot org
          Reporter: vries at gcc dot gnu.org
                CC: dwz at sourceware dot org
  Target Milestone: ---

[ Spinoff of PR24249 comment 8 ]

Consider an hello world executable hello.

It contains these sections:
...
$ readelf -S hello | grep '\[' | sed 's/[]]//;s/[[]//' | awk '{print $1, $2}'
Nr Name
0 NULL
1 .interp
2 .note.ABI-tag
3 .note.gnu.build-i
4 .hash
5 .gnu.hash
6 .dynsym
7 .dynstr
8 .gnu.version
9 .gnu.version_r
10 .rela.dyn
11 .rela.plt
12 .init
13 .plt
14 .text
15 .fini
16 .rodata
17 .eh_frame_hdr
18 .eh_frame
19 .init_array
20 .fini_array
21 .dynamic
22 .got
23 .got.plt
24 .data
25 .bss
26 .comment
27 .debug_aranges
28 .debug_info
29 .debug_abbrev
30 .debug_line
31 .debug_str
32 .debug_loc
33 .debug_ranges
34 .symtab
35 .strtab
36 .shstrtab
...

Now say we self-dwz-m hello into hello.1:
...
$ cp hello hello.1; cp hello.1 hello.2; dwz -m hello.dwz hello.1 hello.2
...

which has these sections:
...
Nr Name
0 NULL
1 .interp
2 .note.ABI-tag
3 .note.gnu.build-i
4 .hash
5 .gnu.hash
6 .dynsym
7 .dynstr
8 .gnu.version
9 .gnu.version_r
10 .rela.dyn
11 .rela.plt
12 .init
13 .plt
14 .text
15 .fini
16 .rodata
17 .eh_frame_hdr
18 .eh_frame
19 .init_array
20 .fini_array
21 .dynamic
22 .got
23 .got.plt
24 .data
25 .bss
26 .comment
27 .debug_aranges
28 .debug_info
29 .debug_abbrev
30 .debug_line
31 .debug_loc
32 .debug_ranges
33 .gnu_debugaltlink
34 .symtab
35 .strtab
36 .shstrtab
...

So, a diff of:
...
$ diff -u 1 2
--- 1   2019-06-25 15:40:11.224007571 +0200
+++ 2   2019-06-25 15:40:08.448025900 +0200
@@ -30,9 +30,9 @@
 28 .debug_info
 29 .debug_abbrev
 30 .debug_line
-31 .debug_str
-32 .debug_loc
-33 .debug_ranges
+31 .debug_loc
+32 .debug_ranges
+33 .gnu_debugaltlink
 34 .symtab
 35 .strtab
 36 .shstrtab
...

Now, hello has a symbol table:
...
Symbol table '.dynsym' contains 4 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND puts@GLIBC_2.2.5 (2)
     2: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND
__libc_start_main@GLIBC_2.2.5 (2)
     3: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__

Symbol table '.symtab' contains 70 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000400238     0 SECTION LOCAL  DEFAULT    1 
     2: 0000000000400254     0 SECTION LOCAL  DEFAULT    2 
     3: 0000000000400274     0 SECTION LOCAL  DEFAULT    3 
     4: 0000000000400298     0 SECTION LOCAL  DEFAULT    4 
     5: 00000000004002c0     0 SECTION LOCAL  DEFAULT    5 
     6: 00000000004002e0     0 SECTION LOCAL  DEFAULT    6 
     7: 0000000000400340     0 SECTION LOCAL  DEFAULT    7 
     8: 000000000040037e     0 SECTION LOCAL  DEFAULT    8 
     9: 0000000000400388     0 SECTION LOCAL  DEFAULT    9 
    10: 00000000004003a8     0 SECTION LOCAL  DEFAULT   10 
    11: 00000000004003d8     0 SECTION LOCAL  DEFAULT   11 
    12: 00000000004003f0     0 SECTION LOCAL  DEFAULT   12 
    13: 0000000000400410     0 SECTION LOCAL  DEFAULT   13 
    14: 0000000000400430     0 SECTION LOCAL  DEFAULT   14 
    15: 0000000000400594     0 SECTION LOCAL  DEFAULT   15 
    16: 00000000004005a0     0 SECTION LOCAL  DEFAULT   16 
    17: 00000000004005ac     0 SECTION LOCAL  DEFAULT   17 
    18: 00000000004005e0     0 SECTION LOCAL  DEFAULT   18 
    19: 0000000000600e00     0 SECTION LOCAL  DEFAULT   19 
    20: 0000000000600e08     0 SECTION LOCAL  DEFAULT   20 
    21: 0000000000600e10     0 SECTION LOCAL  DEFAULT   21 
    22: 0000000000600ff0     0 SECTION LOCAL  DEFAULT   22 
    23: 0000000000601000     0 SECTION LOCAL  DEFAULT   23 
    24: 0000000000601020     0 SECTION LOCAL  DEFAULT   24 
    25: 0000000000601030     0 SECTION LOCAL  DEFAULT   25 
    26: 0000000000000000     0 SECTION LOCAL  DEFAULT   26 
    27: 0000000000000000     0 SECTION LOCAL  DEFAULT   27 
    28: 0000000000000000     0 SECTION LOCAL  DEFAULT   28 
    29: 0000000000000000     0 SECTION LOCAL  DEFAULT   29 
    30: 0000000000000000     0 SECTION LOCAL  DEFAULT   30 
    31: 0000000000000000     0 SECTION LOCAL  DEFAULT   31 
    32: 0000000000000000     0 SECTION LOCAL  DEFAULT   32 
    33: 0000000000000000     0 SECTION LOCAL  DEFAULT   33 
    34: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS init.c
    35: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
    36: 0000000000400460     0 FUNC    LOCAL  DEFAULT   14 deregister_tm_clones
    37: 0000000000400490     0 FUNC    LOCAL  DEFAULT   14 register_tm_clones
    38: 00000000004004d0     0 FUNC    LOCAL  DEFAULT   14
__do_global_dtors_aux
    39: 0000000000601030     1 OBJECT  LOCAL  DEFAULT   25 completed.6990
    40: 0000000000600e08     0 OBJECT  LOCAL  DEFAULT   20
__do_global_dtors_aux_fin
    41: 0000000000400500     0 FUNC    LOCAL  DEFAULT   14 frame_dummy
    42: 0000000000600e00     0 OBJECT  LOCAL  DEFAULT   19
__frame_dummy_init_array_
    43: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS hello.c
    44: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS elf-init.c
    45: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
    46: 00000000004006cc     0 OBJECT  LOCAL  DEFAULT   18 __FRAME_END__
    47: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS 
    48: 0000000000600e08     0 NOTYPE  LOCAL  DEFAULT   19 __init_array_end
    49: 0000000000600e10     0 OBJECT  LOCAL  DEFAULT   21 _DYNAMIC
    50: 0000000000600e00     0 NOTYPE  LOCAL  DEFAULT   19 __init_array_start
    51: 00000000004005ac     0 NOTYPE  LOCAL  DEFAULT   17 __GNU_EH_FRAME_HDR
    52: 0000000000601000     0 OBJECT  LOCAL  DEFAULT   23
_GLOBAL_OFFSET_TABLE_
    53: 0000000000400590     2 FUNC    GLOBAL DEFAULT   14 __libc_csu_fini
    54: 0000000000601020     0 NOTYPE  WEAK   DEFAULT   24 data_start
    55: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND puts@@GLIBC_2.2.5
    56: 0000000000601030     0 NOTYPE  GLOBAL DEFAULT   24 _edata
    57: 0000000000400594     0 FUNC    GLOBAL DEFAULT   15 _fini
    58: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND
__libc_start_main@@GLIBC_
    59: 0000000000601020     0 NOTYPE  GLOBAL DEFAULT   24 __data_start
    60: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
    61: 0000000000601028     0 OBJECT  GLOBAL HIDDEN    24 __dso_handle
    62: 00000000004005a0     4 OBJECT  GLOBAL DEFAULT   16 _IO_stdin_used
    63: 0000000000400520   101 FUNC    GLOBAL DEFAULT   14 __libc_csu_init
    64: 0000000000601038     0 NOTYPE  GLOBAL DEFAULT   25 _end
    65: 0000000000400430    43 FUNC    GLOBAL DEFAULT   14 _start
    66: 0000000000601030     0 NOTYPE  GLOBAL DEFAULT   25 __bss_start
    67: 0000000000400507    21 FUNC    GLOBAL DEFAULT   14 main
    68: 0000000000601030     0 OBJECT  GLOBAL HIDDEN    24 __TMC_END__
    69: 00000000004003f0     0 FUNC    GLOBAL DEFAULT   12 _init
...

The Ndx corresponds to st_shndx:
...
Every symbol table entry is ‘‘defined’’ in relation to some section;
this member holds the relevant section header table index.
...

Intestingly, hello.1 has the exact same symbol table.

So, if we look at:
...
    33: 0000000000000000     0 SECTION LOCAL  DEFAULT   33 
...
then in hello this refers to .debug_ranges while in hello.1 this refers to
.gnu_debugaltlink.

For STT_SECTION we have:
...
The symbol is associated with a section. Symbol table entries of
this type exist primarily for relocation and normally have
STB_LOCAL binding.
...

So while this seems inconsistent, it also doesn't seem harmful, since dwz only
works on executables/shared libs, where relocation is already done. So, this is
somewhat similar to PR24345 - "Dwz invalidates debug sections generated by
--emit-relocs".

But, we could remove the symbol related to the removed section:
...
    31: 0000000000000000     0 SECTION LOCAL  DEFAULT   31 
...
and update Ndx for the two following symbols:
...
    32: 0000000000000000     0 SECTION LOCAL  DEFAULT   32 
    33: 0000000000000000     0 SECTION LOCAL  DEFAULT   33 
...

Likewise, we currently don't make an attempt to update any of the other
symbols.  The range of the non-section symbols is 12-25:
...
$ readelf -s hello | grep -v SECTION | awk '{print $7}' | egrep -v
'ABS|UND|Ndx' | sort -u -n

12
14
15
16
17
18
19
20
21
23
24
25
...
and is in the SHF_ALLOC part which dwz doesn't update.  But we don't actually
check that the update is not necessary.

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-06-25 14:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-01  0:00 [Bug default/24733] New: [dwz] Verify/update symbol table vries at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).