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: ELF symbol aliasing in


On Tuesday 17 November 2009 12:56:14 Matthias Urlichs wrote:
> Some legacy mixed c/c++ code (*cough* originally for Mac OS X *cough*
> and Windows *cough*cough*) which I'm trying to port to Linux requires
> that a (large) number of functions have more than one name.
> 
> Usually, that's quite easy to accomplish -- GCC has an "alias" directive
> to do this, case closed.
> 
> Unfortunately, that alias directive needs to be in the same source file
> as the original code, which is unfortunate -- on said Mac OS, this can
> be done with an external table that's fed to the linker.
> 
> Is there a way to accomplish this with gnu tools?

i think i tried this before and you cant alias one symbol to one in a 
different object.  a linker script could do it just fine though i bet.

> As an example, I'd like to make the code below work:
> 
> $ cat foo.c
> int foo(void) { return 42; }
> $ cat bar.c
> #include <stdio.h>
> extern int foo_alias(void);
> int main() { printf("%d\n",foo_alias()); }
> $ cat alias_table
> foo foo_alias
> $ gcc -c foo.c bar.c
> $ gcc -o foo foo.o bar.o _SOME_MAGIC_HERE_
> $ ./foo
> 42
> $
> 
> ... without changing foo.c or bar.c.

i'm not sure how representative this example is to your actual needs.  are you 
actually [final] linking an application ?  or do you really need to create a 
shared library and/or static archive with the aliases contained in there ?

if it's just for finally linked applications, you could try the --defsym= or 
--wrap= linker options.
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.


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