[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <c9a43e5da01ee2215393c0f3c50956171fe660ab.camel@xry111.site>
Date: Mon, 09 Dec 2024 18:01:56 +0800
From: Xi Ruoyao <xry111@...111.site>
To: Ard Biesheuvel <ardb@...nel.org>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>, Huacai Chen
<chenhuacai@...nel.org>, Huacai Chen <chenhuacai@...ngson.cn>, Sasha Levin
<sashal@...nel.org>, Xuerui Wang <kernel@...0n.name>, Masahiro Yamada
<masahiroy@...nel.org>, Nathan Chancellor <nathan@...nel.org>, Nick
Desaulniers <ndesaulniers@...gle.com>, Nicolas Schier <nicolas@...sle.eu>,
stable@...r.kernel.org, linux-kbuild@...r.kernel.org,
linux-kernel@...r.kernel.org, loongarch@...ts.linux.dev
Subject: Re: [PATCH 6.1&6.6 0/3] kbuild: Avoid weak external linkage where
possible
On Mon, 2024-12-09 at 09:31 +0100, Ard Biesheuvel wrote:
> Given that this is relatively new toolchain behavior, I'd suggest
> fixing the compiler to emit weak external references via GOT entries
> even when -mdirect-extern-access is in effect.
I'm working on an approach in the linker instead. A PC-relative address
in +/- 2GiB range is
pcalau12i.d $a0, %pc_hi20(sym + addend)
addi.d $a0, $a0, %pc_lo12(sym + addend)
If doing a static linking, when sym is weak undefined, we should just
load addend. The compiler already guarantees addend is in [-2**31,
2**31) range, so we just need to rewrite the pair to
lu12i.w $a0, ((addend + 0x800) & ~0x7ff)
addi.d $a0, $a0, (addend & 0x7ff)
OTOH if not doing a static linking, the user shouldn't use -mdirect-
extern-access at all [this rule is the thing related to copy relocation:
if copy relocation was available it would be possibly valid to use -
mdirect-extern-access w/o static linking] and the linker is correct to
report an error (but the error message is unclear and I need to fix it
anyway).
--
Xi Ruoyao <xry111@...111.site>
School of Aerospace Science and Technology, Xidian University
Powered by blists - more mailing lists