This is the mail archive of the
mailing list for the binutils project.
Weak symbol in an executable, overridable by shared libraries at runtime
- From: Lorenzo Pistone <blaffablaffa at gmail dot com>
- To: binutils at sourceware dot org
- Date: Sat, 02 Nov 2013 22:44:32 +0100
- Subject: Weak symbol in an executable, overridable by shared libraries at runtime
- Authentication-results: sourceware.org; auth=none
Is there a way to define a weak symbol in an executable (not a .so!),
that can be overridden by the runtime linking process by a symbol found
in another library?
The aim is to provide a fallback implementation, within my executable,
for systems where a specific function in a standard library cannot be
found. More exactly, if I compile my program with -ffast-math, some
calls to __pow_finite are generated: on recent systems this function is
in libm.so, but on older systems this function simply does not exist.
The idea is then to have a weak symbol "__pow_infinite" in my
executable, whose implementation just calls the normal "pow": this way,
on a recent system, the weak symbol is overridden and the libm.so
version is used, whereas on an old system there's no other symbol than
the weak one, that would be then picked up.