Reputation: 745
We have built our code using gcc4.1.2, and we have used function "lstat64" that is defined in the "sys/stat.h" system header file and also defined in a third party library that we use.
When we "nm" our executable, we find that:
W lstat64
My question Is: why gcc marked it as a weak function?
Also, we have ported our code to gcc4.4.4, we found that the new gcc did not marked the function as "weak", it marked it as undefined?
Why this change in behavior?
Upvotes: 3
Views: 430
Reputation: 26800
As per the GCC documentation:
weak
The weak attribute causes the declaration to be emitted as a weak symbol rather than a global. This is primarily useful in defining library functions which can be overridden in user code, though it can also be used with non-function declarations. Weak symbols are supported for ELF targets, and also for a.out targets when using the GNU assembler and linker.
In your case lstat64
was probably marked as weak in GCC 4.1.2 because it would then not conflict with the third party library function. GCC probably wanted these external functions to have precedence.
But in a later version, GCC would have wanted its own version of lstat64
to have precedence.
Upvotes: 3