Skip to content

Commit f2f36c4

Browse files
committed
compiler: Switch default code model for loongarch64 to medium.
LLVM 21 will change the default, but we're making the change now to make building Zig for loongarch64 less painful. llvm/llvm-project#132173
1 parent 4995509 commit f2f36c4

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

build.zig

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -668,24 +668,6 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.St
668668
.strip = options.strip,
669669
.sanitize_thread = options.sanitize_thread,
670670
.single_threaded = options.single_threaded,
671-
.code_model = switch (options.target.result.cpu.arch) {
672-
// NB:
673-
// For loongarch, LLVM supports only small, medium and large
674-
// code model. If we don't explicitly specify the code model,
675-
// the default value `small' will be used.
676-
//
677-
// Since zig binary itself is relatively large, using a `small'
678-
// code model will cause
679-
//
680-
// relocation R_LARCH_B26 out of range
681-
//
682-
// error when linking a loongarch32/loongarch64 zig binary.
683-
//
684-
// Here we explicitly set code model to `medium' to avoid this
685-
// error.
686-
.loongarch32, .loongarch64 => .medium,
687-
else => .default,
688-
},
689671
.valgrind = options.valgrind,
690672
});
691673

src/Package/Module.zig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,14 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
234234
break :b false;
235235
};
236236

237-
const code_model = b: {
237+
const code_model: std.builtin.CodeModel = b: {
238238
if (options.inherited.code_model) |x| break :b x;
239239
if (options.parent) |p| break :b p.code_model;
240-
break :b .default;
240+
break :b switch (target.cpu.arch) {
241+
// Temporary workaround until LLVM 21: https://github.com/llvm/llvm-project/pull/132173
242+
.loongarch64 => .medium,
243+
else => .default,
244+
};
241245
};
242246

243247
const is_safe_mode = switch (optimize_mode) {

0 commit comments

Comments
 (0)