Use sysroot search directories and 16 KiB ARM linker pages in the compiler driver
@@ -4,6 +4,26 @@ module main
44
55import os
66
7+// Libtool can add -L/usr/lib while it relinks libraries under DESTDIR. GCC's
8+// --sysroot does not rebase an ordinary -L argument. Keep these explicit
9+// system directories inside the SDK, including their two-argument spellings.
10+fn target_search_args(root string, input []string) []string {
11+ mut args := []string{cap: input.len}
12+ mut previous := ''
13+ for arg in input {
14+ if (previous == '-L' && arg in ['/usr/lib', '/lib'])
15+ || (previous in ['-I', '-isystem'] && arg == '/usr/include') {
16+ args << root + arg
17+ } else if arg in ['-L/usr/lib', '-L/lib', '-I/usr/include'] {
18+ args << arg[..2] + root + arg[2..]
19+ } else {
20+ args << arg
21+ }
22+ previous = arg
23+ }
24+ return args
25+}
26+
727fn main() {
828 driver := os.base(os.args[0])
929 root := os.getenv('VPAC_MAKEPKG_ROOT')
@@ -23,7 +43,13 @@ fn main() {
2343 os.getenv_opt('VINIX_REAL_CC') or { prefix + 'gcc' }
2444 }
2545 mut args := ['--sysroot=${root}', '-specs=${specs}']
26- args << os.args[1..]
46+ args << target_search_args(root, os.args[1..])
47+ // The released AArch64 kernel maps 16 KiB pages. Some cross GCC
48+ // distributions select a 4 KiB linker maximum even with a musl sysroot.
49+ if os.is_file(os.join_path(root, 'lib/ld-musl-aarch64.so.1'))
50+ && !os.args[1..].any(it in ['-c', '-E', '-S', '-M', '-MM', '-fsyntax-only', '-r']) {
51+ args << '-Wl,-z,max-page-size=16384'
52+ }
2753 os.execvp(compiler, args) or {
2854 eprintln('${driver}: ${compiler}: ${err}')
2955 exit(1)