Why does -O-gcc call "stat" to solve?

I tried to do a search, but found nothing. Whenever I try to compile a shared object and a test binary that references it, I get this error:

[root@hypervisor test-files]# ./test
./test: symbol lookup error: ./test-files.so: undefined symbol: stat
[root@hypervisor test-files]#

After playing with her, I found that if I feed -Oto gcc at compile time, stat () will start working as expected. I was not able to find any signal on the Internet about why -O everything fixes the problem with the undefined character (or is it just masking the error and not fixing it?).

+3
source share
1 answer

In all likelihood, optimization caused the removal of unreachable code, completely eliminating the need for a character.

test-files.so, , C, ld . , , test-files.so , . , test, .

, stat, dlopen().

+1

Source: https://habr.com/ru/post/1678294/


All Articles