Project

General

Profile

Actions

Software #1640

open

Software #1631: XXX Debug memtest86.efi with GDB

Is it necessary to turn off gcc optimization?

Added by Regina Koenig over 1 year ago. Updated over 1 year ago.

Status:
New
Priority:
Normal
Assignee:
-
Start date:
09/01/2022
Due date:
% Done:

0%

Estimated time:
(Total: 0.00 h)

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?


Subtasks 1 (1 open0 closed)

Software #1650: Try to find a position in Code where optimization level makes a differenceNew09/01/2022

Actions
Actions #1

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

Actions #2

Updated by Regina Koenig over 1 year ago

Without changes (original build procedure), memtest.efi has 141K

Actions #3

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

Actions #4

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

Actions #5

Updated by Regina Koenig over 1 year ago

nm lib/string.o
shows that these two symbols are really NOT defined
Actions #6

Updated by Regina Koenig over 1 year ago

But they are also not defined when compiling with official optimization flags

Actions #7

Updated by Regina Koenig over 1 year ago

https://stackoverflow.com/questions/27850184/g-gcc-compiler-is-giving-undefined-reference-error-when-optiomzation-is-turned
gives a hint:

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>
Actions #8

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.

Actions

Also available in: Atom PDF