| author | |
| committer | |
| log | 75e9a722db3335da0e8c254a0e04c5775ebfc160 |
| tree | 5b7ca9dec716b2b883a224fa25289c32cb556a10 |
| parent | 3ded862cdf4cec619aea95b595103b72dd23c401 |
| parent | bfebc11d0633e3f4a3fe86d1a9d6f90ffdb1fbb6 |
| signature |
fix -target and -mcpu issues7 files changed, 59 insertions(+), 58 deletions(-)
lib/std/zig/system.zig+6-15| ... | ... | @@ -325,22 +325,19 @@ pub const NativeTargetInfo = struct { |
| 325 | 325 | // native CPU architecture as being different than the current target), we use this: |
| 326 | 326 | const cpu_arch = cross_target.getCpuArch(); |
| 327 | 327 | |
| 328 | const cpu = switch (cross_target.cpu_model) { | |
| 328 | var cpu = switch (cross_target.cpu_model) { | |
| 329 | 329 | .native => detectNativeCpuAndFeatures(cpu_arch, os, cross_target), |
| 330 | .baseline => baselineCpuAndFeatures(cpu_arch, cross_target), | |
| 330 | .baseline => Target.Cpu.baseline(cpu_arch), | |
| 331 | 331 | .determined_by_cpu_arch => if (cross_target.cpu_arch == null) |
| 332 | 332 | detectNativeCpuAndFeatures(cpu_arch, os, cross_target) |
| 333 | 333 | else |
| 334 | baselineCpuAndFeatures(cpu_arch, cross_target), | |
| 335 | .explicit => |model| blk: { | |
| 336 | var adjusted_model = model.toCpu(cpu_arch); | |
| 337 | cross_target.updateCpuFeatures(&adjusted_model.features); | |
| 338 | break :blk adjusted_model; | |
| 339 | }, | |
| 334 | Target.Cpu.baseline(cpu_arch), | |
| 335 | .explicit => |model| model.toCpu(cpu_arch), | |
| 340 | 336 | } orelse backup_cpu_detection: { |
| 341 | 337 | cpu_detection_unimplemented = true; |
| 342 | break :backup_cpu_detection baselineCpuAndFeatures(cpu_arch, cross_target); | |
| 338 | break :backup_cpu_detection Target.Cpu.baseline(cpu_arch); | |
| 343 | 339 | }; |
| 340 | cross_target.updateCpuFeatures(&cpu.features); | |
| 344 | 341 | |
| 345 | 342 | var target = try detectAbiAndDynamicLinker(allocator, cpu, os, cross_target); |
| 346 | 343 | target.cpu_detection_unimplemented = cpu_detection_unimplemented; |
| ... | ... | @@ -884,10 +881,4 @@ pub const NativeTargetInfo = struct { |
| 884 | 881 | }, |
| 885 | 882 | } |
| 886 | 883 | } |
| 887 | ||
| 888 | fn baselineCpuAndFeatures(cpu_arch: Target.Cpu.Arch, cross_target: CrossTarget) Target.Cpu { | |
| 889 | var adjusted_baseline = Target.Cpu.baseline(cpu_arch); | |
| 890 | cross_target.updateCpuFeatures(&adjusted_baseline.features); | |
| 891 | return adjusted_baseline; | |
| 892 | } | |
| 893 | 884 | }; |
src-self-hosted/stage2.zig+40-39| ... | ... | @@ -679,44 +679,42 @@ fn stage2TargetParse( |
| 679 | 679 | mcpu_oz: ?[*:0]const u8, |
| 680 | 680 | dynamic_linker_oz: ?[*:0]const u8, |
| 681 | 681 | ) !void { |
| 682 | const target: CrossTarget = if (zig_triple_oz) |zig_triple_z| blk: { | |
| 683 | const zig_triple = mem.toSliceConst(u8, zig_triple_z); | |
| 684 | const mcpu = if (mcpu_oz) |mcpu_z| mem.toSliceConst(u8, mcpu_z) else null; | |
| 685 | const dynamic_linker = if (dynamic_linker_oz) |dl_z| mem.toSliceConst(u8, dl_z) else null; | |
| 686 | var diags: CrossTarget.ParseOptions.Diagnostics = .{}; | |
| 687 | break :blk CrossTarget.parse(.{ | |
| 688 | .arch_os_abi = zig_triple, | |
| 689 | .cpu_features = mcpu, | |
| 690 | .dynamic_linker = dynamic_linker, | |
| 691 | .diagnostics = &diags, | |
| 692 | }) catch |err| switch (err) { | |
| 693 | error.UnknownCpuModel => { | |
| 694 | std.debug.warn("Unknown CPU: '{}'\nAvailable CPUs for architecture '{}':\n", .{ | |
| 695 | diags.cpu_name.?, | |
| 696 | @tagName(diags.arch.?), | |
| 697 | }); | |
| 698 | for (diags.arch.?.allCpuModels()) |cpu| { | |
| 699 | std.debug.warn(" {}\n", .{cpu.name}); | |
| 700 | } | |
| 701 | process.exit(1); | |
| 702 | }, | |
| 703 | error.UnknownCpuFeature => { | |
| 704 | std.debug.warn( | |
| 705 | \\Unknown CPU feature: '{}' | |
| 706 | \\Available CPU features for architecture '{}': | |
| 707 | \\ | |
| 708 | , .{ | |
| 709 | diags.unknown_feature_name, | |
| 710 | @tagName(diags.arch.?), | |
| 711 | }); | |
| 712 | for (diags.arch.?.allFeaturesList()) |feature| { | |
| 713 | std.debug.warn(" {}: {}\n", .{ feature.name, feature.description }); | |
| 714 | } | |
| 715 | process.exit(1); | |
| 716 | }, | |
| 717 | else => |e| return e, | |
| 718 | }; | |
| 719 | } else .{}; | |
| 682 | const zig_triple = if (zig_triple_oz) |zig_triple_z| mem.toSliceConst(u8, zig_triple_z) else "native"; | |
| 683 | const mcpu = if (mcpu_oz) |mcpu_z| mem.toSliceConst(u8, mcpu_z) else null; | |
| 684 | const dynamic_linker = if (dynamic_linker_oz) |dl_z| mem.toSliceConst(u8, dl_z) else null; | |
| 685 | var diags: CrossTarget.ParseOptions.Diagnostics = .{}; | |
| 686 | const target: CrossTarget = CrossTarget.parse(.{ | |
| 687 | .arch_os_abi = zig_triple, | |
| 688 | .cpu_features = mcpu, | |
| 689 | .dynamic_linker = dynamic_linker, | |
| 690 | .diagnostics = &diags, | |
| 691 | }) catch |err| switch (err) { | |
| 692 | error.UnknownCpuModel => { | |
| 693 | std.debug.warn("Unknown CPU: '{}'\nAvailable CPUs for architecture '{}':\n", .{ | |
| 694 | diags.cpu_name.?, | |
| 695 | @tagName(diags.arch.?), | |
| 696 | }); | |
| 697 | for (diags.arch.?.allCpuModels()) |cpu| { | |
| 698 | std.debug.warn(" {}\n", .{cpu.name}); | |
| 699 | } | |
| 700 | process.exit(1); | |
| 701 | }, | |
| 702 | error.UnknownCpuFeature => { | |
| 703 | std.debug.warn( | |
| 704 | \\Unknown CPU feature: '{}' | |
| 705 | \\Available CPU features for architecture '{}': | |
| 706 | \\ | |
| 707 | , .{ | |
| 708 | diags.unknown_feature_name, | |
| 709 | @tagName(diags.arch.?), | |
| 710 | }); | |
| 711 | for (diags.arch.?.allFeaturesList()) |feature| { | |
| 712 | std.debug.warn(" {}: {}\n", .{ feature.name, feature.description }); | |
| 713 | } | |
| 714 | process.exit(1); | |
| 715 | }, | |
| 716 | else => |e| return e, | |
| 717 | }; | |
| 720 | 718 | |
| 721 | 719 | try stage1_target.fromTarget(target); |
| 722 | 720 | } |
| ... | ... | @@ -902,6 +900,7 @@ const Stage2Target = extern struct { |
| 902 | 900 | llvm_cpu_features: ?[*:0]const u8, |
| 903 | 901 | cpu_builtin_str: ?[*:0]const u8, |
| 904 | 902 | cache_hash: ?[*:0]const u8, |
| 903 | cache_hash_len: usize, | |
| 905 | 904 | os_builtin_str: ?[*:0]const u8, |
| 906 | 905 | |
| 907 | 906 | dynamic_linker: ?[*:0]const u8, |
| ... | ... | @@ -1131,6 +1130,7 @@ const Stage2Target = extern struct { |
| 1131 | 1130 | } |
| 1132 | 1131 | }; |
| 1133 | 1132 | |
| 1133 | const cache_hash_slice = cache_hash.toOwnedSlice(); | |
| 1134 | 1134 | self.* = .{ |
| 1135 | 1135 | .arch = @enumToInt(target.cpu.arch) + 1, // skip over ZigLLVM_UnknownArch |
| 1136 | 1136 | .vendor = 0, |
| ... | ... | @@ -1140,7 +1140,8 @@ const Stage2Target = extern struct { |
| 1140 | 1140 | .llvm_cpu_features = llvm_features_buffer.toOwnedSlice().ptr, |
| 1141 | 1141 | .cpu_builtin_str = cpu_builtin_str_buffer.toOwnedSlice().ptr, |
| 1142 | 1142 | .os_builtin_str = os_builtin_str_buffer.toOwnedSlice().ptr, |
| 1143 | .cache_hash = cache_hash.toOwnedSlice().ptr, | |
| 1143 | .cache_hash = cache_hash_slice.ptr, | |
| 1144 | .cache_hash_len = cache_hash_slice.len, | |
| 1144 | 1145 | .is_native = cross_target.isNative(), |
| 1145 | 1146 | .glibc_or_darwin_version = glibc_or_darwin_version, |
| 1146 | 1147 | .dynamic_linker = dynamic_linker, |
src/cache_hash.cpp+6-2| ... | ... | @@ -24,11 +24,15 @@ void cache_init(CacheHash *ch, Buf *manifest_dir) { |
| 24 | 24 | ch->b64_digest = BUF_INIT; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | void cache_str(CacheHash *ch, const char *ptr) { | |
| 27 | void cache_mem(CacheHash *ch, const char *ptr, size_t len) { | |
| 28 | 28 | assert(ch->manifest_file_path == nullptr); |
| 29 | 29 | assert(ptr != nullptr); |
| 30 | 30 | // + 1 to include the null byte |
| 31 | blake2b_update(&ch->blake, ptr, strlen(ptr) + 1); | |
| 31 | blake2b_update(&ch->blake, ptr, len); | |
| 32 | } | |
| 33 | ||
| 34 | void cache_str(CacheHash *ch, const char *ptr) { | |
| 35 | cache_mem(ch, ptr, strlen(ptr) + 1); | |
| 32 | 36 | } |
| 33 | 37 | |
| 34 | 38 | void cache_int(CacheHash *ch, int x) { |
src/cache_hash.hpp+1| ... | ... | @@ -35,6 +35,7 @@ struct CacheHash { |
| 35 | 35 | void cache_init(CacheHash *ch, Buf *manifest_dir); |
| 36 | 36 | |
| 37 | 37 | // Next, use the hash population functions to add the initial parameters. |
| 38 | void cache_mem(CacheHash *ch, const char *ptr, size_t len); | |
| 38 | 39 | void cache_str(CacheHash *ch, const char *ptr); |
| 39 | 40 | void cache_int(CacheHash *ch, int x); |
| 40 | 41 | void cache_bool(CacheHash *ch, bool x); |
src/codegen.cpp+2-2| ... | ... | @@ -8664,7 +8664,7 @@ static Error define_builtin_compile_vars(CodeGen *g) { |
| 8664 | 8664 | cache_int(&cache_hash, g->zig_target->os); |
| 8665 | 8665 | cache_int(&cache_hash, g->zig_target->abi); |
| 8666 | 8666 | if (g->zig_target->cache_hash != nullptr) { |
| 8667 | cache_str(&cache_hash, g->zig_target->cache_hash); | |
| 8667 | cache_mem(&cache_hash, g->zig_target->cache_hash, g->zig_target->cache_hash_len); | |
| 8668 | 8668 | } |
| 8669 | 8669 | if (g->zig_target->glibc_or_darwin_version != nullptr) { |
| 8670 | 8670 | cache_int(&cache_hash, g->zig_target->glibc_or_darwin_version->major); |
| ... | ... | @@ -10309,7 +10309,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { |
| 10309 | 10309 | cache_int(ch, g->zig_target->os); |
| 10310 | 10310 | cache_int(ch, g->zig_target->abi); |
| 10311 | 10311 | if (g->zig_target->cache_hash != nullptr) { |
| 10312 | cache_str(ch, g->zig_target->cache_hash); | |
| 10312 | cache_mem(ch, g->zig_target->cache_hash, g->zig_target->cache_hash_len); | |
| 10313 | 10313 | } |
| 10314 | 10314 | if (g->zig_target->glibc_or_darwin_version != nullptr) { |
| 10315 | 10315 | cache_int(ch, g->zig_target->glibc_or_darwin_version->major); |
src/stage2.cpp+3| ... | ... | @@ -251,9 +251,12 @@ Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, cons |
| 251 | 251 | target->cache_hash = "\n\n"; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | target->cache_hash_len = strlen(target->cache_hash); | |
| 255 | ||
| 254 | 256 | if (dynamic_linker != nullptr) { |
| 255 | 257 | target->dynamic_linker = dynamic_linker; |
| 256 | 258 | } |
| 259 | ||
| 257 | 260 | return ErrorNone; |
| 258 | 261 | } |
| 259 | 262 |
src/stage2.h+1| ... | ... | @@ -293,6 +293,7 @@ struct ZigTarget { |
| 293 | 293 | const char *llvm_cpu_features; |
| 294 | 294 | const char *cpu_builtin_str; |
| 295 | 295 | const char *cache_hash; |
| 296 | size_t cache_hash_len; | |
| 296 | 297 | const char *os_builtin_str; |
| 297 | 298 | const char *dynamic_linker; |
| 298 | 299 | }; |