[dpdk-dev] [PATCH 2/2] bpf: remove use of weak functions

Bruce Richardson bruce.richardson at intel.com
Wed Apr 10 16:27:39 CEST 2019


On Wed, Apr 10, 2019 at 10:07:33AM -0400, Aaron Conole wrote:
> Bruce Richardson <bruce.richardson at intel.com> writes:
> 
> > Weak functions don't work well with static libraries and require the use of
> > "whole-archive" flag to ensure that the correct function is used when
> > linking.  Since the weak function is only used as a placeholder within this
> > library alone, we can replace it with a non-weak version protected using
> > preprocessor ifdefs.
> >
> > Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
> > ---
> 
> I agree with dropping the weak implementations.
> 
> But, can't we adjust the order of objects when building with multiple
> strong definitions and the linker will choose the first?  I know this
> works for the GNU linker.
> 
> I do find this information to help support this statement:
> 
> https://stackoverflow.com/questions/51656838/attribute-weak-and-static-libraries
> 
> Unfortunately, I don't find anything in the C standard to govern entity
> precedence.  This means it isn't something that works across linker
> implementations (but compatible implementations like clang will maintain
> that behavior).
> 
It may be possible, but I'd be worried about the fragility of the support.
Is it a good idea to have multiple implementations of a function in a .a
file. Without running the resulting binary, we have no way of knowing the
correct function was picked up. At least with the weak versions, we can see
from nm what is used.

/Bruce


More information about the dev mailing list