This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
ELF symbol aliasing in
- From: Matthias Urlichs <matthias at urlichs dot de>
- To: binutils at sourceware dot org
- Date: Tue, 17 Nov 2009 18:56:14 +0100
- Subject: ELF symbol aliasing in
- References: <1258479843.22585.ezmlm@sourceware.org>
Hi,
I've got a problem.
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?
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.
Is that possible?
Help is appreciated.