Skip to content

Commit

Permalink
loongarch: use medium code model for zig loongarch64 binary (ziglang#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yxd-ym authored and richerfu committed Oct 28, 2024
1 parent 7002c81 commit d7832b9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d7832b9

Please sign in to comment.