This is the mail archive of the binutils@sources.redhat.com 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]

Re: ld, --defsym, and local symbols


Adam Megacz <adam@megacz.com> writes:

> Sorry about re-asking this question in my last post...
> 
> Ian Lance Taylor <ian@airs.com> writes:
> > > Is there any way to redefine a file-local symbol? Linker scripts,
> > > perhaps?
> 
> > There is no reliable way to redefine a file-local symbol at link time.
> 
> Nuts. Why?

Propose a mechanism, and I'll explain why it won't work.

> > There is no guarantee that all relocations relevant to that symbol are
> > even available in the object file.
> 
> I don't understand -- doesn't the object file contain a list of all
> relocations? Can't you just scan that list for relocations using the
> desired symbol?

The object file contains a list of all relocations which were not
resolved by the assembler.  However, the assembler will normally
resolve some relocations locally--specifically, PC relative
relocations to local symbols defined in the same section.

For example, if you have access to an ix86 ELF system, compile this
code:

static int foo() { return 0; }
int bar() { return foo(); }

When I do this on my system using gcc 3.0.3, the resulting object file
has no relocations at all.  It doesn't need any; the call from bar()
to foo() is a PC relative relocation to a local symbol defined in the
same section.

Ian


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