-O    --> works
-O2  --> works
-O3  --> works
-O0  --> fails
-Os  --> works
Because it builds when optimization is on, and because the error you
posted in your original post is a linker error, that leads me to the
following hypothesis:

I think that with optimization turned on, there is some automatic dead
code removal happening. That is, functions that are unused are removed
from the link. ...

I don't think so.  static inline functions never generate code if they are not referenced and included inline.

More likely is the fact that inlining is disabled at -O0 and now the functions really are implemented as static functions and generate static functions.  Now you really do have unreferenced static functions.  Try removing the static storage class from the inline prototypes.



Those functions, the unused ones removed from the link,
are calling other functions that are not found because preprocessor
conditional logic (based on Kconfig settings) is excluding them from
ever being compiled. But everything builds successfully because the
linker doesn't care about resolving dependencies of functions that are
never called.

But... With optimization turned off, the linker is trying to link
everything, including the unused functions, and then it realizes that
it can't find the nonexistent functions referenced by the unused
functions.

How's that for long-winded?

Again, this is a *hypothesis* based on everything I read in this thread so far.

You might want to check if your default options include
-ffunction-sections, -fdata-sections, and/or -Wl,–gc-sections. If so,
that would be in favor of the above.

Cheers,
Nathan


Reply via email to