iPXE discussion forum
Building with debug symbols - Printable Version

+- iPXE discussion forum (https://forum.ipxe.org)
+-- Forum: iPXE user forums (/forumdisplay.php?fid=1)
+--- Forum: General (/forumdisplay.php?fid=2)
+--- Thread: Building with debug symbols (/showthread.php?tid=17374)



Building with debug symbols - ebruno - 2019-02-04 17:12

I am trying to build with debugging symbols. I was able to build with gdbudp included. But I am missing something when attempting to build with debug symbols . I tried setting EXTRA_CFLAGS to -g and CFLAGS to -g but when open the the image with gdb I get the message

Reading symbols from bin-x86_64-efi/snp--intelx.efi.tmp...(no debugging symbols found)...done.

Any pointers on how to enable "-g" during compile.


RE: Building with debug symbols - mcb30 - 2019-02-04 17:21

(2019-02-04 17:12)ebruno Wrote:  I am trying to build with debugging symbols. I was able to build with gdbudp included. But I am missing something when attempting to build with debug symbols . I tried setting EXTRA_CFLAGS to -g and CFLAGS to -g but when open the the image with gdb I get the message

Reading symbols from bin-x86_64-efi/snp--intelx.efi.tmp...(no debugging symbols found)...done.

Any pointers on how to enable "-g" during compile.

It should be enabled by default anyway. Add "V=1" to the make command line to see the raw build commands.

Michael


RE: Building with debug symbols - ebruno - 2019-02-04 18:01

I can see the -g flag in the compile , see sample below:
gcc -E -DARCH=x86_64 -DPLATFORM=efi -DSECUREBOOT=0 -fstrength-reduce -fomit-frame-pointer -falign-jumps=1 -falign-loops=1 -falign-functions=1 -m64 -mno-mmx -mno-sse -fshort-wchar -Ui386 -Ulinux -DNVALGRIND -fpie -mno-red-zone -Iinclude -I. -Iarch/x86/include -Iarch/x86_64/include -Iarch/x86_64/include/efi -Os -g -ffreestanding -Wall -W -Wformat-nonliteral -fno-stack-protector -fno-dwarf2-cfi-asm -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wno-address -g -Werror -ffunction-sections -fdata-sections -include include/compiler.h -DASM_TCHAR='@' -DASM_TCHAR_OPS='@' -DOBJECT=dhcpopts -Wno-error -M net/dhcpopts.c -MG -MP | sed 's/\.o\s*:/_DEPS +=/' > bin-x86_64-efi/deps/net/dhcpopts.c.d
[DEPS] net/fcoe.c

Here is the final link command.

ld -m elf_x86_64 -q -S --gc-sections -static -T scripts/efi.lds -u _efi_start --defsym check__efi_start=_efi_start -u obj_snp --defsym check_obj_snp=obj_snp -u obj_intelx --defsym check_obj_intelx=obj_intelx -u obj_config --defsym check_obj_config=obj_config -u obj_config_efi --defsym check_obj_config_efi=obj_config_efi --defsym pci_vendor_id=0 --defsym pci_device_id=0 -e _efi_start bin-x86_64-efi/version.snp--intelx.efi.o bin-x86_64-efi/blib.a -o bin-x86_64-efi/snp--intelx.efi.tmp \
--defsym _build_id=`perl -e 'printf "0x%08x", int ( rand ( 0xffffffff ) );'` \
--defsym _build_timestamp=1549298277 \
-Map bin-x86_64-efi/snp--intelx.efi.tmp.map
objdump -ht bin-x86_64-efi/snp--intelx.efi.tmp | perl ./util/sortobjdump.pl >> bin-x86_64-efi/snp--intelx.efi.tmp.map
./util/elf2efi64 --subsystem=10 bin-x86_64-efi/snp--intelx.efi.tmp bin-x86_64-efi/snp--intelx.efi

When attempt to load the file in to gdb I get

gdb snp--intelx.efi
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright © 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
BFD: /home/XXXX/ipxe/src/bin-x86_64-efi/snp--intelx.efi: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .text
BFD: /home/XXXX/ipxe/src/bin-x86_64-efi/snp--intelx.efi: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .rodata
BFD: /home/XXXX/ipxe/src/bin-x86_64-efi/snp--intelx.efi: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .data
BFD: /home/XXXX/ipxe/src/bin-x86_64-efi/snp--intelx.efi: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .bss
BFD: /home/XXXX/ipxe/src/bin-x86_64-efi/snp--intelx.efi: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .reloc
BFD: /home/XXXX/ipxe/src/bin-x86_64-efi/snp--intelx.efi: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .debug
Reading symbols from snp--intelx.efi...(no debugging symbols found)...done.


RE: Building with debug symbols - ebruno - 2019-02-27 01:12

Digging in to this a bit more found in src/Makefile.efl line 9 LDFLAGS += -q -S

-S tells the linker to strip Omit debugger symbol information (but not all symbols) from the output file.

However when build with the -S flag I get

ld -m elf_x86_64 -q --gc-sections -static -T scripts/efi.lds -u _efi_start --defsym check__efi_start=_efi_start -u obj_snp --defsym check_obj_snp=obj_snp -u obj_intelx --defsym c\
heck_obj_intelx=obj_intelx -u obj_config --defsym check_obj_config=obj_config -u obj_config_efi --defsym check_obj_config_efi=obj_config_efi --defsym pci_vendor_id=0 --defsym pci_dev\
ice_id=0 -e _efi_start bin-x86_64-efi/version.snp--intelx.efi.o bin-x86_64-efi/blib.a -o bin-x86_64-efi/snp--intelx.efi.tmp \
--defsym _build_id=`perl -e 'printf "0x%08x", int ( rand ( 0xffffffff ) );'` \
--defsym _build_timestamp=1551225293 \
-Map bin-x86_64-efi/snp--intelx.efi.tmp.map
objdump -ht bin-x86_64-efi/snp--intelx.efi.tmp | perl ./util/sortobjdump.pl >> bin-x86_64-efi/snp--intelx.efi.tmp.map
./util/elf2efi64 --subsystem=10 bin-x86_64-efi/snp--intelx.efi.tmp bin-x86_64-efi/snp--intelx.efi
Unrecognised relocation type 10
Makefile.efi:25: recipe for target 'bin-x86_64-efi/snp--intelx.efi' failed
make[2]: *** [bin-x86_64-efi/snp--intelx.efi] Error 1
rm bin-x86_64-efi/version.snp--intelx.efi.o



snp--intelx.efi.tmp now has debug symbols
ericb@bsdpemulator-01:~/SystemReprovisioningTools/ZeroTouchOS$ gdb ipxe/src/bin-x86_64-efi/snp--intelx.efi.tmp
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright © 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ipxe/src/bin-x86_64-efi/snp--intelx.efi.tmp...done.
(gdb) list
14
15 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
16
17 #include <stddef.h>
18 #include <stdio.h>
19 #include <ipxe/init.h>
20 #include <ipxe/version.h>
21 #include <usr/autoboot.h>
22
23 /**
(gdb) list main
23 /**
24 * Main entry point
25 *
26 * @ret rc Return status code
27 */
28 __asmcall int main ( void ) {
29 int rc;
30
31 /* Perform one-time-only initialisation (e.g. heap) */
32 initialise();

If add -S to LDFLAGS the build completes but no debug symbols in the binaries.

/util/elf2efi64 seems to application having an issue.

/util/elf2efi64 --subsystem=10 bin-x86_64-efi/snp--intelx.efi.tmp bin-x86_64-efi/snp--intelx.efi
Unrecognised relocation type 10
Makefile.efi:25: recipe for target 'bin-x86_64-efi/snp--intelx.efi' failed