[AArch64, Committed] Fix the placement of _DYNAMIC in the GOT.

Marcus Shawcroft marcus.shawcroft@arm.com
Thu Jun 27 15:47:00 GMT 2013


This patch fixes an issue in the static linker highlighted by this thread:

http://sourceware.org/ml/libc-ports/2013-06/msg00043.html

This patch fixes the location of &_DYNAMIC in the GOT.

We currently emit:
got[0] ...    <- _GLOBAL_OFFSET_TABLE_
...
gotplt[0] &_DYNAMIC  <- DT_PLTGOT
gotplt[1] reserved
gotplt[2] reserved
gotplt[3] first real plt

The purpose of placing &_DYNAMIC in a dedicated GOT slot is to allow the 
dynamic loader to easily locate its own dynamic section before it has 
relocated itself.  This current layout is broken, the _DYNAMIC entry 
should be placed at a reserved slot pointed to by _GLOBAL_OFFSET_TABLE_.

This patch switches to this layout:
got[0]    &_DYNAMIC  <- _GLOBAL_OFFSET_TABLE_
...
gotplt[0] reserved  <- DT_PLTGOT
gotplt[1] reserved
gotplt[2] reserved
gotplt[3] first real plt

This change is safe because the only use of gotplt[0] is the ld.so and 
currently ld.so uses an alternative (broken) mechanism to find _DYNAMIC.

Once this fix is in the static linker we can have the behaviour of ld.so 
corrected to find _DYNAMIC by dereferencing _GLOBAL_OFFSET_TABLE_.

/Marcus

2013-06-27  Marcus Shawcroft  <marcus.shawcroft@arm.com>

	* elfnn-aarch64.c (elfNN_aarch64_check_relocs): Reserve one slot
	in sgot.
	(elfNN_aarch64_finish_dynamic_sections): Place the &_DYNAMIC reference
	in sgot[0] rather than sgotplt[0].
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bfd-fix-_dynamic.diff
Type: text/x-patch
Size: 1628 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20130627/671aae77/attachment.bin>


More information about the Binutils mailing list