This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Change global symbol to local in ELF?
- From: Rayson Ho <raysonlogin at gmail dot com>
- To: Lonnie Princehouse <lonnie dot princehouse at gmail dot com>
- Cc: binutils at sourceware dot org
- Date: Wed, 22 Apr 2009 15:46:03 -0500
- Subject: Re: Change global symbol to local in ELF?
- References: <e1ee56d90904221339w62f13626lfd186efa4965c566@mail.gmail.com>
You can try using "objcopy --localize-symbol" to turn symbols from
global to static:
tridge:/tmp/mozilla> nm a.o
00000000 T func
tridge:/tmp/mozilla> objcopy a.o --localize-symbol=func
tridge:/tmp/mozilla> nm a.o
00000000 t func
Rayson
On Wed, Apr 22, 2009 at 3:39 PM, Lonnie Princehouse
<lonnie.princehouse@gmail.com> wrote:
> Hi all,
>
> There's probably an easy answer for this, but I'm not really sure what
> to search for.
>
> I have a partially linked object lib.o:
>
> ld -r -static file1.o file2.o ... -lc -o lib.o
>
> It defines a global function symbol, foo, that conflicts with a
> different function of the same name in another object, main.o
>
> gcc main.o lib.o -o program
>
> lib.o: In function `foo':
> example/file1.c:3: multiple definition of `foo'
> example/main.c:4: first defined here
>
> Both lib.o and main.o should use their own respective versions of
> foo(), so I don't think telling ld to ignore multiply defined symbols
> will work, since my understanding is that this would cause the first
> definition to be used everywhere.
>
> foo in lib.o is not needed by any external objects. Ideally it would
> be local, not global. So I guess I'm looking for a way to change a
> symbol from global to local, either during the partial linking step or
> before the final linking. I've looked through the ld manual, and it
> seems a linker script could do this using symbol versions, but only
> with dynamically linking? These are statically linked out of
> necessity (the target system doesn't do dynamic linking)
>
> Any suggestions greatly appreciated.
>
> (assume for now I that I can't rename the symbols in the source code)
>