Does the LD --wrap feature work for library internal references?

Sebastian Huber sebastian.huber@embedded-brains.de
Wed Dec 19 13:11:00 GMT 2018


Hello,

I would like to use the LD --wrap feature to wrap a library internal 
function (in libbsd.a in this example).

https://sourceware.org/binutils/docs/ld/Options.html#index-_002d_002dwrap_003dsymbol

For one function this seems to work:

/build/rtems/5/bin/powerpc-rtems5-gcc -Wl,--wrap=_bsd_ether_ifattach 
-qrtems -B/build/rtems/5/powerpc-rtems5/lib/ 
-B/build/rtems/5/powerpc-rtems5/qoriq_e6500_32/lib/ --specs bsp_specs 
-mcpu=e6500 -mcpu=e6500 -m32 -m32 -msdata=sysv -msdata=sysv -fno-common 
-fno-common -ffunction-sections -ffunction-sections -fdata-sections 
-fdata-sections -Wl,--gc-sections testsuite/media01/test_main.c.38.o 
testsuite/media01/dpaa_if_input.c.38.o -o 
/scratch/git-rtems-libbsd/build/powerpc-rtems5-qoriq_e6500_32-default/media01.exe 
-Wl,-Bstatic -L. -lbsd -Wl,-Bdynamic -lftpd -ltelnetd -lbsd -lm
/build/rtems/5/lib/gcc/powerpc-rtems5/7.4.0/../../../../powerpc-rtems5/bin/ld: 
./libbsd.a(if_bridge.c.18.o): in function `bridge_clone_create':
/scratch/git-rtems-libbsd/build/powerpc-rtems5-qoriq_e6500_32-default/../../freebsd/sys/net/if_bridge.c:702: 
undefined reference to `__wrap__bsd_ether_ifattach'
/build/rtems/5/lib/gcc/powerpc-rtems5/7.4.0/../../../../powerpc-rtems5/bin/ld: 
./libbsd.a(if_lagg.c.18.o): in function `lagg_clone_create':
/scratch/git-rtems-libbsd/build/powerpc-rtems5-qoriq_e6500_32-default/../../freebsd/sys/net/if_lagg.c:528: 
undefined reference to `__wrap__bsd_ether_ifattach'
/build/rtems/5/lib/gcc/powerpc-rtems5/7.4.0/../../../../powerpc-rtems5/bin/ld: 
./libbsd.a(if_vlan.c.18.o): in function `vlan_clone_create':
/scratch/git-rtems-libbsd/build/powerpc-rtems5-qoriq_e6500_32-default/../../freebsd/sys/net/if_vlan.c:1071: 
undefined reference to `__wrap__bsd_ether_ifattach'
/build/rtems/5/lib/gcc/powerpc-rtems5/7.4.0/../../../../powerpc-rtems5/bin/ld: 
./libbsd.a(if_fmanmac.c.18.o): in function `fman_mac_dev_attach':
/scratch/git-rtems-libbsd/build/powerpc-rtems5-qoriq_e6500_32-default/../../rtemsbsd/sys/powerpc/drivers/net/ethernet/freescale/dpaa/if_fmanmac.c:471: 
undefined reference to `__wrap__bsd_ether_ifattach'

If I add

void
__wrap__bsd_ether_ifattach(struct ifnet *ifp, const u_int8_t *lla)
{
     puts("ether_ifattach");
     __real__bsd_ether_ifattach(ifp, lla);
}

then I get the expected output.

nm media01.exe | grep ether_ifattach
0001a670 T _bsd_ether_ifattach
00005a30 T __wrap__bsd_ether_ifattach

For another it doesn't work:

/build/rtems/5/bin/powerpc-rtems5-gcc -Wl,--wrap=_bsd_ether_output 
-qrtems -B/build/rtems/5/powerpc-rtems5/lib/ 
-B/build/rtems/5/powerpc-rtems5/qoriq_e6500_32/lib/ --specs bsp_specs 
-mcpu=e6500 -mcpu=e6500 -m32 -m32 -msdata=sysv -msdata=sysv -fno-common 
-fno-common -ffunction-sections -ffunction-sections -fdata-sections 
-fdata-sections -Wl,--gc-sections testsuite/media01/test_main.c.38.o 
testsuite/media01/dpaa_if_input.c.38.o -o 
/scratch/git-rtems-libbsd/build/powerpc-rtems5-qoriq_e6500_32-default/media01.exe 
-Wl,-Bstatic -L. -lbsd -Wl,-Bdynamic -lftpd -ltelnetd -lbsd -lm

It links, I would have expected an undefined reference to 
__wrap__bsd_ether_output. In the executable I find this:

nm media01.exe | grep ether_output
0001b640 T _bsd_ether_output

It is not clear to me why it works with one function and not with another.

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.



More information about the Binutils mailing list