From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7867) id C32AA3858298; Thu, 7 Sep 2023 11:54:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C32AA3858298 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: liu & zhensong To: bfd-cvs@sourceware.org Subject: [binutils-gdb] Use 32/64_PCREL to replace a pair of ADD32/64 and SUB32/64. X-Act-Checkin: binutils-gdb X-Git-Author: cailulu X-Git-Refname: refs/heads/master X-Git-Oldrev: 6de11ff67a925a496319d25dee0bea58427aacf6 X-Git-Newrev: ecb802d02eeb8040ce26b89ec7a2445c4b86e646 Message-Id: <20230907115458.C32AA3858298@sourceware.org> Date: Thu, 7 Sep 2023 11:54:58 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Sep 2023 11:54:58 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Decb802d02eeb= 8040ce26b89ec7a2445c4b86e646 commit ecb802d02eeb8040ce26b89ec7a2445c4b86e646 Author: cailulu Date: Fri Sep 1 11:09:00 2023 +0800 Use 32/64_PCREL to replace a pair of ADD32/64 and SUB32/64. =20 Subtraction for labels that require static relocation usually generates ADD32/64 and SUB32/64. =20 If subsy of BFD_RELOC_32/64 and PC in same segment, and disable relax or PC at start of subsy or enable relax but not in SEC_CODE, we generate 32/64_PCREL to replace a pair of ADD32/64 and SUB32/64. Diff: --- gas/config/tc-loongarch.c | 22 ++++++++++++---------- gas/config/tc-loongarch.h | 12 ++++++++++-- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index 2e8a259d147..57faffeb14d 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -1195,7 +1195,6 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTR= IBUTE_UNUSED) static int64_t stack_top; static int last_reloc_is_sop_push_pcrel_1 =3D 0; int last_reloc_is_sop_push_pcrel =3D last_reloc_is_sop_push_pcrel_1; - segT sub_segment; last_reloc_is_sop_push_pcrel_1 =3D 0; =20 char *buf =3D fixP->fx_frag->fr_literal + fixP->fx_where; @@ -1273,16 +1272,19 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg AT= TRIBUTE_UNUSED) (use md_number_to_chars (buf, 0, fixP->fx_size)). */ case BFD_RELOC_64: case BFD_RELOC_32: - if (fixP->fx_r_type =3D=3D BFD_RELOC_32 - && fixP->fx_addsy && fixP->fx_subsy - && (sub_segment =3D S_GET_SEGMENT (fixP->fx_subsy)) - && strcmp (sub_segment->name, ".eh_frame") =3D=3D 0 - && S_GET_VALUE (fixP->fx_subsy) - =3D=3D fixP->fx_frag->fr_address + fixP->fx_where) + if (fixP->fx_pcrel) { - fixP->fx_r_type =3D BFD_RELOC_LARCH_32_PCREL; - fixP->fx_subsy =3D NULL; - break; + switch (fixP->fx_r_type) + { + case BFD_RELOC_64: + fixP->fx_r_type =3D BFD_RELOC_LARCH_64_PCREL; + break; + case BFD_RELOC_32: + fixP->fx_r_type =3D BFD_RELOC_LARCH_32_PCREL; + break; + default: + break; + } } =20 if (fixP->fx_addsy && fixP->fx_subsy) diff --git a/gas/config/tc-loongarch.h b/gas/config/tc-loongarch.h index a9f2a0a17cc..d353f18d0d2 100644 --- a/gas/config/tc-loongarch.h +++ b/gas/config/tc-loongarch.h @@ -71,8 +71,16 @@ extern bool loongarch_frag_align_code (int); relaxation, so do not resolve such expressions in the assembler. */ #define md_allow_local_subtract(l,r,s) 0 =20 -/* Values passed to md_apply_fix don't include symbol values. */ -#define TC_FORCE_RELOCATION_SUB_LOCAL(FIX, SEG) 1 +/* If subsy of BFD_RELOC32/64 and PC in same segment, and without relax + or PC at start of subsy or with relax but sub_symbol_segment not in + SEC_CODE, we generate 32/64_PCREL. */ +#define TC_FORCE_RELOCATION_SUB_LOCAL(FIX, SEG) \ + (!((BFD_RELOC_32 || BFD_RELOC_64) \ + &&(!LARCH_opts.relax \ + || S_GET_VALUE (FIX->fx_subsy) \ + =3D=3D FIX->fx_frag->fr_address + FIX->fx_where \ + || (LARCH_opts.relax \ + && ((S_GET_SEGMENT (FIX->fx_subsy)->flags & SEC_CODE) =3D=3D 0))))) =20 #define TC_VALIDATE_FIX_SUB(FIX, SEG) 1 #define DIFF_EXPR_OK 1