Page MenuHomeFreeBSD

riscv: Enable linker relaxation with lld 15 and later
Needs ReviewPublic

Authored by rick_sloservers.com on Sat, Oct 3, 12:56 PM.
Tags
Referenced Files
F174775672: D60278.diff
Mon, Oct 5, 10:27 PM
F174739429: D60278.diff
Mon, Oct 5, 3:33 PM
F174739001: D60278.id.diff
Mon, Oct 5, 3:28 PM
Unknown Object (File)
Mon, Oct 5, 8:56 AM
Unknown Object (File)
Sun, Oct 4, 10:19 PM
Unknown Object (File)
Sun, Oct 4, 4:47 PM
Unknown Object (File)
Sun, Oct 4, 1:26 AM
Unknown Object (File)
Sun, Oct 4, 12:13 AM
Subscribers

Details

Summary

ld.lld gained RISC-V linker relaxation in LLVM 15, but bsd.linker.mk
only reports riscv-relaxations for GNU ld, so we still build with
-mno-relax.

Report it for lld 15 and later, and pass -mrelax explicitly since our
clang defaults to -mno-relax (389f88cffd0d).

Test Plan

Built world and a QEMU kernel for riscv64 with lld 19 and compared them with an unrelaxed build of the same tree, verified relaxation took effect: every call in libc.so.7 is now a jal, and so are about half of the calls in the kernel.

The kernel boots to multi-user in qemu-system-riscv64, with and without loader.efi. Modules work too, including a VNET jail with epair and pf, which is what relaxation broke on arm64 (PR 264094).

kyua results for lib/libc, lib/msun, bin/sh and sys/net match the unrelaxed build.

Tested only in QEMU, I lack RISCV hardware for testing on real hw.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

Did you use LLMs to generate this?

Did you use LLMs to generate this?

Yes

If you’re to use them, at least have the decency to remove all the slop and write a proper commit message. As it stands this is a very low-effort change that feels extractive.

Yes, no problem. Sorry, it's not lack of effort on my part, just ignorance. I'm new to this system and didn't know that the summary becomes the commit message, I can understand now why that would be irritating. Give a few moments, please, and I will rewrite.

rick_sloservers.com retitled this revision from riscv: Use linker relaxation with lld 15 and later to riscv: Enable linker relaxation with lld 15 and later.Sat, Oct 3, 1:42 PM
rick_sloservers.com edited the summary of this revision. (Show Details)
rick_sloservers.com edited the test plan for this revision. (Show Details)
stand/defs.mk
186–188

What's going on here that you didn't add the -mrelax flag? Are we opting to never enable relaxations for the bootloader?

stand/defs.mk
186–188

No, the loader gets relaxed too. stand/efi/loader and libsa include bsd.prog.mk and bsd.lib.mk, which now add -mrelax when the linker supports relaxations, so this block only matters for a linker that can't relax. With lld 15+ it doesn't apply. I only changed its comment, since it said lld can't relax.

I can add a .else with -mrelax here too if you'd rather it be explicit.