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 3EABB38362CE for ; Thu, 1 Sep 2022 02:12:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3EABB38362CE 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=1661998347; bh=KvqMvMRcw4IrgMFTHcI2psrWPcfItMm44YNKupjmWow=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=UOx7AU41kyIWnFHySUUHJvJlWjbeP2O6vSYDIeCbyhbs92nGGK2etusBT/v7U1CeW mlqpeSKFPH7Q0mPLUQnK9PLkf1hCTkM0vPDwmpm6W+WVJvSOuOH93aU9duT01SiD/e ei9KnXSzJ0lWq/RHT8k2C/zk8Zi9uonoF2V3VtbU= Received: from [IPv6:240e:358:118a:f800:dc73:854d:832e:4] (unknown [IPv6:240e:358:118a:f800:dc73:854d:832e:4]) (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 4C83A65CFA; Wed, 31 Aug 2022 22:12:23 -0400 (EDT) Message-ID: Subject: Re: [PATCH] LoongArch: Use copy relocation for %pc_lo12 against external symbol From: Xi Ruoyao To: liuzhensong , binutils@sourceware.org Cc: WANG Xuerui , chenglulu@loongson.cn Date: Thu, 01 Sep 2022 10:12:16 +0800 In-Reply-To: <3b43c733-6011-8c7c-4a1e-3faa9f91f711@loongson.cn> References: <20220831132259.71417-1-xry111@xry111.site> <3b43c733-6011-8c7c-4a1e-3faa9f91f711@loongson.cn> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.45.2 MIME-Version: 1.0 X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD,LIKELY_SPAM_FROM,PDS_OTHER_BAD_TLD,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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 Thu, 2022-09-01 at 09:38 +0800, liuzhensong wrote: > > But in commit 42bd525 we already started to rely on > > undocumented %pc_{hi20,lo12} behavior: if you just apply them "as > > documented" to the pcalau12i/jirl pairs the result will be > > absolutely > > wrong. And 42bd525 behavior is not fully correct: if you just write > >=20 > > pcalau12i $t0, %pc_hi20(data) > > ld.d, $t0, $t0, %pc_lo12(data) > Do you have a test case? $ cat t2.s =20 .text .align 2 .type x, @function .global x x: pcalau12i $a0, %pc_hi20(data) ld.d $a0, $a0, %pc_lo12(data) jr $ra $ gcc t2.s -c $ ./ld/ld-new t2.o -shared $ objdump -d | grep -A50 data 0000000000000210 : 210: 1c00010f pcaddu12i $t3, 8(0x8) 214: 28f801ef ld.d $t3, $t3, -512(0xe00) 218: 4c0001ed jirl $t1, $t3, 0 21c: 03400000 andi $zero, $zero, 0x0 Disassembly of section .text: 0000000000000220 : 220: 1a000004 pcalau12i $a0, 0 224: 28c84084 ld.d $a0, $a0, 528(0x210) 228: 4c000020 jirl $zero, $ra, 0 i.e. Instead of reporting an error like "cannot create a runtime relocation against external symbol 'data'", the linker silently produces a PLT (nonsense: can you use a PLT for data?) and load two instructions from the PLT into the register (also nonsense). So if someone mistypes "la.local" where "la.global" should be used (it's just a simple programming mistake, and it's likely to happen in the practice!), the linking will "succeeds" silently. Then the program blows up at runtime. > It doesn't make sense for only "pcaddu18i + jirl" to access 128G. > What we need is a jump that can access =C2=B12G, just like any other pc- > relative instructions can access =C2=B12G. The point is, if we interpret %pc_lo12 "as it's documented": "(*(uint32_t *) PC) [21 ... 10] =3D (S+A) [11 ... 0]" it will be absolutely wrong for a jirl instruction. You may update the doc to say something like "if R_LARCH_PCALA_LO12 is applied to a jirl instruction, a PLT entry will be created and blah blah". But again I'm not sure about if "the behavior of a relocation depends on the instruction for which it's applied" is a good idea. We are using highly imprecise descriptions for PCALA-style relocations in ELF psABI, despite I've disagreed in the review. Now if someone wants to know "how this relocation will *really* behave", he/she will need to read BFD code. PCALAU12I instruction itself is already puzzling enough (comparing with PCADDU12I, which behaves more "normal"), now the doc just makes it more puzzling. --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University