Weak symbol in an executable, overridable by shared libraries at runtime

H.J. Lu hjl.tools@gmail.com
Sun Nov 3 12:05:00 GMT 2013


On Sat, Nov 2, 2013 at 2:44 PM, Lorenzo Pistone <blaffablaffa@gmail.com> wrote:
> Hello,
> 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.
>
> Cheers.

The secondary symbol is what you are looking for. But it isn't supported
everywhere.

-- 
H.J.



More information about the Binutils mailing list