From ea171a2ea87f6bc8391287fb9787719f4613358d Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 03:30:17 +0100 Subject: [PATCH] Use sysroot search directories and 16 KiB ARM linker pages in the compiler driver --- tools/vinix-cc.v | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tools/vinix-cc.v b/tools/vinix-cc.v index 3d61386..c2f7b6c 100644 --- a/tools/vinix-cc.v +++ b/tools/vinix-cc.v @@ -4,6 +4,26 @@ module main import os +// Libtool can add -L/usr/lib while it relinks libraries under DESTDIR. GCC's +// --sysroot does not rebase an ordinary -L argument. Keep these explicit +// system directories inside the SDK, including their two-argument spellings. +fn target_search_args(root string, input []string) []string { + mut args := []string{cap: input.len} + mut previous := '' + for arg in input { + if (previous == '-L' && arg in ['/usr/lib', '/lib']) + || (previous in ['-I', '-isystem'] && arg == '/usr/include') { + args << root + arg + } else if arg in ['-L/usr/lib', '-L/lib', '-I/usr/include'] { + args << arg[..2] + root + arg[2..] + } else { + args << arg + } + previous = arg + } + return args +} + fn main() { driver := os.base(os.args[0]) root := os.getenv('VPAC_MAKEPKG_ROOT') @@ -23,7 +43,13 @@ fn main() { os.getenv_opt('VINIX_REAL_CC') or { prefix + 'gcc' } } mut args := ['--sysroot=${root}', '-specs=${specs}'] - args << os.args[1..] + args << target_search_args(root, os.args[1..]) + // The released AArch64 kernel maps 16 KiB pages. Some cross GCC + // distributions select a 4 KiB linker maximum even with a musl sysroot. + if os.is_file(os.join_path(root, 'lib/ld-musl-aarch64.so.1')) + && !os.args[1..].any(it in ['-c', '-E', '-S', '-M', '-MM', '-fsyntax-only', '-r']) { + args << '-Wl,-z,max-page-size=16384' + } os.execvp(compiler, args) or { eprintln('${driver}: ${compiler}: ${err}') exit(1) -- 2.56.1