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]

ELF symbol aliasing in


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.


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