[PATCH] PR target/66232: -fPIC -fno-plt -mx32 fails to generate indirect branch via GOT

H.J. Lu hjl.tools@gmail.com
Thu May 21 17:16:00 GMT 2015


On Thu, May 21, 2015 at 6:33 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, May 21, 2015 at 6:11 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
>> On Thu, May 21, 2015 at 2:59 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> X32 doesn't support indirect branch via 32-bit memory slot since
>>> indirect branch will load 64-bit address from 64-bit memory slot.
>>> Since x32 GOT slot is 64-bit, we should allow indirect branch via GOT
>>> slot for x32.
>>>
>>> I am testing it on x32.  OK for master if there is no regression?
>>>
>>> Thanks.
>>>
>>>
>>> H.J.
>>> --
>>> gcc/
>>>
>>>         PR target/66232
>>>         * config/i386/constraints.md (Bg): Add a constraint for x32
>>>         call and sibcall memory operand.
>>>         * config/i386/i386.md (*call_x32): New pattern.
>>>         (*sibcall_x32): Likewise.
>>>         (*call_value_x32): Likewise.
>>>         (*sibcall_value_x32): Likewise.
>>>         * config/i386/predicates.md (x32_sibcall_memory_operand): New
>>>         predicate.
>>>         (x32_call_insn_operand): Likewise.
>>>         (x32_sibcall_insn_operand): Likewise.
>>>
>>> gcc/testsuite/
>>>
>>>         PR target/66232
>>>         * gcc.target/i386/pr66232-1.c: New test.
>>>         * gcc.target/i386/pr66232-2.c: Likewise.
>>>         * gcc.target/i386/pr66232-3.c: Likewise.
>>>         * gcc.target/i386/pr66232-4.c: Likewise.
>>
>> OK.
>>
>> maybe you should use match_code some more in x32_sibcall_memory_operand, e.g.
>>
>> (match_code "constant" "0")
>> (match_code "unspec" "00")
>>
>> But it is up to you, since XINT doesn't fit in this scheme...
>>
>
>>>
>>> +;; Return true if OP is a memory operand that can be used in x32 calls
>>> +;; and sibcalls.  Only th 64-bit GOT slot is allowed.
>>> +(define_predicate "x32_sibcall_memory_operand"
>>> +  (and (match_operand 0 "memory_operand")
>>> +       (match_test "CONSTANT_P (XEXP (op, 0))")
>>> +       (match_test "GET_CODE (XEXP (XEXP (op, 0), 0)) == UNSPEC")
>>> +       (match_test "XINT (XEXP (XEXP (op, 0), 0), 1) == UNSPEC_GOTPCREL")))
>>> +
>
> Since "match_code" doesn't support "constant" neither
>
> #define CONSTANT_P(X)   \
>   (GET_RTX_CLASS (GET_CODE (X)) == RTX_CONST_OBJ)
>
> I will keep it asis.

Here is the updated patch.  It limited memory operand to
GOT slot only.  It used a single pattern to cover both call
and sibcall since only GOT slot is allowed.

OK for master if there is no regression?

Thanks.


-- 
H.J.
---
X32 doesn't support indirect branch via 32-bit memory slot since
indirect branch will load 64-bit address from 64-bit memory slot.
Since x32 GOT slot is 64-bit, we should allow indirect branch via GOT
slot for x32.

gcc/

PR target/66232
* config/i386/constraints.md (Bg): Add a constraint for x32
call and sibcall memory operand.
* config/i386/i386.md (*call_got_x32): New pattern.
(*call_value_got_x32): Likewise.
* config/i386/predicates.md (x32_call_got_memory_operand): New
predicate.
(x32_call_insn_got_operand): Likewise.

gcc/testsuite/

PR target/66232
* gcc.target/i386/pr66232-1.c: New test.
* gcc.target/i386/pr66232-2.c: Likewise.
* gcc.target/i386/pr66232-3.c: Likewise.
* gcc.target/i386/pr66232-4.c: Likewise.
* gcc.target/i386/pr66232-5.c: Likewise.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Allow-indirect-branch-via-GOT-slot-for-x32.patch
Type: text/x-patch
Size: 7833 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20150521/aea42049/attachment.bin>


More information about the Gcc-patches mailing list