4

I am writing a bare metal application and am running into an issue that I believe is related to the linker.

Issue:

IRQ handler is not being linked from the static library provided. The IRQ is declared outside of the library with __attribute__ ((weak, alias("defaultInterrupt"))). When this attribute is provided, the IRQ is not linked. When the attribute is removed, the IRQ is linked.

This post: Linking with static library not equivalent to linking with its objects indicates that the issue may be with the linker not finding the strong declaration because it stops searching, but does not suggest a fix.

Question:

Is there any way to ensure that the linker will find the strongly declared function?

Environment:

I am using arm-none-eabi-ld distributed by ARM, found here: arm-none-eabi

Already Attempted:

Re-ordering the libraries passed to the linker

Community
  • 1
  • 1
user2328113
  • 143
  • 5
  • 3
    The linked question does provide a solution. Perhaps you missed it so it is worth trying if you have not already tried: "This is solved by surrounding the static library with the --whole-archive and --no-whole-archive linker flags". – kaylum May 03 '16 at 02:26
  • @kaylum, thanks for responding. Correct me if I'm wrong, but that would include the entire library. As this is a bare metal application, my flash space is limited and including the entire library is not a viable option. – user2328113 May 03 '16 at 02:42
  • 1
    You could extract that object file from your static library (use `ar x`) and explicitly include it in the linker command line - I think that will force the linker to include it. Or, you could explicitly reference some other symbol defined within that object file. Do you have the source code to the static library? – Nate Eldredge May 03 '16 at 04:15

1 Answers1

1

It appears that a similar question was asked quite some time ago in a galaxy not at all far away: Override weak symbols in static library

tl;dr; The take away is that the weak attribute doesn't apply as one would expect in static archive libraries. The linker stops searching at the first encounter of the target symbol name. The author of the accepted answer explains that weak may only make sense for shared objects.

Community
  • 1
  • 1
2bluesc
  • 372
  • 4
  • 7