zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.88k stars 6.63k forks source link

Provide a way to define symbols in app project needed by static libraries #44035

Open rweickelt opened 2 years ago

rweickelt commented 2 years ago

When linking external libraries (libext), it is sometimes desired to leave a symbol in the library undefined and to provide it in the application code. This is usually not a problem when linking application object files because the linker will always look into application objects when obtaining an undefined symbol.

But zephyr builds the application as a static library (libapp). Since libapp appears before libext on the linker command line, the desired symbol will not be found. It should be noted that the library link order is correct. It's just not expected that zephyr app target is a static library itself.

Please provide a way to easily add an external library to zephyrs whole-archive group or a different solution.

erwango commented 2 years ago

Please update title

rweickelt commented 2 years ago

Sorry, the title got lost.

zephyrbot commented 9 months ago

Hi @tejlmand,

This issue, marked as an Feature Request, was opened a while ago and did not get any traction. It was just assigned to you based on the labels. If you don't consider yourself the right person to address this issue, please re-assing it to the right person.

Please take a moment to review if the issue is still relevant to the project. If it is, please provide feedback and direction on how to move forward. If it is not, has already been addressed, is a duplicate, or is no longer relevant, please close it with a short comment explaining the reason.

@rweickelt you are also encouraged to help moving this issue forward by providing additional information and confirming this request/issue is still relevant to you.

Thanks!

nordicjm commented 2 days ago

Not sure I follow what is being asked here, but have you tried looking into llext? https://docs.zephyrproject.org/latest/services/llext/index.html

rweickelt commented 2 days ago

No, I am not talking about runtime-linking.

Let's assume I am linking libExt into my Zephyr project. libExt has undefined symbols (on purpose). That can be a application-specific function or a global variable or something like that. I want to use link-time optimization (LTO) and thus I don't want to hand pointers over at run-time.

In a usual embedded project where I build my application I would implement the desired function directly in the application project. The linker will notice the missing symbol in libExt.a and always look for it in the application's object files.

The Zephyr build system builds the application project as a library (libApp) before linking everything together. In that case, the missing symbol from libExt.a that is now part of libApp is not found by the linker. That is probably because libExt appears before libApp on the linker command line which is unexpected.

I am looking for a way to solve this particular build system problem.