| author | |
| committer | |
| log | bfebc11d0633e3f4a3fe86d1a9d6f90ffdb1fbb6 |
| tree | 60e7ad6b44d7e3e4052edab33fdcb25706022ac7 |
| parent | c988167377c92359fed42f12ad32b5f349f9ffb8 |
| signature |
- add Stage2Target.cache_hash_len
- add cache_mem(ch, ptr, len)
- update call sites to use { ptr, len }6 files changed, 17 insertions(+), 5 deletions(-)
src-self-hosted/stage2.zig+4-1| ... | @@ -900,6 +900,7 @@ const Stage2Target = extern struct { | ... | @@ -900,6 +900,7 @@ const Stage2Target = extern struct { |
| 900 | llvm_cpu_features: ?[*:0]const u8, | 900 | llvm_cpu_features: ?[*:0]const u8, |
| 901 | cpu_builtin_str: ?[*:0]const u8, | 901 | cpu_builtin_str: ?[*:0]const u8, |
| 902 | cache_hash: ?[*:0]const u8, | 902 | cache_hash: ?[*:0]const u8, |
| 903 | cache_hash_len: usize, | ||
| 903 | os_builtin_str: ?[*:0]const u8, | 904 | os_builtin_str: ?[*:0]const u8, |
| 904 | 905 | ||
| 905 | dynamic_linker: ?[*:0]const u8, | 906 | dynamic_linker: ?[*:0]const u8, |
| ... | @@ -1129,6 +1130,7 @@ const Stage2Target = extern struct { | ... | @@ -1129,6 +1130,7 @@ const Stage2Target = extern struct { |
| 1129 | } | 1130 | } |
| 1130 | }; | 1131 | }; |
| 1131 | 1132 | ||
| 1133 | const cache_hash_slice = cache_hash.toOwnedSlice(); | ||
| 1132 | self.* = .{ | 1134 | self.* = .{ |
| 1133 | .arch = @enumToInt(target.cpu.arch) + 1, // skip over ZigLLVM_UnknownArch | 1135 | .arch = @enumToInt(target.cpu.arch) + 1, // skip over ZigLLVM_UnknownArch |
| 1134 | .vendor = 0, | 1136 | .vendor = 0, |
| ... | @@ -1138,7 +1140,8 @@ const Stage2Target = extern struct { | ... | @@ -1138,7 +1140,8 @@ const Stage2Target = extern struct { |
| 1138 | .llvm_cpu_features = llvm_features_buffer.toOwnedSlice().ptr, | 1140 | .llvm_cpu_features = llvm_features_buffer.toOwnedSlice().ptr, |
| 1139 | .cpu_builtin_str = cpu_builtin_str_buffer.toOwnedSlice().ptr, | 1141 | .cpu_builtin_str = cpu_builtin_str_buffer.toOwnedSlice().ptr, |
| 1140 | .os_builtin_str = os_builtin_str_buffer.toOwnedSlice().ptr, | 1142 | .os_builtin_str = os_builtin_str_buffer.toOwnedSlice().ptr, |
| 1141 | .cache_hash = cache_hash.toOwnedSlice().ptr, | 1143 | .cache_hash = cache_hash_slice.ptr, |
| 1144 | .cache_hash_len = cache_hash_slice.len, | ||
| 1142 | .is_native = cross_target.isNative(), | 1145 | .is_native = cross_target.isNative(), |
| 1143 | .glibc_or_darwin_version = glibc_or_darwin_version, | 1146 | .glibc_or_darwin_version = glibc_or_darwin_version, |
| 1144 | .dynamic_linker = dynamic_linker, | 1147 | .dynamic_linker = dynamic_linker, |
src/cache_hash.cpp+6-2| ... | @@ -24,11 +24,15 @@ void cache_init(CacheHash *ch, Buf *manifest_dir) { | ... | @@ -24,11 +24,15 @@ void cache_init(CacheHash *ch, Buf *manifest_dir) { |
| 24 | ch->b64_digest = BUF_INIT; | 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 | assert(ch->manifest_file_path == nullptr); | 28 | assert(ch->manifest_file_path == nullptr); |
| 29 | assert(ptr != nullptr); | 29 | assert(ptr != nullptr); |
| 30 | // + 1 to include the null byte | 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 | void cache_int(CacheHash *ch, int x) { | 38 | void cache_int(CacheHash *ch, int x) { |
src/cache_hash.hpp+1| ... | @@ -35,6 +35,7 @@ struct CacheHash { | ... | @@ -35,6 +35,7 @@ struct CacheHash { |
| 35 | void cache_init(CacheHash *ch, Buf *manifest_dir); | 35 | void cache_init(CacheHash *ch, Buf *manifest_dir); |
| 36 | 36 | ||
| 37 | // Next, use the hash population functions to add the initial parameters. | 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 | void cache_str(CacheHash *ch, const char *ptr); | 39 | void cache_str(CacheHash *ch, const char *ptr); |
| 39 | void cache_int(CacheHash *ch, int x); | 40 | void cache_int(CacheHash *ch, int x); |
| 40 | void cache_bool(CacheHash *ch, bool x); | 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,7 +8664,7 @@ static Error define_builtin_compile_vars(CodeGen *g) { |
| 8664 | cache_int(&cache_hash, g->zig_target->os); | 8664 | cache_int(&cache_hash, g->zig_target->os); |
| 8665 | cache_int(&cache_hash, g->zig_target->abi); | 8665 | cache_int(&cache_hash, g->zig_target->abi); |
| 8666 | if (g->zig_target->cache_hash != nullptr) { | 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 | if (g->zig_target->glibc_or_darwin_version != nullptr) { | 8669 | if (g->zig_target->glibc_or_darwin_version != nullptr) { |
| 8670 | cache_int(&cache_hash, g->zig_target->glibc_or_darwin_version->major); | 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,7 +10309,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { |
| 10309 | cache_int(ch, g->zig_target->os); | 10309 | cache_int(ch, g->zig_target->os); |
| 10310 | cache_int(ch, g->zig_target->abi); | 10310 | cache_int(ch, g->zig_target->abi); |
| 10311 | if (g->zig_target->cache_hash != nullptr) { | 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 | if (g->zig_target->glibc_or_darwin_version != nullptr) { | 10314 | if (g->zig_target->glibc_or_darwin_version != nullptr) { |
| 10315 | cache_int(ch, g->zig_target->glibc_or_darwin_version->major); | 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,9 +251,12 @@ Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, cons |
| 251 | target->cache_hash = "\n\n"; | 251 | target->cache_hash = "\n\n"; |
| 252 | } | 252 | } |
| 253 | 253 | ||
| 254 | target->cache_hash_len = strlen(target->cache_hash); | ||
| 255 | |||
| 254 | if (dynamic_linker != nullptr) { | 256 | if (dynamic_linker != nullptr) { |
| 255 | target->dynamic_linker = dynamic_linker; | 257 | target->dynamic_linker = dynamic_linker; |
| 256 | } | 258 | } |
| 259 | |||
| 257 | return ErrorNone; | 260 | return ErrorNone; |
| 258 | } | 261 | } |
| 259 | 262 |
src/stage2.h+1| ... | @@ -293,6 +293,7 @@ struct ZigTarget { | ... | @@ -293,6 +293,7 @@ struct ZigTarget { |
| 293 | const char *llvm_cpu_features; | 293 | const char *llvm_cpu_features; |
| 294 | const char *cpu_builtin_str; | 294 | const char *cpu_builtin_str; |
| 295 | const char *cache_hash; | 295 | const char *cache_hash; |
| 296 | size_t cache_hash_len; | ||
| 296 | const char *os_builtin_str; | 297 | const char *os_builtin_str; |
| 297 | const char *dynamic_linker; | 298 | const char *dynamic_linker; |
| 298 | }; | 299 | }; |