ARM: calls to undefined weak symbols
Phil Blundell
pb@pbcl.net
Wed Mar 2 13:23:00 GMT 2016
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:
     .text
         .align  2
         .weak fred
         .global _start
_start:
         sub     r0,r1,r2
cmp  r0, #1
bne     2f
add     r0, r0, #1
         bl fred
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.
p.
More information about the Binutils
mailing list