RFC: Add R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX

975 views
Skip to first unread message

H.J. Lu

unread,
Oct 7, 2015, 11:25:55 AM10/7/15
to x86-6...@googlegroups.com
X86 instruction encoding supports converting some instructions on memory
operand with GOTPCREL relocation against symbol, foo, into a different
form on immediate operand if foo is defined locally. Those instructions
are:

call *foo@GOTPCREL(%rip) => nop call foo or call foo nop
jmp *foo@GOTPCREL(%rip) => jmp foo nop
mov foo@GOTPCREL(%rip), %reg => lea foo(%rip), %reg

When PIC is false,

test %reg, foo@GOTPCREL(%rip) => test $foo, %reg
binop foo@GOTPCREL(%rip), %reg => binop $foo, %reg

where binop is one of adc, add, and, cmp, or, sbb, sub, xor instructions.

I am proposing to add 2 new relocations, R_X86_64_GOTPCRELX and
R_X86_64_REX_GOTPCRELX, to x86-64 psABI. Instead of generating
R_X86_64_GOTPCREL relocation agasint foo for foo@GOTPCREL(%rip),
we generate R_X86_64_GOTPCRELX or R_X86_64_REX_GOTPCRELX if there
is a REX prefix. Linker can treat them the same as R_X86_64_GOTPCREL
or it can perform the transformations listed above.

Any feedbacks?

Thanks.

--
H.J.

H.J. Lu

unread,
Oct 20, 2015, 1:16:33 PM10/20/15
to x86-6...@googlegroups.com
Here are 3 patches against x86-64 psABI. The updated pdf file is
available from

https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-gotpcrelx.pdf

They have been implemented on binutils users/hjl/got branch. I
will check it into binutils master branch this week.


--
H.J.
0001-Add-R_X86_64_GOTPCRELX-and-R_X86_64_REX_GOTPCRELX.patch
0002-Combine-GOTPLT-and-GOT-Slots.patch
0003-Optimize-GOTPCRELX-Relocations.patch
Reply all
Reply to author
Forward
0 new messages