public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* combining object files and managing relocatable symbols
@ 2006-09-20 20:16 Erik Leunissen
  2006-09-20 20:41 ` H. J. Lu
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Erik Leunissen @ 2006-09-20 20:16 UTC (permalink / raw)
  To: binutils

I've got two ELF object files; let's call them A.o and B.o.

A.o refers to a symbol X, which is defined in B.o

What I want to accomplish is to create a new relocatable object file C.o 
from these object files such that:
1. the reference to X in A.o is resolved
2. symbol X in C.o is unavailable for further linking against. I guess 
this means reducing it to a local symbol.

Doing a partial link does step 1 ( ld -r -nostdlib -o C.o A.o B.o ).
However, I did not find a way to do step 2.

Any suggestions?

Thanks in advance,

Erik Leunissen

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: combining object files and managing relocatable symbols
  2006-09-20 20:16 combining object files and managing relocatable symbols Erik Leunissen
@ 2006-09-20 20:41 ` H. J. Lu
  2006-09-20 20:59   ` Erik Leunissen
  2006-09-20 21:25 ` vamsi krishna
  2006-09-20 22:52 ` Erik Leunissen
  2 siblings, 1 reply; 10+ messages in thread
From: H. J. Lu @ 2006-09-20 20:41 UTC (permalink / raw)
  To: Erik Leunissen; +Cc: binutils

On Wed, Sep 20, 2006 at 09:58:59PM +0200, Erik Leunissen wrote:
> I've got two ELF object files; let's call them A.o and B.o.
> 
> A.o refers to a symbol X, which is defined in B.o
> 
> What I want to accomplish is to create a new relocatable object file C.o 
> from these object files such that:
> 1. the reference to X in A.o is resolved
> 2. symbol X in C.o is unavailable for further linking against. I guess 
> this means reducing it to a local symbol.
> 
> Doing a partial link does step 1 ( ld -r -nostdlib -o C.o A.o B.o ).
> However, I did not find a way to do step 2.
> 

Have you tried

# objcopy --localize-symbol X C.o


H.J.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: combining object files and managing relocatable symbols
  2006-09-20 20:41 ` H. J. Lu
@ 2006-09-20 20:59   ` Erik Leunissen
  0 siblings, 0 replies; 10+ messages in thread
From: Erik Leunissen @ 2006-09-20 20:59 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

H. J. Lu wrote:
> 
> Have you tried
> 
> # objcopy --localize-symbol X C.o
> 

Missed that one. Thanks for the quick reply,

Erik

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: combining object files and managing relocatable symbols
  2006-09-20 20:16 combining object files and managing relocatable symbols Erik Leunissen
  2006-09-20 20:41 ` H. J. Lu
@ 2006-09-20 21:25 ` vamsi krishna
  2006-09-20 22:19   ` Andreas Schwab
  2006-09-20 22:52 ` Erik Leunissen
  2 siblings, 1 reply; 10+ messages in thread
From: vamsi krishna @ 2006-09-20 21:25 UTC (permalink / raw)
  To: Erik Leunissen; +Cc: binutils

Hi Erik,

> Doing a partial link does step 1 ( ld -r -nostdlib -o C.o A.o B.o ).
> However, I did not find a way to do step 2.

I think you should link with 'ld -r -E -nostdlib -o C.o A.o B.o' , the
-E flag forces the linker to export all the symbols.

HTH
Vamsi kundeti




>
> Any suggestions?
>
> Thanks in advance,
>
> Erik Leunissen
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: combining object files and managing relocatable symbols
  2006-09-20 21:25 ` vamsi krishna
@ 2006-09-20 22:19   ` Andreas Schwab
  0 siblings, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2006-09-20 22:19 UTC (permalink / raw)
  To: vamsi krishna; +Cc: Erik Leunissen, binutils

"vamsi krishna" <vamsi.krishnak@gmail.com> writes:

> Hi Erik,
>
>> Doing a partial link does step 1 ( ld -r -nostdlib -o C.o A.o B.o ).
>> However, I did not find a way to do step 2.
>
> I think you should link with 'ld -r -E -nostdlib -o C.o A.o B.o' , the
> -E flag forces the linker to export all the symbols.

-E has no effect for relocatable linking, since there are no dynamic
symbols yet.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: combining object files and managing relocatable symbols
  2006-09-20 20:16 combining object files and managing relocatable symbols Erik Leunissen
  2006-09-20 20:41 ` H. J. Lu
  2006-09-20 21:25 ` vamsi krishna
@ 2006-09-20 22:52 ` Erik Leunissen
  2006-09-20 22:57   ` H. J. Lu
  2 siblings, 1 reply; 10+ messages in thread
From: Erik Leunissen @ 2006-09-20 22:52 UTC (permalink / raw)
  To: binutils

Indeed, using:

    objcopy --localize-symbol=X C.o

did what I wanted. Symbol X is now local to C.o and resides in the text 
section.

Would it be possible to take this process one step further:
not only localize the symbol, but make it invisible altogether?

I expected "objcopy -x and -X" to do exactly that, but it did not. Can 
anybody tell why?

Thanks again for your attention,

Erik Leunissen

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: combining object files and managing relocatable symbols
  2006-09-20 22:52 ` Erik Leunissen
