authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-11 21:47:56-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-03-11 21:47:56-04:00
log75e9a722db3335da0e8c254a0e04c5775ebfc160
tree5b7ca9dec716b2b883a224fa25289c32cb556a10
parent3ded862cdf4cec619aea95b595103b72dd23c401
parentbfebc11d0633e3f4a3fe86d1a9d6f90ffdb1fbb6
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #4714 from mikdusan/target

fix -target and -mcpu issues

7 files changed, 59 insertions(+), 58 deletions(-)

lib/std/zig/system.zig+6-15
......@@ -325,22 +325,19 @@ pub const NativeTargetInfo = struct {
325325 // native CPU architecture as being different than the current target), we use this:
326326 const cpu_arch = cross_target.getCpuArch();
327327
328 const cpu = switch (cross_target.cpu_model) {
328 var cpu = switch (cross_target.cpu_model) {
329329 .native => detectNativeCpuAndFeatures(cpu_arch, os, cross_target),
330 .baseline => baselineCpuAndFeatures(cpu_arch, cross_target),
330 .baseline => Target.Cpu.baseline(cpu_arch),
331331 .determined_by_cpu_arch => if (cross_target.cpu_arch == null)
332332 detectNativeCpuAndFeatures(cpu_arch, os, cross_target)
333333 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),
340336 } orelse backup_cpu_detection: {
341337 cpu_detection_unimplemented = true;
342 break :backup_cpu_detection baselineCpuAndFeatures(cpu_arch, cross_target);
338 break :backup_cpu_detection Target.Cpu.baseline(cpu_arch);
343339 };
340 cross_target.updateCpuFeatures(&cpu.features);
344341
345342 var target = try detectAbiAndDynamicLinker(allocator, cpu, os, cross_target);
346343 target.cpu_detection_unimplemented = cpu_detection_unimplemented;
......@@ -884,10 +881,4 @@ pub const NativeTargetInfo = struct {
884881 },
885882 }
886883 }
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 }
893884};
src-self-hosted/stage2.zig+40-39
......@@ -679,44 +679,42 @@ fn stage2TargetParse(
679679 mcpu_oz: ?[*:0]const u8,
680680 dynamic_linker_oz: ?[*:0]const u8,
681681) !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 };
720718
721719 try stage1_target.fromTarget(target);
722720}
......@@ -902,6 +900,7 @@ const Stage2Target = extern struct {
902900 llvm_cpu_features: ?[*:0]const u8,
903901 cpu_builtin_str: ?[*:0]const u8,
904902 cache_hash: ?[*:0]const u8,
903 cache_hash_len: usize,
905904 os_builtin_str: ?[*:0]const u8,
906905
907906 dynamic_linker: ?[*:0]const u8,
......@@ -1131,6 +1130,7 @@ const Stage2Target = extern struct {
11311130 }
11321131 };
11331132
1133 const cache_hash_slice = cache_hash.toOwnedSlice();
11341134 self.* = .{
11351135 .arch = @enumToInt(target.cpu.arch) + 1, // skip over ZigLLVM_UnknownArch
11361136 .vendor = 0,
......@@ -1140,7 +1140,8 @@ const Stage2Target = extern struct {
11401140 .llvm_cpu_features = llvm_features_buffer.toOwnedSlice().ptr,
11411141 .cpu_builtin_str = cpu_builtin_str_buffer.toOwnedSlice().ptr,
11421142 .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,
11441145 .is_native = cross_target.isNative(),
11451146 .glibc_or_darwin_version = glibc_or_darwin_version,
11461147 .dynamic_linker = dynamic_linker,
src/cache_hash.cpp+6-2
......@@ -24,11 +24,15 @@ void cache_init(CacheHash *ch, Buf *manifest_dir) {
2424 ch->b64_digest = BUF_INIT;
2525}
2626
27void cache_str(CacheHash *ch, const char *ptr) {
27void cache_mem(CacheHash *ch, const char *ptr, size_t len) {
2828 assert(ch->manifest_file_path == nullptr);
2929 assert(ptr != nullptr);
3030 // + 1 to include the null byte
31 blake2b_update(&ch->blake, ptr, strlen(ptr) + 1);
31 blake2b_update(&ch->blake, ptr, len);
32}
33
34void cache_str(CacheHash *ch, const char *ptr) {
35 cache_mem(ch, ptr, strlen(ptr) + 1);
3236}
3337
3438void cache_int(CacheHash *ch, int x) {
src/cache_hash.hpp+1
......@@ -35,6 +35,7 @@ struct CacheHash {
3535void cache_init(CacheHash *ch, Buf *manifest_dir);
3636
3737// Next, use the hash population functions to add the initial parameters.
38void cache_mem(CacheHash *ch, const char *ptr, size_t len);
3839void cache_str(CacheHash *ch, const char *ptr);
3940void cache_int(CacheHash *ch, int x);
4041void cache_bool(CacheHash *ch, bool x);
src/codegen.cpp+2-2
......@@ -8664,7 +8664,7 @@ static Error define_builtin_compile_vars(CodeGen *g) {
86648664 cache_int(&cache_hash, g->zig_target->os);
86658665 cache_int(&cache_hash, g->zig_target->abi);
86668666 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);
86688668 }
86698669 if (g->zig_target->glibc_or_darwin_version != nullptr) {
86708670 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) {
1030910309 cache_int(ch, g->zig_target->os);
1031010310 cache_int(ch, g->zig_target->abi);
1031110311 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);
1031310313 }
1031410314 if (g->zig_target->glibc_or_darwin_version != nullptr) {
1031510315 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
251251 target->cache_hash = "\n\n";
252252 }
253253
254 target->cache_hash_len = strlen(target->cache_hash);
255
254256 if (dynamic_linker != nullptr) {
255257 target->dynamic_linker = dynamic_linker;
256258 }
259
257260 return ErrorNone;
258261}
259262
src/stage2.h+1
......@@ -293,6 +293,7 @@ struct ZigTarget {
293293 const char *llvm_cpu_features;
294294 const char *cpu_builtin_str;
295295 const char *cache_hash;
296 size_t cache_hash_len;
296297 const char *os_builtin_str;
297298 const char *dynamic_linker;
298299};