This is the mail archive of the 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: ARM: calls to undefined weak symbols

On Wed, 2016-03-02 at 14:07 +0100, Christian Groessler wrote:
> it just occurred to me: couldn't calls to undefined weak symbolsÂ
> completely be removed
> instead of being replaced by a 'nop' (when doing a 'relaxing' link)?

In general no, they can't, because the linker doesn't have enough
information available to fix up the other places that would need
adjusting afterwards. ÂFor example, if you had:

ÂÂÂÂÂÂÂÂÂ.weak fred
ÂÂÂÂÂÂÂÂÂ.global _start
	 cmp	Âr0, #1
	 addÂÂÂÂÂr0, r0, #1
2:	ÂaddÂÂÂÂÂr0,r1,r2
	Âbx	Âlr

then the "bne 2f" will be completely resolved by the assembler and if
the linker starts adding or removing instructions then the branch
target will point to the wrong location.

Of course, this particular example would be eminently fixable by having
the assembler output a suitable reloc and symbol definition and letting
the linker do the resolution instead. ÂHow easy it would be to identify
and fix up all the other possible places that offsets between
instructions (or between instructions and data) might get encoded into
object files before the linker sees them is less obvious. Â

Clearly it wouldn't be impossible to make this work but, given that
branches to unresolved weaks are fairly uncommon and the cost of a
single nop on a modern cpu is more or less negligible, it seems like it
would be quite a lot of effort for not much benefit.


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