From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11olkn2010.outbound.protection.outlook.com [40.92.19.10]) by sourceware.org (Postfix) with ESMTPS id 55F9E3849AC6 for ; Fri, 19 Apr 2024 06:22:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 55F9E3849AC6 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 55F9E3849AC6 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.92.19.10 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1713507759; cv=pass; b=QLkJFhh5+CZ2piKQVUFRr9CkfkZTi8U7HkVOd3iKv6kR4BrIi4C69akZEcnkU4jZ428SmjSqdhQN50xWsh7nszWLDceR09dcEyrsnJfL/LlPTVMzP5xbQWOZalcrIay7ZlrjmHjCG2Kik7NIyJoewF/b2bhvoJSyrgrtwF7jhlI= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1713507759; c=relaxed/simple; bh=CuuFn3feLRtAsYInilaPNnWrW8xKL+uPbTZBuLQYqG8=; h=From:Date:Message-ID:Subject:To:MIME-Version; b=K/rLyVvv7UZwedEHif1UDVyVMRqGgvg0ZZkQHNn1sE828NT7Nj2K45q0LIXSe+KJVEX1ELZdb3BPAKYjBacDRgfJnT7LbGC90VB+yU+pTaY1koB7nq2T69XuNweNLtRbd7bDiLrSOQfOQPjz3+z4X4iDCidCAJipGe8SHX4JRvI= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PpxfBVf8VWUY2O3e7iaNuUNex75UhzFoBim5Gx3Nw6dEJBBERN/vwbeHzJ31SueiI1+/W9vlnMHFv9puHenRqWaoFban7OWz1Um/q/dIZPB8XqnhJ1zhUx4FAqIe5snHCe4tQKTq+oxyAzMrAZWZsrXw0kVblRzjMBOEKuhCZ17CAoOqX4sG8q5+DORGd2DUKI0CQ8nkwqyylXQBkCP9Q7i3SDkWP1J+IlJTscE/RJBEAlEiv4Ddpx/i/kWyxTsEkx8NE3oAiTORdLh1R3NoBskPo08slKE3lwBoNvBsfGbaEx3tJBJb7dpECwLyqn+9CVloKd75V87IWB16rSKhrQ== 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=3HcWIk/S0BQJ8GRQHtsl477j9yIwoR4sr+Xgf6QGUNY=; b=ZZ3kq71nzwpmx8GnaXMT0ibsQW1/OuGcCRWC7tK3++0fQALxypxP+LMUSeYZ2WYdFoEWSUx7dx2AR14zo9f+H8IRIB6a/mod/NgOfwNYGCQu8h1b599txuZpPIXAUOeWm+HFQ7FpxKJEwYED5OjkSLyo8u7h/hfK2AMPLMaG5kyCmyM30qWi+a8cOJSGX0ZLzVm6Tw4yI8vm5PFrBODsqtxsnIvFJhnbmQNyzZT9WZo8QWpA0ln9DC6kvIsdbw8lyHz+PiZNp+VVnrq1aU5h/xklgdLewBg+gkSkggZ5JssiN4L6bkNJ3gCfnLKQngS6tYeD8izMiRRfHt4+OMvFgA== 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 DM4PR12MB5724.namprd12.prod.outlook.com (2603:10b6:8:5f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.37; Fri, 19 Apr 2024 06:22:35 +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:22:35 +0000 X-Gm-Message-State: AOJu0YzlOjw9Rs6ZdDtcpWeJFGYnRUV8CxDdZJuSczv7NwiZL1EG72In 3MgBFsXoBFbVatu5J/FwbEa6mn7F7BIqcwXYQi+io1+TcI9nXtM5OjQMITo8vSj1JMmdTMmnBOR JsBUt4MquNWSCCofCA+LeH28/yRc= X-Google-Smtp-Source: AGHT+IENoaNrbUgJpeS/XWUAcejg3u4RYJUMb7JwsPhYjiuRYVfwjWWB+v29uvdilbVxQtUsTgmTGSxPRmmDVCDhs5g= X-Received: by 2002:a05:6e02:1fe8:b0:369:f021:5a5 with SMTP id dt8-20020a056e021fe800b00369f02105a5mr1452384ilb.3.1713507387293; Thu, 18 Apr 2024 23:16:27 -0700 (PDT) References: <20240322082915.3900449-1-mengqinggang@loongson.cn> In-Reply-To: From: Fangrui Song Date: Thu, 18 Apr 2024 23:16:13 -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: [PwAo7wJYyqpMYLOMNhUIUhPQXPZjwzMy] X-ClientProxiedBy: BN1PR10CA0008.namprd10.prod.outlook.com (2603:10b6:408:e0::13) 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_|DM4PR12MB5724:EE_ X-MS-Office365-Filtering-Correlation-Id: fb4c3f61-d212-48b6-6a5e-08dc60391a4c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U0BaTYrP9byLNxfpx3/HL60lI7LIOZCBxMinq9VivCGsoyvvtj8PWeyV9jCT5c1OnUZiWeOgOJpGpcxcCTza2eyqBLdrQk2TEChD901rSe+Jp5zDOKPJtzvOpNhhUG41XR+lvIjnSineXyYgMSwVvF+EjcAv8wOmBQIz95k3vF+DI41XAiS3nDeHDNjuNDHB2GAzcb10U+t+y+UMwfRJG2ffzhIlR8hlZY6vFHDhUDrBpZVu79Ld+Nw6w9fPqeiChJ9RBKe3Jckzvv7rJwsSMQravzUKLKkMpxoOUda15GJ1Acfx9UNSGZh117LLA9SBZNbbq2A6NHWu3TPW8JMF/uyShFBasohoBP/SlCiKpG7RP8gDW1cN/lIMOGNFng6e/865+XJteSPof4+41LMW1DiC8D2Etiad8AANVbNUQYyJH9lhvACft02Pgc0DhrUSlp5Z1eHCKFDtk3LLAn1FTWGH5p3Fccv8w2dWhAzUDSgEINwsfz7Gp5gGuJqfxlNF/NmZQ+qVWWgR5ETOB2qyeKhi9yucpdv8VDRIGu4Y426RmMgJVTXok3jHfDiAWxmb1t1jgRPKjtfGHxKujJzn2vyJ7dh58M2aobnAhyQqg72z5ymzFC2VlPO+kGwLZfQgFzzilGQ3GaSFOX8r4YYpXrXbcphs/K3AQwSGe0iLzVs= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SytyOEowL2NxUVk0blpBZzRmdnVtVFlndzFXa0VickE4SmplbzJlcHJkSUNH?= =?utf-8?B?TjYzWEFUcUV2bUhSMjh3OHFGeVJieGJsUzJ5eFhuM2FON2dCZlpyWitZRVZz?= =?utf-8?B?dW9ncTBvTXVweDlReGhMeWExNTZya2l1S3RQbE1aaVJGZno3SUNMcklNamJV?= =?utf-8?B?ZUJ6VXltZkxVelVxcGVGajRHangycU5yZEpkMUxkdm4zVERyajFuQmhDbXJh?= =?utf-8?B?VWVqcGliU3c2WFFCK2wvNGY1clM3Z1F4dTVQVGpPY3NjTVg0UTRhVkhzOFZh?= =?utf-8?B?Ykx5aXc2RmZCWGlMN0VIZTJNZ0tHdFptVlVOckQrVFAxR2Y5aWhVNlRhcXgr?= =?utf-8?B?azlGSmV4YWgxTjBJV0xrZVRJZFFwcDBaeUt5Q2ZLTHJtN2tiNDk1SWswY2lQ?= =?utf-8?B?ZEZQdWVXdEd3QUtmL2UxRkN5NUF5eVNUSk84ZzFhdkFEd1hsQU04THk2ZUtj?= =?utf-8?B?b0NrSGpaTHRoUmF4SlpKa0J1L0NsTm5RNzlkVEdlUDhTZWxiSWxRUVoyUGZ4?= =?utf-8?B?WFg1OUFwc2tpTmloMEdqQTVPUWMzZElsMDJmczRlc25PR2RTNTFaditzT3hj?= =?utf-8?B?ZitUeFFHQVBEZHBiUlF0Wjg1dDFaTnhJTk1ydEhuV3UrRUh1MUFUc0J3K0Ex?= =?utf-8?B?bERYOXdVblNORmkyWWUyQUNqOVlSanBPZ1Y2TEwzUCszMGwvbDlVT1dMU2ZN?= =?utf-8?B?TDErWk5ydjBhTHRpbWZ5djM1SHlLL3lIVkV6MTVYZWs4QWFoamExRzZLd01Y?= =?utf-8?B?a0tjaW4vVERTTGEyMGVyditUeGRqVElteHNqRjNZbzNpek1qcUJTTld3OWhk?= =?utf-8?B?RlFkeDhTVXdsNm5NZC8xczVVWFcycTJWSkIxVEVEUUhqSVpsaVlyUkRlNkFN?= =?utf-8?B?UUdhaHZZeUE2Q0pnWnBORVZkeHRRTnpqaE1LQy8rYnRhSlFRRmdEbEw5NUlZ?= =?utf-8?B?c01KR1gvYmZUM2o4YUphY3NXZmVJc3JOQUUrM0NRN2lXSmJjbVNHWDJKb0FC?= =?utf-8?B?YXVxMDROTDkyTCtCZVZNMURxSVNPOVRPczBmNkU5OHl0WGRXeWpyT2c0S3k0?= =?utf-8?B?SGNuMUpMZ0ZJVjJsSUp4d2ZiRndrL24yZWNMY0RBNk9IVnM3SHZpUE93ejVR?= =?utf-8?B?QUlETVp2SlM4UVI4eUxvQ0g3UmM5Z3o2NGh0NndVZVM3WDcxL1VKUCtLdEds?= =?utf-8?B?dU8xZmZEbzNzVVJZT2dYVU1yVlFVdVdvK1NLOFNaeDhRWjhsSVQxd05qZTd3?= =?utf-8?B?cm5iRGJQUXVtTVNBdjN2MjJONEVDRDdxUlF3QStuRUdCendIWXlEZDZMTG9t?= =?utf-8?B?REZaeXVBa1FvWWRmTjU1ZExGY2ZtRnQ0WUhrMXhJdUFrTlgvT0NMVjV1UnNu?= =?utf-8?B?dkVjK3NEOUpwTWhmdE9vZzlIeVlsV2dxbDNuYmY0N0x1dllFM1dYdVNqcHRX?= =?utf-8?B?TGNHVVYzcEIrWGVPUU5IYUhYcFpCSkxWemxFMWovNFlJRW9TQWk5WjBIc1Rs?= =?utf-8?B?eTkxWktPYlB5N1J2RjJGaHllOUtrZDlUdm1MZTVyY3Y4V2NReTZUQ2wvL1B5?= =?utf-8?B?UFdpbStCbWJETk8rcGNXZ09nblZlcEpXTGtUWXZ0eWNiZHR4ZEZTMTBtaEdE?= =?utf-8?B?Yk1tUnhYQmpZWmpOdDMrWlVISjVvZlE9PQ==?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-5183d.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: fb4c3f61-d212-48b6-6a5e-08dc60391a4c 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:22:35.2353 (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: DM4PR12MB5724 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 Thu, Apr 18, 2024 at 11:04=E2=80=AFPM Fangrui Song wrote: > > 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 ne= ed 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 relocat= ion is > > STT_SECTION type, the addend of relocation needs to add the section out= put > > offset. We prevent it for R_LARCH_ALIGN. > > > > The elf_backend_data.rela_normal only can set all relocations of a targ= et to > > rela_normal. Add a new function is_rela_normal to elf_backend_data, it = can > > 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.l= ds > > 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->re= la.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_b= fd, > > 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_has= h_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 = add > > + 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 thir= d > > + 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= _entry *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/= gas/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= /testsuite/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/t= estsuite/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 secti= on 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-= loongarch-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 daeda14191c1710ce967259a47ef4e0a3fb6= eebf. > > 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 = undefined symbol error. > > How does this happen when the R_LARCH_ALIGN relocation references > another local symbol instead of .text ? I should make it clear that I think this R_LARCH_ALIGN referencing STT_SECTION with addend align+256*align_limit representation is questionable. Why do you break the regular semantics of STT_SECTION relocatable linking? Can an absolute symbol be used instead?