From aba6453890ce1754b7d1c01a67612766690ff15e Mon Sep 17 00:00:00 2001 From: Aaron Sawdey Date: Tue, 14 Apr 2020 14:38:47 -0500 Subject: [PATCH] Fix for PR/94542, do not make TLS refs PC-relative For rs6000 target, it is not valid to make PC-relative references to TLS symbols. So addr_to_insn_form() needs to check if things are TLS before returning PC-rel forms. 2020-04-14 Aaron Sawdey PR target/94542 * config/rs6000/rs6000.c (address_to_insn_form): Do not attempt to use PC-relative addressing for TLS references. --- gcc/ChangeLog | 6 ++++++ gcc/config/rs6000/rs6000.c | 33 ++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 483bd85f65c..e88c0e13d15 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2020-04-14 Aaron Sawdey + + PR target/94542 + * config/rs6000/rs6000.c (address_to_insn_form): Do not attempt to + use PC-relative addressing for TLS references. + 2020-04-14 Martin Jambor PR ipa/94434 diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 2b6613bcb7e..4defc1ab52b 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -24824,15 +24824,21 @@ address_to_insn_form (rtx addr, if (GET_RTX_CLASS (GET_CODE (addr)) == RTX_AUTOINC) return INSN_FORM_UPDATE; - /* Handle PC-relative symbols and labels. Check for both local and external - symbols. Assume labels are always local. */ + /* Handle PC-relative symbols and labels. Check for both local and + external symbols. Assume labels are always local. TLS symbols + are not PC-relative for rs6000. */ if (TARGET_PCREL) { - if (SYMBOL_REF_P (addr) && !SYMBOL_REF_LOCAL_P (addr)) - return INSN_FORM_PCREL_EXTERNAL; - - if (SYMBOL_REF_P (addr) || LABEL_REF_P (addr)) + if (LABEL_REF_P (addr)) return INSN_FORM_PCREL_LOCAL; + + if (SYMBOL_REF_P (addr) && !SYMBOL_REF_TLS_MODEL (addr)) + { + if (!SYMBOL_REF_LOCAL_P (addr)) + return INSN_FORM_PCREL_EXTERNAL; + else + return INSN_FORM_PCREL_LOCAL; + } } if (GET_CODE (addr) == CONST) @@ -24866,14 +24872,19 @@ address_to_insn_form (rtx addr, return INSN_FORM_BAD; /* Check for local and external PC-relative addresses. Labels are always - local. */ + local. TLS symbols are not PC-relative for rs6000. */ if (TARGET_PCREL) { - if (SYMBOL_REF_P (op0) && !SYMBOL_REF_LOCAL_P (op0)) - return INSN_FORM_PCREL_EXTERNAL; - - if (SYMBOL_REF_P (op0) || LABEL_REF_P (op0)) + if (LABEL_REF_P (op0)) return INSN_FORM_PCREL_LOCAL; + + if (SYMBOL_REF_P (op0) && !SYMBOL_REF_TLS_MODEL (op0)) + { + if (!SYMBOL_REF_LOCAL_P (op0)) + return INSN_FORM_PCREL_EXTERNAL; + else + return INSN_FORM_PCREL_LOCAL; + } } /* If it isn't PC-relative, the address must use a base register. */ -- 2.30.2