From patchwork Fri Dec 13 05:53:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 102952 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0BFA63858429 for ; Fri, 13 Dec 2024 06:01:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0BFA63858429 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=xry111.site header.i=@xry111.site header.a=rsa-sha256 header.s=default header.b=jfq3vDiz X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 4726B3858423 for ; Fri, 13 Dec 2024 05:55:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4726B3858423 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4726B3858423 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.208.246.23 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734069311; cv=none; b=xXuqmXMO8ckmDQyMEbIddYBqLmLzo1dg/cKV4H00iB91BC9Kp+fWn2H8m2D9I6UCaDY1uzCBlqmSfqPZMsMqfCYHtypfM0WX4sLSdZ951jCRjbs8fSieoTXl8MFcuVhpP1fOY/4XkUFXDohJ7Wg9Q0CaCH7UQ6aVk/otJQxGA1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734069311; c=relaxed/simple; bh=935MtlpgZFyzvoRVtRC78BTGRfY1yjfh/55a65YYJ84=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jAVr2fZcfF82gnOxg54pK+CBJ0jtqwK+y9fzNL2niWJcR76xL6TbigAZY5FdAfN5Bx8IfxduTafpcNvILhn/mg5y/Oxs3J/BgGvdnt3GJ+ipG0s7hbJNaQNXuA1FeaZp7Aqpp9FMLzfa8pQxoUQGVhzYhxZpZs6H5GbV5ypoc94= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4726B3858423 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xry111.site; s=default; t=1734069310; bh=csFK0eSW32/HuY0L/9R6Sr4Gp01mVXERkP4fcwjCcn8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jfq3vDizgOFyT46SVUEMeJZFWreVQi89DsN8qAa6nwpL9n1EpGA1qZuiElSySsPGV 7rEjnlZ56Y4oRHi8XW5KIVEd/a8VMKXq8TNhOJ5aMWAKp5tYDseDxY9CKqVaHYL0o5 waMs3ifz53G3Fsfsf/vhbquMNoOsYFENZrJwLlp4= Received: from stargazer.. (unknown [IPv6:240e:457:1120:870:571c:7044:9d4:458a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 63BD6676A1; Fri, 13 Dec 2024 00:55:04 -0500 (EST) From: Xi Ruoyao To: binutils@sourceware.org Cc: Xi Ruoyao , mengqinggang@loongson.cn, Lulu Cai , Chenghua Xu , Huacai Chen , WANG Xuerui Subject: [PATCH 3/3] LoongArch: Reword message for unresolvable PC-relative relocs Date: Fri, 13 Dec 2024 13:53:52 +0800 Message-ID: <20241213055427.579306-4-xry111@xry111.site> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241213055427.579306-1-xry111@xry111.site> References: <20241213055427.579306-1-xry111@xry111.site> MIME-Version: 1.0 X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, LIKELY_SPAM_FROM, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org If we hit such a bad reloc, it means the programmer has somehow wrongly instructed the compiler to generate PC-relative relocs against external symbols. "Recompiling with -fPIC" (or -fPIE) is just misleading. Signed-off-by: Xi Ruoyao --- bfd/elfnn-loongarch.c | 4 ++++ ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d | 2 +- ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global_pie.d | 2 +- ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d | 2 +- ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak_pie.d | 2 +- ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d | 2 +- ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d | 2 +- 7 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c index 5d252bcccb9..93368275b46 100644 --- a/bfd/elfnn-loongarch.c +++ b/bfd/elfnn-loongarch.c @@ -894,6 +894,10 @@ bad_static_reloc (struct bfd_link_info *info, pic = _("; recompile with -fPIE"); } + if (r_type == R_LARCH_PCREL20_S2 || r_type == R_LARCH_PCALA_HI20) + pic = _("; recompile with -mno-direct-extern-access and check the " + "symbol visibility"); + (*_bfd_error_handler) (_("%pB:(%pA+%#lx): relocation %s against `%s` can not be used when making " "%s%s"), diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d index 6ecefd1d48a..fac02d036ba 100644 --- a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d +++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d @@ -2,4 +2,4 @@ #source: bad_pcala_hi20_global.s #target: [check_shared_lib_support] #ld: -shared --defsym global_a=0x10 --defsym global_b=0x20 -#error: .*: relocation R_LARCH_PCALA_HI20 against `global_b` can not be used when making a shared object; recompile with -fPIC +#error: .*: relocation R_LARCH_PCALA_HI20 against `global_b` can not be used when making a shared object; recompile with -mno-direct-extern-access and check the symbol visibility diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global_pie.d b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global_pie.d index 5dc2f7c4e4b..a5cd359ac63 100644 --- a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global_pie.d +++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global_pie.d @@ -1,4 +1,4 @@ #name: PC-relative relocation making executable #source: bad_pcala_hi20_global_pie.s #ld: -pie -z undefs --defsym _start=0 -#error: .*: relocation R_LARCH_PCALA_HI20 against `sym` can not be used when making a PIE object; recompile with -fPIE +#error: .*: relocation R_LARCH_PCALA_HI20 against `sym` can not be used when making a PIE object; recompile with -mno-direct-extern-access and check the symbol visibility diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d index cefc42cf89f..fa6cff370be 100644 --- a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d +++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d @@ -2,4 +2,4 @@ #source: bad_pcala_hi20_weak.s #target: [check_shared_lib_support] #ld: -shared --defsym global_a=0x10 --defsym global_b=0x20 -#error: .*: relocation R_LARCH_PCALA_HI20 against `global_b` can not be used when making a shared object; recompile with -fPIC +#error: .*: relocation R_LARCH_PCALA_HI20 against `global_b` can not be used when making a shared object; recompile with -mno-direct-extern-access and check the symbol visibility diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak_pie.d b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak_pie.d index 5515f257191..62a3d8dae25 100644 --- a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak_pie.d +++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak_pie.d @@ -1,4 +1,4 @@ #name: PC-relative relocation making executable #source: bad_pcala_hi20_weak_pie.s #ld: -pie --defsym _start=0 -#error: .*: relocation R_LARCH_PCALA_HI20 against `sym` can not be used when making a PIE object; recompile with -fPIE +#error: .*: relocation R_LARCH_PCALA_HI20 against `sym` can not be used when making a PIE object; recompile with -mno-direct-extern-access and check the symbol visibility diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d index 8e063dfb0ec..b517f22c20c 100644 --- a/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d +++ b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d @@ -2,4 +2,4 @@ #source: bad_pcrel20_s2_global.s #target: [check_shared_lib_support] #ld: -shared --defsym global_a=0x10 --defsym global_b=0x20 -#error: .*: relocation R_LARCH_PCREL20_S2 against `global_b` can not be used when making a shared object; recompile with -fPIC +#error: .*: relocation R_LARCH_PCREL20_S2 against `global_b` can not be used when making a shared object; recompile with -mno-direct-extern-access and check the symbol visibility diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d index 605df24988a..bf551ef6db2 100644 --- a/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d +++ b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d @@ -2,4 +2,4 @@ #source: bad_pcrel20_s2_weak.s #target: [check_shared_lib_support] #ld: -shared --defsym global_a=0x10 --defsym global_b=0x20 -#error: .*: relocation R_LARCH_PCREL20_S2 against `global_b` can not be used when making a shared object; recompile with -fPIC +#error: .*: relocation R_LARCH_PCREL20_S2 against `global_b` can not be used when making a shared object; recompile with -mno-direct-extern-access and check the symbol visibility