diff options
| author | Luuk de Gram <luuk@degram.dev> | 2022-05-31 19:13:08 +0200 |
|---|---|---|
| committer | Luuk de Gram <luuk@degram.dev> | 2022-06-24 08:12:17 +0200 |
| commit | a6747d328cad831ceb07fb47cd0fa3647da21afb (patch) | |
| tree | 1d91b7a8b7df925681d798177c5c0c5f86799aa2 /src/link | |
| parent | 9015efe4059b7e8448a9c09c3a116cb6b2550957 (diff) | |
| download | zig-a6747d328cad831ceb07fb47cd0fa3647da21afb.tar.gz zig-a6747d328cad831ceb07fb47cd0fa3647da21afb.zip | |
stage2: Enable compiler-rt when LLVM is existant
Rather than checking if the user wants to use LLVM for the current compilation,
check for the existance of LLVM as part of the compiler. This is temporarily,
until other backends gain the ability to compiler LLVM themselves.
This means that when a user passed `-fno-LLVM` we will use the native
backend for the user's code, but use LLVM for compiler-rt.
This also fixes emitting names for symbols in the Wasm linker,
by deduplicating symbol names when multiple symbols point the same object.
Diffstat (limited to 'src/link')
| -rw-r--r-- | src/link/Wasm.zig | 15 | ||||
| -rw-r--r-- | src/link/Wasm/types.zig | 2 |
2 files changed, 13 insertions, 4 deletions
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 6ffba60956..31d06ca881 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -2286,7 +2286,9 @@ fn emitNameSection(self: *Wasm, file: fs.File, arena: Allocator) !void { } }; - var funcs = try std.ArrayList(Name).initCapacity(arena, self.functions.count() + self.imported_functions_count); + // we must de-duplicate symbols that point to the same function + var funcs = std.AutoArrayHashMap(u32, Name).init(arena); + try funcs.ensureUnusedCapacity(self.functions.count() + self.imported_functions_count); var globals = try std.ArrayList(Name).initCapacity(arena, self.wasm_globals.items.len + self.imported_globals_count); var segments = try std.ArrayList(Name).initCapacity(arena, self.data_segments.count()); @@ -2296,7 +2298,12 @@ fn emitNameSection(self: *Wasm, file: fs.File, arena: Allocator) !void { break :blk self.string_table.get(self.imports.get(sym_loc).?.name); } else sym_loc.getName(self); switch (symbol.tag) { - .function => try funcs.append(.{ .index = symbol.index, .name = name }), + .function => { + const gop = funcs.getOrPutAssumeCapacity(symbol.index); + if (!gop.found_existing) { + gop.value_ptr.* = .{ .index = symbol.index, .name = name }; + } + }, .global => globals.appendAssumeCapacity(.{ .index = symbol.index, .name = name }), else => {}, } @@ -2306,7 +2313,7 @@ fn emitNameSection(self: *Wasm, file: fs.File, arena: Allocator) !void { segments.appendAssumeCapacity(.{ .index = @intCast(u32, index), .name = key }); } - std.sort.sort(Name, funcs.items, {}, Name.lessThan); + std.sort.sort(Name, funcs.values(), {}, Name.lessThan); std.sort.sort(Name, globals.items, {}, Name.lessThan); const header_offset = try reserveCustomSectionHeader(file); @@ -2314,7 +2321,7 @@ fn emitNameSection(self: *Wasm, file: fs.File, arena: Allocator) !void { try leb.writeULEB128(writer, @intCast(u32, "name".len)); try writer.writeAll("name"); - try self.emitNameSubsection(.function, funcs.items, writer); + try self.emitNameSubsection(.function, funcs.values(), writer); try self.emitNameSubsection(.global, globals.items, writer); try self.emitNameSubsection(.data_segment, segments.items, writer); diff --git a/src/link/Wasm/types.zig b/src/link/Wasm/types.zig index 2c99f0f003..835c02ea12 100644 --- a/src/link/Wasm/types.zig +++ b/src/link/Wasm/types.zig @@ -192,6 +192,7 @@ pub const Feature = struct { sign_ext, simd128, tail_call, + shared_mem, }; pub const Prefix = enum(u8) { @@ -229,4 +230,5 @@ pub const known_features = std.ComptimeStringMap(Feature.Tag, .{ .{ "sign-ext", .sign_ext }, .{ "simd128", .simd128 }, .{ "tail-call", .tail_call }, + .{ "shared-mem", .shared_mem }, }); |
