authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-04-07 13:59:21+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-04-07 21:36:56+02:00
logf2f36c49c8856674e0769300a5c2768a47302520
tree3b885ae403f3d56dcc8476ab39350e038dfd5c85
parent499550902824ad8862cd43f972fdb052df531e2c

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. https://github.com/llvm/llvm-project/pull/132173

2 files changed, 6 insertions(+), 20 deletions(-)

build.zig-18
......@@ -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+6-2
......@@ -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) {