We find this bug when we run gdb test gdb.dwarf2/dwz.exp. Here are the steps to reproduce this bug: 1. Compile and link $ gcc 1.c -c -o 1.o $ gcc 2.c -c -o 2.o $ gcc dwz.S -c -o dwz.o $ build-x86/ld/ld-new 1.o dwz.o 2.o --wrap main -o 1.exe 2. Examine the address of main and __wrap_main $ readelf -s 1.exe | grep main 10: 08048088 18 FUNC GLOBAL DEFAULT 1 __wrap_main 12: 08048074 20 FUNC GLOBAL DEFAULT 1 main 3. Examine the DW_AT_low_pc attribute for main, $ readelf -wi ./1.exe Contents of the .debug_info section: Compilation Unit @ offset 0x0: Length: 0x17 (32-bit) Version: 4 Abbrev Offset: 0x0 Pointer Size: 4 <0><b>: Abbrev Number: 2 (DW_TAG_partial_unit) <1><c>: Abbrev Number: 3 (DW_TAG_subprogram) <d> DW_AT_name : main <12> DW_AT_low_pc : 0x8048088 <------- [1] <16> DW_AT_high_pc : 0x8048092 As we can see, DW_AT_low_pc should be the address of main instead of __wrap_main, otherwise, GDB will be confused. We find this problem on both x86 and arm targets.
Created attachment 7587 [details] dwz.S $ cat 1.c int main (void) { return 0; } $ cat 2.c int __wrap_main (void) { __real_main (); return 0; }
commit b71c404358dbc78d3e84c4299c6139c5291ac441 Author: Alan Modra <amodra@gmail.com> Date: Tue Jun 10 23:07:52 2014 +0930 add pr number to changelog commit 7b8e2718e4412ddc1e42c6a68166de919eb62221 Author: Alan Modra <amodra@gmail.com> Date: Tue Jun 10 23:02:55 2014 +0930 missing changelog entries for 8a5da09b9 commit 8a5da09b9e326a19e78b20a1021a5148ea0484b0 Author: Alan Modra <amodra@gmail.com> Date: Tue Jun 10 21:50:21 2014 +0930 Unwrap symbols for debug information Fixes issues with dwz multi-file (-m) and ld's -wrap option. Symbols referenced from DWARF debug info in a separate file, eg. to specify low and high pc, must use the real symbol. The DWARF info is specifying attributes of the real function, not one interposed with --wrap. include/ * bfdlink.h (unwrap_hash_lookup): Declare. bfd/ * linker.c (unwrap_hash_lookup): New function. * elf-bfd (RELOC_FOR_GLOBAL_SYMBOL): Call unwrap_hash_lookup. * elf32-i370.c (i370_elf_relocate_section): Likewise. * elf32-m32c.c (m32c_elf_relocate_section): Likewise. * elf32-m32r.c (m32r_elf_relocate_section): Likewise. * elf32-score.c (s3_bfd_score_elf_relocate_section): Likewise. * elf32-score7.c (s7_bfd_score_elf_relocate_section): Likewise. * elf32-spu.c (spu_elf_relocate_section): Likewise. * elf64-hppa.c (elf64_hppa_relocate_section): Likewise.
commit 7ed689ad61de0cbfe4e5a6f18f097776128202e4 Author: Alan Modra <amodra@gmail.com> Date: Wed Jun 11 19:11:12 2014 +0930 Fix silly thinko * linker.c (unwrap_hash_lookup): Add missing parens.