This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Linker magic for aliases an external symbol... how to?
- From: Alan Modra <amodra at gmail dot com>
- To: Philip Prindeville <philipp_subx at redfish-solutions dot com>
- Cc: binutils at sourceware dot org
- Date: Fri, 2 Sep 2016 09:39:20 +0930
- Subject: Re: Linker magic for aliases an external symbol... how to?
- Authentication-results: sourceware.org; auth=none
- References: <2423b918-d698-7d1e-a083-a62a6b855000@redfish-solutions.com>
On Thu, Sep 01, 2016 at 01:45:24PM -0600, Philip Prindeville wrote:
> I've tried in main.c:
>
> void logmsg(int, const char *, ...) asm("syslog");
>
> and:
>
> void logmsg(int, const char *, ...) __attribute__ ((weak, alias
> ("syslog")));
>
> as well as various link-time options like:
>
> -Wl,--defsym=logmsg=syslog
>
> as well as:
>
> -Wl,-Map=ld.map
>
> where ld.map contains:
>
> SECTIONS {
> .text :
> {
> logmsg = syslog;
>
> }
> }
No, none of these ideas will work because you don't have a place in
the executable to define logmsg.
Old C hackers would just write this in the executable
void logmsg (void)
{
extern void syslog (void);
syslog (void);
}
trusting that the compiler will turn this into a sibling call, leaving
the args in place. This works for most architectures and some
compiler optimization levels..
It would be safer to write the assembly version of the above, or
binary edit the shared lib.
--
Alan Modra
Australia Development Lab, IBM