mirror of
https://github.com/ziglang/zig.git
synced 2026-01-01 11:03:11 +00:00
fix zig-cache to treat cpu-features as raw-bytes
- add Stage2Target.cache_hash_len
- add cache_mem(ch, ptr, len)
- update call sites to use { ptr, len }
This commit is contained in:
parent
c988167377
commit
bfebc11d06
@ -900,6 +900,7 @@ const Stage2Target = extern struct {
|
||||
llvm_cpu_features: ?[*:0]const u8,
|
||||
cpu_builtin_str: ?[*:0]const u8,
|
||||
cache_hash: ?[*:0]const u8,
|
||||
cache_hash_len: usize,
|
||||
os_builtin_str: ?[*:0]const u8,
|
||||
|
||||
dynamic_linker: ?[*:0]const u8,
|
||||
@ -1129,6 +1130,7 @@ const Stage2Target = extern struct {
|
||||
}
|
||||
};
|
||||
|
||||
const cache_hash_slice = cache_hash.toOwnedSlice();
|
||||
self.* = .{
|
||||
.arch = @enumToInt(target.cpu.arch) + 1, // skip over ZigLLVM_UnknownArch
|
||||
.vendor = 0,
|
||||
@ -1138,7 +1140,8 @@ const Stage2Target = extern struct {
|
||||
.llvm_cpu_features = llvm_features_buffer.toOwnedSlice().ptr,
|
||||
.cpu_builtin_str = cpu_builtin_str_buffer.toOwnedSlice().ptr,
|
||||
.os_builtin_str = os_builtin_str_buffer.toOwnedSlice().ptr,
|
||||
.cache_hash = cache_hash.toOwnedSlice().ptr,
|
||||
.cache_hash = cache_hash_slice.ptr,
|
||||
.cache_hash_len = cache_hash_slice.len,
|
||||
.is_native = cross_target.isNative(),
|
||||
.glibc_or_darwin_version = glibc_or_darwin_version,
|
||||
.dynamic_linker = dynamic_linker,
|
||||
|
||||
@ -24,11 +24,15 @@ void cache_init(CacheHash *ch, Buf *manifest_dir) {
|
||||
ch->b64_digest = BUF_INIT;
|
||||
}
|
||||
|
||||
void cache_str(CacheHash *ch, const char *ptr) {
|
||||
void cache_mem(CacheHash *ch, const char *ptr, size_t len) {
|
||||
assert(ch->manifest_file_path == nullptr);
|
||||
assert(ptr != nullptr);
|
||||
// + 1 to include the null byte
|
||||
blake2b_update(&ch->blake, ptr, strlen(ptr) + 1);
|
||||
blake2b_update(&ch->blake, ptr, len);
|
||||
}
|
||||
|
||||
void cache_str(CacheHash *ch, const char *ptr) {
|
||||
cache_mem(ch, ptr, strlen(ptr) + 1);
|
||||
}
|
||||
|
||||
void cache_int(CacheHash *ch, int x) {
|
||||
|
||||
@ -35,6 +35,7 @@ struct CacheHash {
|
||||
void cache_init(CacheHash *ch, Buf *manifest_dir);
|
||||
|
||||
// Next, use the hash population functions to add the initial parameters.
|
||||
void cache_mem(CacheHash *ch, const char *ptr, size_t len);
|
||||
void cache_str(CacheHash *ch, const char *ptr);
|
||||
void cache_int(CacheHash *ch, int x);
|
||||
void cache_bool(CacheHash *ch, bool x);
|
||||
|
||||
@ -8664,7 +8664,7 @@ static Error define_builtin_compile_vars(CodeGen *g) {
|
||||
cache_int(&cache_hash, g->zig_target->os);
|
||||
cache_int(&cache_hash, g->zig_target->abi);
|
||||
if (g->zig_target->cache_hash != nullptr) {
|
||||
cache_str(&cache_hash, g->zig_target->cache_hash);
|
||||
cache_mem(&cache_hash, g->zig_target->cache_hash, g->zig_target->cache_hash_len);
|
||||
}
|
||||
if (g->zig_target->glibc_or_darwin_version != nullptr) {
|
||||
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) {
|
||||
cache_int(ch, g->zig_target->os);
|
||||
cache_int(ch, g->zig_target->abi);
|
||||
if (g->zig_target->cache_hash != nullptr) {
|
||||
cache_str(ch, g->zig_target->cache_hash);
|
||||
cache_mem(ch, g->zig_target->cache_hash, g->zig_target->cache_hash_len);
|
||||
}
|
||||
if (g->zig_target->glibc_or_darwin_version != nullptr) {
|
||||
cache_int(ch, g->zig_target->glibc_or_darwin_version->major);
|
||||
|
||||
@ -251,9 +251,12 @@ Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, cons
|
||||
target->cache_hash = "\n\n";
|
||||
}
|
||||
|
||||
target->cache_hash_len = strlen(target->cache_hash);
|
||||
|
||||
if (dynamic_linker != nullptr) {
|
||||
target->dynamic_linker = dynamic_linker;
|
||||
}
|
||||
|
||||
return ErrorNone;
|
||||
}
|
||||
|
||||
|
||||
@ -293,6 +293,7 @@ struct ZigTarget {
|
||||
const char *llvm_cpu_features;
|
||||
const char *cpu_builtin_str;
|
||||
const char *cache_hash;
|
||||
size_t cache_hash_len;
|
||||
const char *os_builtin_str;
|
||||
const char *dynamic_linker;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user