From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id E60C53858404 for ; Wed, 31 Aug 2022 13:42:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E60C53858404 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=1661953320; bh=J317y661ZE9C4qjHRicGZSLowIWvjBqztUajhIazkHc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=KTsyFchR9CRRc1UolGWAjs9iOhl20umgxOEeEAw9dk74PjFReffwfFIk8Ng0RJQMm ygs3QB4Cv4clevy++1DfwVgmOzRzA2Rpf31ulsV9Bg2tvLbhPnOM+EuFcJZtdRGmim Z/VNu6tO9FNZOL8e6GfIXGq+YQlffY9422llnrLM= Received: from localhost.localdomain (xry111.site [IPv6:2001:470:683e::1]) (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 0C79E668A0; Wed, 31 Aug 2022 09:41:58 -0400 (EDT) Message-ID: Subject: Re: [PATCH] LoongArch: Use copy relocation for %pc_lo12 against external symbol From: Xi Ruoyao To: binutils@sourceware.org Cc: liuzhensong , WANG Xuerui , caiyinyu Date: Wed, 31 Aug 2022 21:41:56 +0800 In-Reply-To: <20220831132259.71417-1-xry111@xry111.site> References: <20220831132259.71417-1-xry111@xry111.site> 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.7 required=5.0 tests=BAYES_00,BODY_8BITS,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: Some self review: On Wed, 2022-08-31 at 21:22 +0800, Xi Ruoyao wrote: > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= /* For pcalau12i + jirl.=C2=A0 */ > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= h->needs_plt =3D 1; > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= if (h->plt.refcount < 0) > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0h->plt.refcount =3D 0; > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= h->plt.refcount++; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= /* Check if it's a jirl instruction.=C2=A0 */ > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= bfd_byte *contents =3D elf_section_data (sec)->this_hdr.contents; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= uint32_t insn =3D 0; > + > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= if (contents || bfd_malloc_and_get_section (abfd, sec, &contents)) > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0memcpy(&insn, contents + rel->r_offset, sizeof(insn)); > + > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= if ((insn & 0xfc000000) =3D=3D 0x4c000000) This is tricky. 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 pcalau12i $t0, %pc_hi20(data) ld.d, $t0, $t0, %pc_lo12(data) With 42bd525, the BFD linker generates a "PLT for data" (absolutely nonsense), and destroys the ld.d instruction. All of these buggy behavior happens silently, the user will only find something wrong when the linked program crashes. I'm not sure if checking JIRL (i. e. the behavior of a relocation now depends on the instruction where it's applied) is a good idea. Maybe we should use the following instead of pcalau12i/jirl: pcaddu18i $t0, %b16_hi20(func) jirl $ra, $t0, %b16(func) ("b16_hi20" is a hypothetical thing here.) This will make things less tricky, and also expand the range to 128 GiB. --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University