Re: [PATCH 6.1&6.6 0/3] kbuild: Avoid weak external linkage where possible

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University





[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux