public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Does the LD --wrap feature work for library internal references?
@ 2018-12-19 13:11 Sebastian Huber
  2019-01-03 15:49 ` Nick Clifton
  0 siblings, 1 reply; 28+ messages in thread
From: Sebastian Huber @ 2018-12-19 13:11 UTC (permalink / raw)
  To: binutils

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.

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2019-01-29 11:02 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-19 13:11 Does the LD --wrap feature work for library internal references? Sebastian Huber
2019-01-03 15:49 ` Nick Clifton
2019-01-04  7:03   ` Sebastian Huber
2019-01-04 13:49     ` Nick Clifton
2019-01-04 14:12       ` Sebastian Huber
2019-01-04 14:27         ` Nick Clifton
2019-01-04 19:45           ` Sebastian Huber
2019-01-05 18:51             ` Sebastian Huber
2019-01-10 11:13               ` Nick Clifton
2019-01-10 12:14                 ` Sebastian Huber
2019-01-10 13:09                   ` Alan Modra
2019-01-10 13:12                     ` Sebastian Huber
2019-01-10 13:40                       ` Alan Modra
2019-01-10 13:48                         ` Sebastian Huber
2019-01-10 14:05                           ` Alan Modra
2019-01-10 19:04                             ` Joel Sherrill
2019-01-14  9:41                               ` Sebastian Huber
2019-01-18  0:24                                 ` Alan Modra
2019-01-18  9:04                                   ` Sebastian Huber
2019-01-18 13:41                                     ` Alan Modra
2019-01-23  9:11                                       ` Sebastian Huber
2019-01-25  8:37                                         ` Sebastian Huber
2019-01-25 13:55                                           ` Sebastian Huber
2019-01-25 23:52                                             ` Alan Modra
2019-01-28  9:28                                               ` Sebastian Huber
2019-01-29  0:31                                                 ` Alan Modra
2019-01-29  7:44                                                   ` Sebastian Huber
2019-01-29 11:02                                                     ` Sebastian Huber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).