From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id A49343858294 for ; Sun, 18 Sep 2022 09:58:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A49343858294 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1663495094; bh=SbmtfFOgRlLrnrvM+elNM72VFg89Zbkcb5LYxnQt4mE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Ly/6gHoCCsLOMeJYk6tdBnQ5CmOaO+5/Zqebd7cinQOJmajMhA40HMDFBHO5GD0+g FrtbP58Ie9p03Tq+R19HWo9RBr+PC+5jiJMKU0TAzCMi9AnkjpR8EaQiNRxFWr7kes qLS0CcihBD+yV+uUXyLfaH+gdkSE8sYXy/QK/Yss= Received: from [IPv6:240e:358:1176:d200:dc73:854d:832e:2] (unknown [IPv6:240e:358:1176:d200:dc73:854d:832e:2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 94DD6661EC; Sun, 18 Sep 2022 05:58:10 -0400 (EDT) Message-ID: <793d0e700362794e814ad67c78aa532458202aef.camel@xry111.site> Subject: Re: [PATCH 2/2] LoongArch: Fix R_LARCH_IRELATIVE insertion after elf_link_sort_relocs From: Xi Ruoyao To: liuzhensong , binutils@sourceware.org Cc: Chenghua Xu , Lulu Cheng , Wang Xuerui Date: Sun, 18 Sep 2022 17:58:03 +0800 In-Reply-To: References: <20220913154414.554861-1-xry111@xry111.site> <20220913154414.554861-3-xry111@xry111.site> <939eebd1-365d-72c5-5b2c-43bd6e0f1ff2@loongson.cn> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.0 MIME-Version: 1.0 X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD,LIKELY_SPAM_FROM,SPF_HELO_PASS,SPF_PASS,TXREP,T_PDS_OTHER_BAD_TLD autolearn=no 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 Sat, 2022-09-17 at 04:11 +0800, Xi Ruoyao via Binutils wrote: > The problem is loongarch_elf_finish_dynamic_symbol runs after > elf_link_sort_relocs.=C2=A0 elf_link_sort_relocs basically does: >=20 > (pseudo code) >=20 > buffer =3D [] > for section in {input of .rela.dyn} > =C2=A0=C2=A0=C2=A0 buffer +=3D (section.content) as [RELA] >=20 > buffer.sort_by(some_comparator) >=20 > buffer =3D buffer as [byte] > for section in {input of .rela.dyn} > =C2=A0=C2=A0=C2=A0 section.content =3D buffer[..section.content.len()] > =C2=A0=C2=A0=C2=A0 buffer =3D buffer[section.content.len()..] >=20 > So a "slot" in relplt->contents can end up elsewhere.=C2=A0 You can read = the > code of elf_link_sort_relocs to see it... >=20 > I can try to write a test case for this, but it's 04:00 AM now so I'd do > it after a sleep... Take this as an example, note that the R_LARCH_IRELATIVE relocation is missing with -z combreloc: $ cat b1.s .text .align 2 .local ifunc .type ifunc, @gnu_indirect_function .set ifunc, resolver resolver: la.local $a0, impl jr $ra impl: li.w $a0, 42 jr $ra .global test .type test, @function test: move $s0, $ra bl ifunc xori $a0, $a0, 42 jr $s0 .data .global ptr .type ptr, @object ptr: .dword test $ gas/as-new b1.s -o b1.o $ ld/ld-new -shared b1.o # "-z combreloc" is the default $ readelf -r a.out Relocation section '.rela.dyn' at offset 0x1f0 contains 2 entries: Offset Info Type Sym. Value Sym. Name + A= ddend 000000000000 000000000000 R_LARCH_NONE 8018 000000008000 000400000002 R_LARCH_64 0000000000000264 test + 0 $ ld/ld-new -shared b1.o -z nocombreloc $ readelf -r a.out Relocation section '.rela.data' at offset 0x1f0 contains 1 entry: Offset Info Type Sym. Value Sym. Name + A= ddend 000000008000 000400000002 R_LARCH_64 0000000000000264 test + 0 Relocation section '.rela.got' at offset 0x208 contains 1 entry: Offset Info Type Sym. Value Sym. Name + A= ddend 000000008018 00000000000c R_LARCH_IRELATIVE 250 --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University