This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Linker magic for aliases an external symbol... how to?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]