@ 2006-09-20 22:57   ` H. J. Lu
  2006-09-21  9:46     ` Erik Leunissen
  0 siblings, 1 reply; 10+ messages in thread
From: H. J. Lu @ 2006-09-20 22:57 UTC (permalink / raw)
  To: Erik Leunissen; +Cc: binutils

On Thu, Sep 21, 2006 at 12:19:28AM +0200, Erik Leunissen wrote:
> Indeed, using:
> 
>    objcopy --localize-symbol=X C.o
> 
> did what I wanted. Symbol X is now local to C.o and resides in the text 
> section.
> 
> Would it be possible to take this process one step further:
> not only localize the symbol, but make it invisible altogether?
> 
> I expected "objcopy -x and -X" to do exactly that, but it did not. Can 
> anybody tell why?
> 

You need to do it in 2 steps, -L and then -x. You can open a bug
report at

http://www.sourceware.org/bugzilla/

to request that "-L foo -x" will remove foo in one step.


H.J.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: combining object files and managing relocatable symbols
  2006-09-20 22:57   ` H. J. Lu
@ 2006-09-21  9:46     ` Erik Leunissen
  2006-09-21 15:03       ` H. J. Lu
  0 siblings, 1 reply; 10+ messages in thread
From: Erik Leunissen @ 2006-09-21  9:46 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

H. J. Lu wrote:
> 
> You need to do it in 2 steps, -L and then -x. You can open a bug
> report at
> 
> http://www.sourceware.org/bugzilla/
> 
> to request that "-L foo -x" will remove foo in one step.
> 

I have no problem with needing multiple, separate calls to objcopy if it 
indeed removes the local symbol X from C.o.

My real problem is that the symbol X remains present as it was before 
the call to objcopy -x (according to: nm C.o ).

Is this a flaw in objcopy -x, or are there some requirements for it to 
work that I don't know of? In case relevant, here's the version of 
objcopy that I use:

 > objcopy -V
GNU objcopy 2.14.90.0.5 20030722 (SuSE Linux)

Regards,

Erik Leunissen

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: combining object files and managing relocatable symbols
  2006-09-21  9:46     ` Erik Leunissen
@ 2006-09-21 15:03       ` H. J. Lu
  2006-09-22  0:21         ` Erik Leunissen
  0 siblings, 1 reply; 10+ messages in thread
From: H. J. Lu @ 2006-09-21 15:03 UTC (permalink / raw)
  To: Erik Leunissen; +Cc: binutils

On Thu, Sep 21, 2006 at 10:20:02AM +0200, Erik Leunissen wrote:
> H. J. Lu wrote:
> >
> >You need to do it in 2 steps, -L and then -x. You can open a bug
> >report at
> >
> >http://www.sourceware.org/bugzilla/
> >
> >to request that "-L foo -x" will remove foo in one step.
> >
> 
> I have no problem with needing multiple, separate calls to objcopy if it 
> indeed removes the local symbol X from C.o.
> 
> My real problem is that the symbol X remains present as it was before 
> the call to objcopy -x (according to: nm C.o ).
> 
> Is this a flaw in objcopy -x, or are there some requirements for it to 
> work that I don't know of? In case relevant, here's the version of 
> objcopy that I use:
> 
> > objcopy -V
> GNU objcopy 2.14.90.0.5 20030722 (SuSE Linux)

That is very old. It works for me:

sh-3.1$ cat x.c
void
X ()
{
}
bash-3.1$ gcc -c x.c
bash-3.1$ /usr/bin/objcopy -L X x.o
bash-3.1$ nm x.o
0000000000000000 t X
bash-3.1$ /usr/bin/objcopy -x x.o
bash-3.1$ nm x.o
bash-3.1$ /usr/bin/objcopy --version
GNU objcopy 2.16.91.0.6 20060212
bash-3.1$


H.J.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: combining object files and managing relocatable symbols
  2006-09-21 15:03       ` H. J. Lu
@ 2006-09-22  0:21         ` Erik Leunissen
  0 siblings, 0 replies; 10+ messages in thread
From: Erik Leunissen @ 2006-09-22  0:21 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

H. J. Lu wrote:

> ...
> That is very old. It works for me:
> ...
> bash-3.1$ /usr/bin/objcopy --version
> GNU objcopy 2.16.91.0.6 20060212

Thanks for checking. I'm going to upgrade then.

Erik

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2006-09-21 15:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-20 20:16 combining object files and managing relocatable symbols Erik Leunissen
2006-09-20 20:41 ` H. J. Lu
2006-09-20 20:59   ` Erik Leunissen
2006-09-20 21:25 ` vamsi krishna
2006-09-20 22:19   ` Andreas Schwab
2006-09-20 22:52 ` Erik Leunissen
2006-09-20 22:57   ` H. J. Lu
2006-09-21  9:46     ` Erik Leunissen
2006-09-21 15:03       ` H. J. Lu
2006-09-22  0:21         ` Erik Leunissen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).