Software #1640
openSoftware #1631: XXX Debug memtest86.efi with GDB
Is it necessary to turn off gcc optimization?
0%
Description
The single object files are compiled with higher optimization levels (-Os or -O3). Is it a problem for Debugging?
Or is it ok, when the final binary and binary with debug symbols are both compiled with same optimization level?
Updated by Regina Koenig over 1 year ago
Explanation in gcc-documentation:
-Os Optimize for size. -Os enables all -O2 optimizations except those that often increase code size
-O3 Highest opmtimization level
Good choice:
-Og Optimize debugging experience. Enables all -O1 optimization flags except for those that may interfere with debugging
Updated by Regina Koenig over 1 year ago
Without changes (original build procedure), memtest.efi has 141K
Updated by Regina Koenig over 1 year ago
Changing the optimization level results in resolving errors:
system/smp.o: In function `smp_init': /home/koenigr/Memtest/git/memtest86plus_debug/build64/../system/smp.c:558: undefined reference to `memcpy' system/xhci.o: In function `xhci_init': /home/koenigr/Memtest/git/memtest86plus_debug/build64/../system/xhci.c:1017: undefined reference to `memset' Makefile:133: recipe for target 'memtest_shared' failed make: *** [memtest_shared] Error 1
Updated by Regina Koenig over 1 year ago
lib/String.h:
memcpy is __builtin_memcpy
memset is __builtin_memset
These are the only two functions defined this way
Updated by Regina Koenig over 1 year ago
nm lib/string.oshows that these two symbols are really NOT defined
Updated by Regina Koenig over 1 year ago
But they are also not defined when compiling with official optimization flags
Updated by Regina Koenig over 1 year ago
quite simple: if you enable optimization the compiler inlines the function. There is no need to link against the library function. If optimization is switched of, you need the function from the lib. Solution: Link with your library which contains the needed function! You have to add something like g++ -g -O3 use_library.cpp -L<LIBDIR> -l<libname>
Updated by Regina Koenig over 1 year ago
https://stackoverflow.com/questions/11747891/when-builtin-memcpy-is-replaced-with-libcs-memcpy
gives second hint:
When I should prefer of using __builtin_memcpy over plain memcpy? It appears that it uses an inline version when the size is a compile time constant and it's less than or equal to 8192.