From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12olkn2072.outbound.protection.outlook.com [40.92.23.72]) by sourceware.org (Postfix) with ESMTPS id 9CBCA384AB58 for ; Fri, 19 Apr 2024 06:13:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9CBCA384AB58 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=maskray.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=maskray.me ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9CBCA384AB58 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.92.23.72 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1713507192; cv=pass; b=GchAX65sg7/WPd6CUjStNAbWJVQYUjW1j8pqPhUu9/HN6diaOJ/pegVfpHi63QtYveg74OBZTqoabj3f9gG2uYikVn35SzgXVwXY3Cg5avIFN3SabfwoEh0IT0o3z5WquQ0td2x5xQHZu/9joNzM9Ra/xR/wIQmP1icqZ118Xak= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1713507192; c=relaxed/simple; bh=2KPe5ar250uHAZLjZRtKDZYLegN25sYJdRsvV+PlIhA=; h=From:Date:Message-ID:Subject:To:MIME-Version; b=oZaacfwlonAT/Be374/EdUVTwrpJL/n6APSiOfYLpkjVJHjxkwC73O2SA9GX7nRlAZ2HZ0mjtPWU8t6vT3OPIoVCYyvqXeTKkv/GTi+qFe1DHvycrI17uhfkxKp1DKZKh3/e5Qkq4Hi8h3y/wb5bqV0v1OjhXBc8Z3SRglXRCg4= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DO+NkZmnsJ/syWm5luQCee4xzjPFLZpCv6+IT+6QNSompDscfHImOGUqvOlfRBlqcGL9Xsjocf7fOL/8JWb0+GBpXfMMyYbv8cCJ0go1C2+s8b4LrSg8HUpd+qiN1+5Kef9RfSh9n6O6ZtgFq3XWpOBBBpErwgVZg0V94OhLEHFamOYhIc5s5RCaW2vub+ZGfB/YPeSLbPxSk1BChxKZaar8w3dZEAJhnbZFH+QtD8q9h3kRKjKn/+OjgSYJ+JlvYOCkvXYjTLh82PmZIxsKL+UTNGaXh+6yqdQPZw40fDEe/DCNBqLY7oonB/qY/GtDUeInBqWq080FNXjfnngZ5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SddXtYoYk7OT7/phDATsOk6vy03G00l8e4SNCv9RQaE=; b=mAHP2MLA8SgYFo5aJf6RAigq3t77ohsiA9OGiel/AUWv26XQitsuKpsvAaYxeU9sx1d3DEtjUrQgLExSEDqVtumcO0Tare+xc0oQm8JvrnkIFDtbgvRHvg+rUVjv4dmZpZG4j5FweureEkmHq5bA2PFhKwGiMaKElM+CGD8kUtcZ5c85Uujhi+70fDlsJaF+ZwMRP3P02q+0Pbr/XmQ2mVC5LGK4m94oq30M+lsw7jtsk/XeX7vcrFekDp6UUBnYQMgaukmwx1bf/oxQBTHYfaw8zdpaNagFYvH/Xp4WOaPQMYN/opvVsHk55jNt8I1vtUyeOelZJspFDOVL4dKWJA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from DS7PR12MB5765.namprd12.prod.outlook.com (2603:10b6:8:74::19) by CY8PR12MB7339.namprd12.prod.outlook.com (2603:10b6:930:51::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.41; Fri, 19 Apr 2024 06:13:06 +0000 Received: from DS7PR12MB5765.namprd12.prod.outlook.com ([fe80::432:c8d:24:ad11]) by DS7PR12MB5765.namprd12.prod.outlook.com ([fe80::432:c8d:24:ad11%4]) with mapi id 15.20.7472.037; Fri, 19 Apr 2024 06:13:06 +0000 X-Gm-Message-State: AOJu0Yy0I+IFvy8OkWOjZ3KfTIOuJZK7T/icy7FkdmuFRtGAtk0zAK3T ZY7/tcpve4IR+DTmmgS5bq/vXaT92vidIFbgUOMJWC7gsxIo54X+OUHtKGEburZRmO39Znmflk/ B5DfaaKEsBArg+RsTtNMobSQ+fsM= X-Google-Smtp-Source: AGHT+IFQu2zhFeJ31OdmxN54VXcADxE30mInQa3wHMEjYb/cSTugJLlM/RogH8a8CGijW7+OMl1/2YnW9PVb7tV4TP8= X-Received: by 2002:a05:6122:a16:b0:4d3:39c3:717c with SMTP id 22-20020a0561220a1600b004d339c3717cmr975690vkn.1.1713506691000; Thu, 18 Apr 2024 23:04:51 -0700 (PDT) References: <20240322082915.3900449-1-mengqinggang@loongson.cn> In-Reply-To: <20240322082915.3900449-1-mengqinggang@loongson.cn> From: Fangrui Song Date: Thu, 18 Apr 2024 23:04:39 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] BFD: Fix the bug of R_LARCH_AGLIN caused by discard section To: mengqinggang , Alan Modra Cc: binutils@sourceware.org, xuchenghua@loongson.cn, chenglulu@loongson.cn, liuzhensong@loongson.cn, cailulu@loongson.cn, xry111@xry111.site, i.swmail@xen0n.name, maskray@google.com, luweining@loongson.cn, wanglei@loongson.cn, hejinyang@loongson.cn Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-TMN: [7HYnNk9enkCiWPbrRy5W351QnATss6jM] X-ClientProxiedBy: BN8PR15CA0013.namprd15.prod.outlook.com (2603:10b6:408:c0::26) To DS7PR12MB5765.namprd12.prod.outlook.com (2603:10b6:8:74::19) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB5765:EE_|CY8PR12MB7339:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e2fc735-07ec-4c2b-3a41-08dc6037c76b X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: awC6GWwgSoQnjo35bs+BKRj7aUc7gmsPpax8aNKqpKEaqZEVlIZMU9lxEoUQLJN/e2JOQp/ADc13OOkGdObgu8u05Kb/zTm6HHAWXjAZBMHFzuAPc0+OjDxcTPUI5zDEuuhefbazav4d2TuOg3m7IJuFIyZ2IOUhptF7MknBpVIKVT8TUKWRiTkxyurCCzQ10SUGdil2Dq2VVviT6xxuk2jUNb6JODBTMEvg3d0AzTHzp/K21TdCRFz8ZSdarp0TmE8we7je5PWMWw0TzwmFsRyaDs54muU7NFtK8vod0YYtBjT3kZCiuipDKktV7XIGANqDOJdNpZSTH0yxvWq5io2OPXhkapDi9SrF6drU5txBnttI932ZCqHEv9vFpz3YTpABofa2OBSKaGXcsRsj7Qea92kcV6aQxo+CoccvHbbTpW0xQuM5JrCU68JEpR8+sGa946SvKDG7yU6sfENU6WyWoTtdlwu9YZT3YpPyxgZ3cXBL0ihHENqgxYUB+3tAPzlsC0Yc60Gnwg8dt4zI6Jeu1w4OmF3NiT5anqWS/Tczqd6RWWMq6PY3caIH1MgKX9xLClCVXeLtTJP3xxX6Y5Hmmw/ZmP06EDR7NpY2ZpDROzxHX8fuk5LipCTAw3EBDhALvpvL+QgEkOdTKr0vljHyy/AhiX1DQ9gDWdRfpm0= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?WDh4S0NpNTlYWHR6RnBvUzRhd1IzdUpzMmYzbzhGekJ4QzhjNEhLb2NOVjBV?= =?utf-8?B?dm4yNlhtaDMrL2pGUWhGb2U0U09hMld4K3RnU0ZUei9JaXFra1o2Ymp6OUxN?= =?utf-8?B?azNvY05jZGxZZ3E4cFcwQnFvVkRGWkJlR3QxUElzdnVIRkk5TDRVOElPa2x0?= =?utf-8?B?L2NoS2hWVUovZmlIdHVnUmxNalE1eHdVaEo0SExhU0NqZEkxWWk0eEN3d2JZ?= =?utf-8?B?NlFWNEs3TW1sWnNEV1JJL1pvMTVxNTU5bGZSSGluektlUFBSanBwUEFzelBX?= =?utf-8?B?NHhNRzhPNHpqVTFHTXRjNXp4aVpLZ0M3YTFJelBqTlhNQUx0cVNodC9YRTBC?= =?utf-8?B?ZFVMdG84TGQ3YnpLWVEwenFDemNKZ3d5dG0wOFltNzg1b1o4S0lZRHhHMHBp?= =?utf-8?B?M3Vpd2VYdXM2OGhwQnJ0bGZHM2RndWlFS2l1akQwSFhjcndzN2RpQWk2Z2E5?= =?utf-8?B?OVhuT1hWL1ErQm9XSFFnSEVmRG5WTnU3ZHNhRlFwK0JyOE8vRzdUZjVHRkg5?= =?utf-8?B?SjgvYUJtQm9yQmgvaTdpT3R0aGxxYTBrNjlmTThpVllEVG91YXRWNGtiRVpQ?= =?utf-8?B?RnRjT2dQM2hQK0JvREtlTlNoaU9QMmVpazgwWGpBOHFDcHNDdlRNZHJSUDBR?= =?utf-8?B?NDNCSjZJUVRzOFQwOW5VZkJSam9nZG9uSGNRL25zSXRQdkNIOVduUVVUS3VX?= =?utf-8?B?SjJwVEJPNitDaDd5UFE5NDJWejlIbmluZC9rbDQ0MzlWdDlXVmwvZHJONVVB?= =?utf-8?B?c0tUZFFTUnlqbUpXT3VKZjJjTlZ1RDU0Z2lYY3U1a3hRa2lDYmVUcWZ0VHcw?= =?utf-8?B?WklBSnpqYXVUMzR1WktWREl4OXcwRlZxR3NZVUhWRWpPcWEvR284M09UcmEy?= =?utf-8?B?K3ZxbzlyTEgvNU5aN3pTZjZCa1lFa1E0RTE5WGhoc25BeEFCUTROMS81VmdY?= =?utf-8?B?RVowSEIzMDB6ZU9kMGNhbXBjNE1LQmZKZ2NNWUtrbjc0cGRBWmlMalNoeVhl?= =?utf-8?B?aVpPYmRJbDFxSjhDQ2tOMmxlMHJadk1ISGQvN25URVFTWGYyQm9JSzlLMFQ2?= =?utf-8?B?OFI0dG1UZ3F4M2kwNVFmamhmS1lhOXprWGp1MENTNDFoU1FVU2YvTkFHZS9V?= =?utf-8?B?YUJUZzNjTm5zQmF3UkJaTjJOWXZmdFQwbFprRHJRaFdKZElkVGd6bDFQelVI?= =?utf-8?B?bU1VMGdqRnBsMnNIYndLZFVQTW9Nc0FCZGd4Rno3azhCaVYwNzhia1hPdWxC?= =?utf-8?B?M0IyWkVVdVFvbnEvbXBTd2cvWXdRamY0bFNJTGJWemZzdzkzbzdSMEV2aFhw?= =?utf-8?B?REZJZnp6ekI1MThyTDVkdVB3azdYVU0zK29WWHF0dEJuSGJOR2ZsYlFnbkl6?= =?utf-8?B?c081aDd6b3FnVTQ4T2dDWmNRWDBvY0gvK0UzTndMSHB6dHRIQ0dMTmtsR29z?= =?utf-8?B?d0orRFUrdUtOQzA0WU96Tk1zNWg4dzBOZjU0TXhhT3A5TWNCOS9YS3FSOXFa?= =?utf-8?B?NEZiV053dloycWV2M3BlR3dob1Q0dHAxNHFKcVR5cHZNUzlSSGQrOUtSQ3Jk?= =?utf-8?B?R29CbnJ0czg1MWg1dll5UUNBb3hRUG1SM2lXdTZpOWMyMFBGYytqUFdHYVhW?= =?utf-8?B?b2RqSG5IRkJGc1FqbTBSdVhwei92WUE9PQ==?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-5183d.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 4e2fc735-07ec-4c2b-3a41-08dc6037c76b X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB5765.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2024 06:13:06.6775 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7339 X-Spam-Status: No, score=-8.7 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,KAM_INFOUSMEBIZ,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, Mar 22, 2024 at 1:29=E2=80=AFAM mengqinggang wrote: > > To represent the first and third expression of .align, R_LARCH_ALIGN need= to > associate with a symbol. We defind a local symbol for R_LARCH_AGLIN. > But if the section of the local symbo is discarded, it may result in > a undefined symbol error. > > Instead, we use the section name symbols, and this does not need to > add extra symbols. > > During partial linking (ld -r), if the symbol associated with a relocatio= n is > STT_SECTION type, the addend of relocation needs to add the section outpu= t > offset. We prevent it for R_LARCH_ALIGN. > > The elf_backend_data.rela_normal only can set all relocations of a target= to > rela_normal. Add a new function is_rela_normal to elf_backend_data, it ca= n > set part of relocations to rela_normal. > --- > bfd/elf-bfd.h | 4 ++ > bfd/elflink.c | 5 +- > bfd/elfnn-loongarch.c | 16 ++++++ > bfd/elfxx-target.h | 5 ++ > gas/config/tc-loongarch.c | 5 +- > gas/testsuite/gas/loongarch/relax_align.d | 56 ++++++++----------- > .../ld-loongarch-elf/relax-align-discard.lds | 4 ++ > .../ld-loongarch-elf/relax-align-discard.s | 17 ++++++ > ld/testsuite/ld-loongarch-elf/relax.exp | 12 ++++ > 9 files changed, 86 insertions(+), 38 deletions(-) > create mode 100644 ld/testsuite/ld-loongarch-elf/relax-align-discard.lds > create mode 100644 ld/testsuite/ld-loongarch-elf/relax-align-discard.s > > diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h > index c5d325435b6..af507b93df5 100644 > --- a/bfd/elf-bfd.h > +++ b/bfd/elf-bfd.h > @@ -1721,6 +1721,10 @@ struct elf_backend_data > backend relocate_section routine for relocatable linking. */ > unsigned rela_normal : 1; > > + /* Whether a relocation is rela_normal. Compared with rela_normal, > + is_rela_normal can set part of relocations to rela_normal. */ > + bool (*is_rela_normal) (Elf_Internal_Rela *); > + > /* Set if DT_REL/DT_RELA/DT_RELSZ/DT_RELASZ should not include PLT > relocations. */ > unsigned dtrel_excludes_plt : 1; > diff --git a/bfd/elflink.c b/bfd/elflink.c > index 5a6cb07b2ce..8223db98186 100644 > --- a/bfd/elflink.c > +++ b/bfd/elflink.c > @@ -11692,7 +11692,10 @@ elf_link_input_bfd (struct elf_final_link_info *= flinfo, bfd *input_bfd) > { > rel_hash =3D PTR_ADD (esdo->rela.hashes, esdo->rela= .count); > rela_hash_list =3D rel_hash; > - rela_normal =3D bed->rela_normal; > + if (bed->is_rela_normal !=3D NULL) > + rela_normal =3D bed->is_rela_normal (irela); > + else > + rela_normal =3D bed->rela_normal; > } > > irela->r_offset =3D _bfd_elf_section_offset (output_bfd= , > diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c > index c42052f9321..1679aa5da7d 100644 > --- a/bfd/elfnn-loongarch.c > +++ b/bfd/elfnn-loongarch.c > @@ -5454,6 +5454,21 @@ elf_loongarch64_hash_symbol (struct elf_link_hash_= entry *h) > return _bfd_elf_hash_symbol (h); > } > > +/* If a relocation is rela_normal and the symbol associated with the > + relocation is STT_SECTION type, the addend of the relocation would ad= d > + sec->output_offset when partial linking (ld -r). > + See elf_backend_data.rela_normal and elf_link_input_bfd(). > + The addend of R_LARCH_ALIGN is used to represent the first and third > + expression of .align, it should be a constant when linking. */ > + > +static bool > +loongarch_elf_is_rela_normal (Elf_Internal_Rela *rel) > +{ > + if (R_LARCH_ALIGN =3D=3D ELFNN_R_TYPE (rel->r_info)) > + return false; > + return true; > +} > + > #define TARGET_LITTLE_SYM loongarch_elfNN_vec > #define TARGET_LITTLE_NAME "elfNN-loongarch" > #define ELF_ARCH bfd_arch_loongarch > @@ -5489,6 +5504,7 @@ elf_loongarch64_hash_symbol (struct elf_link_hash_e= ntry *h) > #define elf_backend_grok_psinfo loongarch_elf_grok_psinfo > #define elf_backend_hash_symbol elf_loongarch64_hash_symbol > #define bfd_elfNN_bfd_relax_section loongarch_elf_relax_section > +#define elf_backend_is_rela_normal loongarch_elf_is_rela_normal > > #define elf_backend_dtrel_excludes_plt 1 > > diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h > index 1e6992b5793..6e2d948b69b 100644 > --- a/bfd/elfxx-target.h > +++ b/bfd/elfxx-target.h > @@ -709,6 +709,10 @@ > #define elf_backend_rela_normal 0 > #endif > > +#ifndef elf_backend_is_rela_normal > +#define elf_backend_is_rela_normal NULL > +#endif > + > #ifndef elf_backend_dtrel_excludes_plt > #define elf_backend_dtrel_excludes_plt 0 > #endif > @@ -955,6 +959,7 @@ static const struct elf_backend_data elfNN_bed =3D > elf_backend_default_use_rela_p, > elf_backend_rela_plts_and_copies_p, > elf_backend_rela_normal, > + elf_backend_is_rela_normal, > elf_backend_dtrel_excludes_plt, > elf_backend_sign_extend_vma, > elf_backend_want_got_plt, > diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c > index 30aefce36fd..6b1a89738ef 100644 > --- a/gas/config/tc-loongarch.c > +++ b/gas/config/tc-loongarch.c > @@ -1791,10 +1791,7 @@ loongarch_frag_align_code (int n, int max) > if (fragP->fr_subtype !=3D 0 && offset > fragP->fr_subtype). */ > if (max > 0 && (bfd_vma) max < worst_case_bytes) > { > - s =3D symbol_find (".Lla-relax-align"); > - if (s =3D=3D NULL) > - s =3D (symbolS *)local_symbol_make (".Lla-relax-align", now_seg, > - &zero_address_frag, 0); > + s =3D symbol_find (now_seg->name); > ex.X_add_symbol =3D s; > ex.X_op =3D O_symbol; > ex.X_add_number =3D (max << 8) | n; > diff --git a/gas/testsuite/gas/loongarch/relax_align.d b/gas/testsuite/ga= s/loongarch/relax_align.d > index fc1fd032611..6710927be1b 100644 > --- a/gas/testsuite/gas/loongarch/relax_align.d > +++ b/gas/testsuite/gas/loongarch/relax_align.d > @@ -7,40 +7,30 @@ > > Disassembly of section .text: > > -[ ]*0000000000000000 <.Lla-relax-align>: > -[ ]+0:[ ]+4c000020[ ]+ret > -[ ]+4:[ ]+03400000[ ]+nop > -[ ]+4: R_LARCH_ALIGN[ ]+\*ABS\*\+0xc > +[ ]*0000000000000000 <.text>: > +[ ]+0:[ ]+1a000004[ ]+pcalau12i[ ]+\$a0, 0 > +[ ]+0: R_LARCH_PCALA_HI20[ ]+L1 > +[ ]+0: R_LARCH_RELAX[ ]+\*ABS\* > +[ ]+4:[ ]+02c00084[ ]+addi.d[ ]+\$a0, \$a0, 0 > +[ ]+4: R_LARCH_PCALA_LO12[ ]+L1 > +[ ]+4: R_LARCH_RELAX[ ]+\*ABS\* > [ ]+8:[ ]+03400000[ ]+nop > +[ ]+8: R_LARCH_ALIGN[ ]+.text\+0x4 > [ ]+c:[ ]+03400000[ ]+nop > -[ ]+10:[ ]+4c000020[ ]+ret > -[ ]+14:[ ]+03400000[ ]+nop > -[ ]+14: R_LARCH_ALIGN[ ]+\*ABS\*\+0xc > -[ ]+18:[ ]+03400000[ ]+nop > +[ ]+10:[ ]+03400000[ ]+nop > +[ ]+14:[ ]+1a000004[ ]+pcalau12i[ ]+\$a0, 0 > +[ ]+14: R_LARCH_PCALA_HI20[ ]+L1 > +[ ]+14: R_LARCH_RELAX[ ]+\*ABS\* > +[ ]+18:[ ]+02c00084[ ]+addi.d[ ]+\$a0, \$a0, 0 > +[ ]+18: R_LARCH_PCALA_LO12[ ]+L1 > +[ ]+18: R_LARCH_RELAX[ ]+\*ABS\* > [ ]+1c:[ ]+03400000[ ]+nop > -[ ]+20:[ ]+4c000020[ ]+ret > +[ ]+1c: R_LARCH_ALIGN[ ]+.text\+0x404 > +[ ]+20:[ ]+03400000[ ]+nop > [ ]+24:[ ]+03400000[ ]+nop > -[ ]+24: R_LARCH_ALIGN[ ]+.Lla-relax-align\+0x104 > -[ ]+28:[ ]+03400000[ ]+nop > -[ ]+2c:[ ]+03400000[ ]+nop > -[ ]+30:[ ]+4c000020[ ]+ret > -[ ]+34:[ ]+03400000[ ]+nop > -[ ]+34: R_LARCH_ALIGN[ ]+.Lla-relax-align\+0xb04 > -[ ]+38:[ ]+03400000[ ]+nop > -[ ]+3c:[ ]+03400000[ ]+nop > -[ ]+40:[ ]+4c000020[ ]+ret > -[ ]+44:[ ]+03400000[ ]+nop > -[ ]+44: R_LARCH_ALIGN[ ]+\*ABS\*\+0xc > -[ ]+48:[ ]+03400000[ ]+nop > -[ ]+4c:[ ]+03400000[ ]+nop > -[ ]+50:[ ]+4c000020[ ]+ret > -[ ]+54:[ ]+03400000[ ]+nop > -[ ]+54: R_LARCH_ALIGN[ ]+\*ABS\*\+0xc > -[ ]+58:[ ]+03400000[ ]+nop > -[ ]+5c:[ ]+03400000[ ]+nop > -[ ]+60:[ ]+4c000020[ ]+ret > -[ ]+64:[ ]+03400000[ ]+nop > -[ ]+64: R_LARCH_ALIGN[ ]+\*ABS\*\+0xc > -[ ]+68:[ ]+03400000[ ]+nop > -[ ]+6c:[ ]+03400000[ ]+nop > -[ ]+70:[ ]+4c000020[ ]+ret > +[ ]+28:[ ]+1a000004[ ]+pcalau12i[ ]+\$a0, 0 > +[ ]+28: R_LARCH_PCALA_HI20[ ]+L1 > +[ ]+28: R_LARCH_RELAX[ ]+\*ABS\* > +[ ]+2c:[ ]+02c00084[ ]+addi.d[ ]+\$a0, \$a0, 0 > +[ ]+2c: R_LARCH_PCALA_LO12[ ]+L1 > +[ ]+2c: R_LARCH_RELAX[ ]+\*ABS\* > diff --git a/ld/testsuite/ld-loongarch-elf/relax-align-discard.lds b/ld/t= estsuite/ld-loongarch-elf/relax-align-discard.lds > new file mode 100644 > index 00000000000..4a81323d926 > --- /dev/null > +++ b/ld/testsuite/ld-loongarch-elf/relax-align-discard.lds > @@ -0,0 +1,4 @@ > +SECTIONS > +{ > + /DISCARD/ : { *(.another.*) } > +} > diff --git a/ld/testsuite/ld-loongarch-elf/relax-align-discard.s b/ld/tes= tsuite/ld-loongarch-elf/relax-align-discard.s > new file mode 100644 > index 00000000000..b65d63f370f > --- /dev/null > +++ b/ld/testsuite/ld-loongarch-elf/relax-align-discard.s > @@ -0,0 +1,17 @@ > +# Use the section name symbol for R_LARCH_ALIGN to avoid discard section= problem > +.section ".another.text", "ax" > +.cfi_startproc > +break 0 > +.cfi_def_cfa_offset 16 > +.p2align 5 > +break 1 > +.cfi_endproc > + > +.text > +.cfi_startproc > +break 0 > +.cfi_def_cfa_offset 16 > +.p2align 5 > +break 1 > +.cfi_endproc > + > diff --git a/ld/testsuite/ld-loongarch-elf/relax.exp b/ld/testsuite/ld-lo= ongarch-elf/relax.exp > index 7d95a9ca41d..ed71fb45b46 100644 > --- a/ld/testsuite/ld-loongarch-elf/relax.exp > +++ b/ld/testsuite/ld-loongarch-elf/relax.exp > @@ -295,6 +295,18 @@ if [istarget loongarch64-*-*] { > "relax-align" \ > ] \ > ] > + > + run_ld_link_tests \ > + [list \ > + [list \ > + "loongarch relax align discard" \ > + "-e 0x0 -T relax-align-discard.lds -r" "" \ > + "" \ > + {relax-align-discard.s} \ > + {} \ > + "relax-align-discard" \ > + ] \ > + ] > } > > set objdump_flags "-s -j .data" > -- > 2.36.0 I just saw this was pushed as commit daeda14191c1710ce967259a47ef4e0a3fb6ee= bf. The addition of the generic elf_backend_is_rela_normal flag seems like something a global maintainer should take a closer look at. In particular, I'm curious if Alan, the author of the "rela_normal" commit (b491616acb5462a3694160ffef6413c160fed10a), has any thoughts on this. The idea appears to be (https://github.com/loongson/la-abi-specs/blob/release/laelf.adoc#:~:text= =3DR_LARCH_ALIGN) .text break 1 .p2align 4, , 8 // R_LARCH_ALIGN .text+0x0804 break 8 In a relocatable link, the addend associated with the STT_SECTION symbol is kept unchanged. > But if the section of the local symbo is discarded, it may result in a un= defined symbol error. How does this happen when the R_LARCH_ALIGN relocation references another local symbol instead of .text ?