aboutsummaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorYANG Xudong <yangxudong@ymatrix.cn>2024-09-01 11:59:24 +0800
committerGitHub <noreply@github.com>2024-08-31 20:59:24 -0700
commitc34cfe486d70ac5e92f101a47fc70a1336077e7e (patch)
tree5f7bbcec3259be63127801a93b5deeebeffb739a /build.zig
parent96daca7b3b6f02033e68ac91776bf6e8d2b67409 (diff)
downloadzig-c34cfe486d70ac5e92f101a47fc70a1336077e7e.tar.gz
zig-c34cfe486d70ac5e92f101a47fc70a1336077e7e.zip
loongarch: use medium code model for zig loongarch64 binary (#21153)
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig18
1 files changed, 18 insertions, 0 deletions
diff --git a/build.zig b/build.zig
index 1b95c190d1..264cbe0405 100644
--- a/build.zig
+++ b/build.zig
@@ -647,6 +647,24 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.St
.strip = options.strip,
.sanitize_thread = options.sanitize_thread,
.single_threaded = options.single_threaded,
+ .code_model = switch (options.target.result.cpu.arch) {
+ // NB:
+ // For loongarch, LLVM supports only small, medium and large
+ // code model. If we don't explicitly specify the code model,
+ // the default value `small' will be used.
+ //
+ // Since zig binary itself is relatively large, using a `small'
+ // code model will cause
+ //
+ // relocation R_LARCH_B26 out of range
+ //
+ // error when linking a loongarch64 zig binary.
+ //
+ // Here we explicitly set code model to `medium' to avoid this
+ // error.
+ .loongarch64 => .medium,
+ else => .default,
+ },
});
exe.root_module.valgrind = options.valgrind;
exe.stack_size = stack_size;