n0p
n0p

Reputation: 3496

How to identify which file implicitly relies on linkage with a library?

I am working on en embedded project. I have integrated open source sub-projects in it (i.e. code I did not write). Compilation is fine but I have linkage errors:

gcc-arm-none-eabi-7-2018-q2-update/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libc.a(lib_a-abort.o):
In function `abort': abort.c:(.text.abort+0xa): undefined reference to `_exit'
gcc-arm-none-eabi-7-2018-q2-update/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libc.a(lib_a-signalr.o):
In function `_kill_r': signalr.c:(.text._kill_r+0x10): undefined reference to `_kill'
gcc-arm-none-eabi-7-2018-q2-update/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard/libc.a(lib_a-signalr.o):
In function `_getpid_r': signalr.c:(.text._getpid_r+0x0): undefined reference to `_getpid' collect2: error: ld returned 1 exit status

I also had errors about undefeined reference to _exit but I fixed these by searching & replacing calls to exit(1).

I tried to search & replace calls to abort() but I still have these errors.

I found some similar questions resolved by adding linker options -specs=nosys.specs but this is not what I want. I want to modify the code so that I can handle errors gracefully without brutally exiting the entire program and to do that I have to find which code relies on this link.

Upvotes: 0

Views: 257

Answers (1)

Employed Russian
Employed Russian

Reputation: 213506

I tried to search & replace calls to abort() but I still have these errors.

I think you are asking: "how to find code that calls abort (after replacing all calls that you can find)?"

If that is indeed your question, use -y linker option. For example:

gcc main.o foo.o bar.o -Wl,-y,abort

/usr/bin/ld: bar.o: reference to abort
/usr/bin/ld: //lib/x86_64-linux-gnu/libc.so.6: definition of abort

P.S. Your build of .../v7e-m/fpv4-sp/hard/libc.a is highly unusual: generally if it defines abort and exit, it should also define _exit.

Upvotes: 1

Related Questions