This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Debug symbols are screwed for a "freestanding" app
- From: Anatol Pomozov <anatol dot pomozov at gmail dot com>
- To: binutils at sourceware dot org
- Date: Sat, 27 Jan 2018 09:44:10 -0800
- Subject: Debug symbols are screwed for a "freestanding" app
- Authentication-results: sourceware.org; auth=none
Hello
I am trying to build a freestanding statically linked x86_64 binary. I
have LinkTimeOptimization enabled.
Here is example of *.c compilation command line I use:
gcc -g -ggdb -flto -nostdlib -ffreestanding -std=c11
-fno-stack-protector -mno-red-zone -fomit-frame-pointer
-fno-math-errno -fno-trapping-math -fno-common -fno-PIC -fno-PIE
-static -W -Wall -Wextra -O3 -mtune=native -MMD -MQ foo.o -MF foo.o.d
-c foo.c -o foo.o
And here is the linked command line:
gcc -Wl,--build-id -Wl,-n -Wl,-Tlinker.ld -flto -nostdlib
-ffreestanding -fno-stack-protector -mno-red-zone -fomit-frame-pointer
-fno-math-errno -fno-trapping-math -fno-common -fno-PIC -fno-PIE
-static foo.o -o foo.elf
I enabled debug symbols using -g flag and see that ELF section is generated.
$ readelf -S foo.elf
There are 17 section headers, starting at offset 0x1a9f68:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .text PROGBITS 0000000000100000 00001000
00000000000169eb 0000000000000000 AX 0 0 16
[ 2] .rodata PROGBITS 0000000000116a00 00017a00
000000000018e3a0 0000000000000000 WA 0 0 32
[ 3] .data PROGBITS 00000000002a4da0 001a5da0
0000000000000014 0000000000000000 WA 0 0 4
[ 4] .got.plt PROGBITS 00000000002a4db8 001a5db8
0000000000000018 0000000000000008 WA 0 0 8
[ 5] .bss NOBITS 00000000002a5000 001a5dd0
00000000000040cc 0000000000000000 WA 0 0 4096
[ 6] .tbss NOBITS 00000000002a90d0 001a5dd0
0000000000009c94 0000000000000000 WAT 0 0 16
[ 7] .note.gnu.build-i NOTE 00000000002a90d0 001a5dd0
0000000000000024 0000000000000000 A 0 0 4
[ 8] .debug_line PROGBITS 0000000000000000 001a5df4
000000000000034e 0000000000000000 0 0 1
[ 9] .debug_info PROGBITS 0000000000000000 001a6142
0000000000000b92 0000000000000000 0 0 1
[10] .debug_abbrev PROGBITS 0000000000000000 001a6cd4
00000000000002dc 0000000000000000 0 0 1
[11] .debug_aranges PROGBITS 0000000000000000 001a6fb0
00000000000000a0 0000000000000000 0 0 16
[12] .debug_str PROGBITS 0000000000000000 001a7050
0000000000000579 0000000000000001 MS 0 0 1
[13] .debug_loc PROGBITS 0000000000000000 001a75c9
00000000000004e0 0000000000000000 0 0 1
[14] .symtab SYMTAB 0000000000000000 001a7ab0
00000000000016f8 0000000000000018 15 215 8
[15] .strtab STRTAB 0000000000000000 001a91a8
0000000000000d1d 0000000000000000 0 0 1
[16] .shstrtab STRTAB 0000000000000000 001a9ec5
00000000000000a1 0000000000000000 0 0 1
It seems fine except that there are few "DW_FORM_strp offset too big" warnings.
$ readelf -w foo.elf > /dev/null
readelf: Warning: DW_FORM_strp offset too big: 5b6
readelf: Warning: DW_FORM_strp offset too big: 588
readelf: Warning: DW_FORM_strp offset too big: 57a
readelf: Warning: DW_FORM_strp offset too big: 5ad
readelf: Warning: DW_FORM_strp offset too big: 5e5
readelf: Warning: DW_FORM_strp offset too big: 602
readelf: Warning: DW_FORM_strp offset too big: 598
readelf: Warning: DW_FORM_strp offset too big: 592
readelf: Warning: DW_FORM_strp offset too big: 5fc
readelf: Warning: DW_FORM_strp offset too big: 619
readelf: Warning: DW_FORM_strp offset too big: 5c4
readelf: Warning: DW_FORM_strp offset too big: 5bb
readelf: Warning: DW_FORM_strp offset too big: 611
readelf: Warning: DW_FORM_strp offset too big: 5ee
readelf: Warning: DW_FORM_strp offset too big: 5d9
readelf: Warning: DW_FORM_strp offset too big: 5cd
When I try to load this file with gdb it says "no debuging symbols found"
$ gdb foo.elf
Type "apropos word" to search for commands related to "word"...
Reading symbols from app.elf...DW_FORM_strp pointing outside of
.debug_str section [in module /home/anatol/sources/foo.elf]
(no debugging symbols found)...done.
I tried to google answer to this question and there is no clear answer
to it. Some people say that it probably some issue between compiler
and linker. Or it might be related to my compilation flags
(freestanding + LTO). Does anyone have a suggestion how to debug this
issue?
My environment is Arch Linux with gcc 7.3.0 and binutils 2.29.1.