| author | |
| committer | |
| log | f2f36c49c8856674e0769300a5c2768a47302520 |
| tree | 3b885ae403f3d56dcc8476ab39350e038dfd5c85 |
| parent | 499550902824ad8862cd43f972fdb052df531e2c |
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/1321732 files changed, 6 insertions(+), 20 deletions(-)
build.zig-18| ... | @@ -668,24 +668,6 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.St | ... | @@ -668,24 +668,6 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.St |
| 668 | .strip = options.strip, | 668 | .strip = options.strip, |
| 669 | .sanitize_thread = options.sanitize_thread, | 669 | .sanitize_thread = options.sanitize_thread, |
| 670 | .single_threaded = options.single_threaded, | 670 | .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 | }, | ||
| 689 | .valgrind = options.valgrind, | 671 | .valgrind = options.valgrind, |
| 690 | }); | 672 | }); |
| 691 | 673 |
src/Package/Module.zig+6-2| ... | @@ -234,10 +234,14 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { | ... | @@ -234,10 +234,14 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { |
| 234 | break :b false; | 234 | break :b false; |
| 235 | }; | 235 | }; |
| 236 | 236 | ||
| 237 | const code_model = b: { | 237 | const code_model: std.builtin.CodeModel = b: { |
| 238 | if (options.inherited.code_model) |x| break :b x; | 238 | if (options.inherited.code_model) |x| break :b x; |
| 239 | if (options.parent) |p| break :b p.code_model; | 239 | 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 | }; | ||
| 241 | }; | 245 | }; |
| 242 | 246 | ||
| 243 | const is_safe_mode = switch (optimize_mode) { | 247 | const is_safe_mode = switch (optimize_mode) { |