From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0ACB53858D20; Sun, 6 Feb 2022 11:54:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0ACB53858D20 From: "iains at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/104117] [9,10,11,12 Regression] Darwin ppc64 uses invalid non-PIC address to access constants (in PIC code). Date: Sun, 06 Feb 2022 11:54:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 10.3.0 X-Bugzilla-Keywords: link-failure, ra, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: iains at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.4 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Feb 2022 11:54:59 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104117 --- Comment #17 from Iain Sandoe --- FTR: this is the patch I came up with: diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 843ce97b993..3f803bd791f 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -8244,8 +8244,14 @@ darwin_rs6000_legitimate_lo_sum_const_p (rtx x, machine_mode mode) if (GET_CODE (x) =3D=3D CONST) x =3D XEXP (x, 0); + /* If we are building PIC code, then any symbol must be wrapped in an + UNSPEC_MACHOPIC_OFFSET so that it will get the picbase subtracted. */ + bool machopic_offs_p =3D false; if (GET_CODE (x) =3D=3D UNSPEC && XINT (x, 1) =3D=3D UNSPEC_MACHOPIC_OFF= SET) - x =3D XVECEXP (x, 0, 0); + { + x =3D XVECEXP (x, 0, 0); + machopic_offs_p =3D true; + } rtx sym =3D NULL_RTX; unsigned HOST_WIDE_INT offset =3D 0; @@ -8276,6 +8282,9 @@ darwin_rs6000_legitimate_lo_sum_const_p (rtx x, machine_mode mode) if (sym) { tree decl =3D SYMBOL_REF_DECL (sym); + /* As noted above, PIC code cannot use a bare SYMBOL_REF. */ + if (TARGET_MACHO && flag_pic && !machopic_offs_p) + return false; #if TARGET_MACHO if (MACHO_SYMBOL_INDIRECTION_P (sym)) /* The decl in an indirection symbol is the original one, which might @@ -8863,7 +8872,7 @@ legitimate_lo_sum_address_p (machine_mode mode, rtx x, int strict) return false; x =3D XEXP (x, 1); - if (TARGET_ELF || TARGET_MACHO) + if (TARGET_ELF) { bool large_toc_ok; @@ -8889,11 +8898,35 @@ legitimate_lo_sum_address_p (machine_mode mode, rtx= x, int strict) return CONSTANT_P (x) || large_toc_ok; } + else if (TARGET_MACHO) + { + if (GET_MODE_NUNITS (mode) !=3D 1) + return false; + if (GET_MODE_SIZE (mode) > UNITS_PER_WORD + && !(/* see above */ + TARGET_HARD_FLOAT && (mode =3D=3D DFmode || mode =3D=3D DDmo= de))) + return false; +#if TARGET_MACHO + if (MACHO_DYNAMIC_NO_PIC_P || !flag_pic) + return CONSTANT_P (x); +#endif + /* Macho-O PIC code from here. */ + if (GET_CODE (x) =3D=3D CONST) + x =3D XEXP (x, 0); + /* SYMBOL_REFs need to be wrapped in an UNSPEC_MACHOPIC_OFFSET. */ + if (SYMBOL_REF_P (x)) + return false; + + /* So this is OK if the wrapped object is const. */ + if (GET_CODE (x) =3D=3D UNSPEC + && XINT (x, 1) =3D=3D UNSPEC_MACHOPIC_OFFSET) + return CONSTANT_P (XVECEXP (x, 0, 0)); + return CONSTANT_P (x); + } return false; } - /* Try machine-dependent ways of modifying an illegitimate address to be legitimate. If we find one, return the new, valid address. This is used from only one place: `memory_address' in explow.c. diff --git a/gcc/lra-constraints.c b/gcc/lra-constraints.c index 5c2a2d7ce9c..3961dfd2725 100644 --- a/gcc/lra-constraints.c +++ b/gcc/lra-constraints.c @@ -3589,21 +3589,8 @@ process_address_1 (int nop, bool check_only_p, *ad.inner =3D gen_rtx_LO_SUM (Pmode, new_reg, addr); if (!valid_address_p (op, &ad, cn)) { - /* Try to put lo_sum into register. */ - insn =3D emit_insn (gen_rtx_SET - (new_reg, - gen_rtx_LO_SUM (Pmode, new_reg, addr))); - code =3D recog_memoized (insn); - if (code >=3D 0) - { - *ad.inner =3D new_reg; - if (!valid_address_p (op, &ad, cn)) - { - *ad.inner =3D addr; - code =3D -1; - } - } - + *ad.inner =3D addr; /* Punt. */ + code =3D -1; } } if (code < 0)=