[GLIBC][AARCH64] Rewrite elf_machine_dynamic using inline assembly

Renlin Li renlin.li@foss.arm.com
Fri Feb 19 11:59:00 GMT 2016


Hi all,

This patch is a small improvement to use inline assembly instead of 
high-level C
code to get the address of _DYNAMIC.

Fixed PC-relative addressing inline assembly code is used here.
It provides +/-1MB PC-relative addressing capability.

I have checked that, in ld.so, the distance between .text section and 
.got section is within 1MB.
The whole image without debug section is less than 130kiB, which is far 
less than the addressing capability.
So direct PC relative addressing should be adequate and safe here.

Originally, two instructions are generated from previous C code. Now 
only one instruction is needed.

Tiny memory model:
adr Rn _GLOBAL_OFFSET_TABLE_
ldr Rn [Rn]

Small memory model:
adrp Rn _GLOBAL_OFFSET_TABLE_
ldr Rn [Rn, imm]

Another benefit is that, it's guaranteed that, no runtime relocation is 
generated for this function.
For example, if glibc is compiled using -mcmodel=large, the original C 
code will generate the
following absolute addressing code which cannot be resolved at this 
early stage. It will cause segment fault.

ldr x0, .L0
.L0:
   _GLOBAL_TABLE_OFFSET_


aarch64-none-linux-gnu is tested without any issues.
Is Okay to commit?

Regards,
Renlin Li

ChangeLog:

2016-02-19  Renlin Li  <renlin.li@arm.com>

     * sysdeps/aarch64/dl-machine.h (elf_machine_dynamic): Use
        PC-relative instruction to get the value of _DYNAMIC.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: glibc.diff
Type: text/x-patch
Size: 996 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20160219/0e9f741c/attachment.bin>


More information about the Libc-alpha mailing list