public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* partial linking that resolves relocations
@ 2011-05-18  7:50 Yni Mous
  2011-05-18 23:57 ` Ian Lance Taylor
  2011-05-19 17:33 ` John Reiser
  0 siblings, 2 replies; 4+ messages in thread
From: Yni Mous @ 2011-05-18  7:50 UTC (permalink / raw)
  To: binutils

Hi,

I'm not sure I'm using the correct terminology, so I will use a simple example:

Assuming two C files:

$ cat 1.c
void foo();

void lala() {
       foo();
}
$ cat 2.c
void foo(){}

$ gcc -c 1.c
$ gcc -c 2.c

$ objdump -dr 1.o
0000000000000000 <lala>:
  0:   55                      push   %rbp
  1:   48 89 e5             mov    %rsp,%rbp
  4:   b8 00 00 00 00   mov    $0x0,%eax
  9:   e8 00 00 00 00   callq  e <lala+0xe>
                       a: R_X86_64_PC32        foo+0xfffffffffffffffc
  e:   5d                       pop    %rbp
  f:   c3                         retq

Is there a way to combine object files (1.o and 2.o) to produce another
object file (similar to ld -i) with the relocations "resolved"?

In this particular case I would want something like:

00000000004004a4 <foo>:
 ....
0000000000400494 <lala>:
 400494:       55                      push   %rbp
 400495:       48 89 e5             mov    %rsp,%rbp
 400498:       b8 00 00 00 00   mov    $0x0,%eax
 40049d:       e8 02 00 00 00   callq  4004a4 <foo>
 4004a2:       5d                       pop    %rbp
 4004a3:       c3                       retq


I want to use this as a quick fix for two libraries that export the same symbol.

Thanks,

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

* Re: partial linking that resolves relocations
  2011-05-18  7:50 partial linking that resolves relocations Yni Mous
@ 2011-05-18 23:57 ` Ian Lance Taylor
  2011-05-19 17:33 ` John Reiser
  1 sibling, 0 replies; 4+ messages in thread
From: Ian Lance Taylor @ 2011-05-18 23:57 UTC (permalink / raw)
  To: Yni Mous; +Cc: binutils

Yni Mous <ynimous@gmail.com> writes:

> Is there a way to combine object files (1.o and 2.o) to produce another
> object file (similar to ld -i) with the relocations "resolved"?

It could be done in principle for this simple test case, but I'm not
aware of any tool which actually does it.

Ian

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

* Re: partial linking that resolves relocations
  2011-05-18  7:50 partial linking that resolves relocations Yni Mous
  2011-05-18 23:57 ` Ian Lance Taylor
@ 2011-05-19 17:33 ` John Reiser
  2011-05-19 17:50   ` John Reiser
  1 sibling, 1 reply; 4+ messages in thread
From: John Reiser @ 2011-05-19 17:33 UTC (permalink / raw)
  To: binutils

On 05/18/2011 12:50 AM, Yni Mous wrote:

> Is there a way to combine object files (1.o and 2.o) to produce another
> object file (similar to ld -i) with the relocations "resolved"?

There is no direct way, although there should be: for instance,
some additional flag such that "ld -r" would resolve what it could,
instead of just accumulating the relocations for later resolution.

There might be a work-around, however.  Run "ld -r", then run
"objcopy --strip-symbol=foo".  If objcopy interprets this favorably,
then objcopy must resolve the relocations that depend on 'foo'.

-- 

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

* Re: partial linking that resolves relocations
  2011-05-19 17:33 ` John Reiser
@ 2011-05-19 17:50   ` John Reiser
  0 siblings, 0 replies; 4+ messages in thread
From: John Reiser @ 2011-05-19 17:50 UTC (permalink / raw)
  To: binutils

> There might be a work-around, however.  Run "ld -r", then run
> "objcopy --strip-symbol=foo".  If objcopy interprets this favorably,
> then objcopy must resolve the relocations that depend on 'foo'.

This succeeds, and works in some cases: "objcopy --localize-symbo=foo".
Someone who is really desperate might take the output of "ld -r", then
change the string name of 'foo' to (gensym), such as by over-writing
the last two characters with "non-printable" bytes.

-- 

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

end of thread, other threads:[~2011-05-19 17:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-18  7:50 partial linking that resolves relocations Yni Mous
2011-05-18 23:57 ` Ian Lance Taylor
2011-05-19 17:33 ` John Reiser
2011-05-19 17:50   ` John Reiser

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).