authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-15 20:28:51-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 17:51:20-07:00
log48d5861f9256dfd1c5357dd6f2a023e700de16e4
tree72534a37dff36062ba16fc86be90997d3f16ef22
parent638db680f4c6380bb193da520f29a7c587bfb719

fix more compilation errors introduced by this branch


14 files changed, 113 insertions(+), 85 deletions(-)

src/Compilation.zig+36-8
...@@ -893,6 +893,12 @@ const CacheUse = union(CacheMode) {...@@ -893,6 +893,12 @@ const CacheUse = union(CacheMode) {
893 whole.lock = null;893 whole.lock = null;
894 }894 }
895 }895 }
896
897 fn moveLock(whole: *Whole) Cache.Lock {
898 const result = whole.lock.?;
899 whole.lock = null;
900 return result;
901 }
896 };902 };
897903
898 const Incremental = struct {904 const Incremental = struct {
...@@ -939,7 +945,9 @@ pub const InitOptions = struct {...@@ -939,7 +945,9 @@ pub const InitOptions = struct {
939 main_mod: ?*Package.Module = null,945 main_mod: ?*Package.Module = null,
940 /// This is provided so that the API user has a chance to tweak the946 /// This is provided so that the API user has a chance to tweak the
941 /// per-module settings of the standard library.947 /// per-module settings of the standard library.
942 std_mod: *Package.Module,948 /// When this is null, a default configuration of the std lib is created
949 /// based on the settings of root_mod.
950 std_mod: ?*Package.Module = null,
943 root_name: []const u8,951 root_name: []const u8,
944 sysroot: ?[]const u8 = null,952 sysroot: ?[]const u8 = null,
945 /// `null` means to not emit a binary file.953 /// `null` means to not emit a binary file.
...@@ -1381,13 +1389,30 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1381,13 +1389,30 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1381 break :eh eh;1389 break :eh eh;
1382 } else null;1390 } else null;
13831391
1392 const std_mod = options.std_mod orelse try Package.Module.create(arena, .{
1393 .global_cache_directory = options.global_cache_directory,
1394 .paths = .{
1395 .root = .{
1396 .root_dir = options.zig_lib_directory,
1397 .sub_path = "std",
1398 },
1399 .root_src_path = "std.zig",
1400 },
1401 .fully_qualified_name = "std",
1402 .cc_argv = &.{},
1403 .inherited = .{},
1404 .global = options.config,
1405 .parent = options.root_mod,
1406 .builtin_mod = options.root_mod.deps.get("builtin").?,
1407 });
1408
1384 const zcu = try arena.create(Module);1409 const zcu = try arena.create(Module);
1385 zcu.* = .{1410 zcu.* = .{
1386 .gpa = gpa,1411 .gpa = gpa,
1387 .comp = comp,1412 .comp = comp,
1388 .main_mod = options.main_mod orelse options.root_mod,1413 .main_mod = options.main_mod orelse options.root_mod,
1389 .root_mod = options.root_mod,1414 .root_mod = options.root_mod,
1390 .std_mod = options.std_mod,1415 .std_mod = std_mod,
1391 .global_zir_cache = global_zir_cache,1416 .global_zir_cache = global_zir_cache,
1392 .local_zir_cache = local_zir_cache,1417 .local_zir_cache = local_zir_cache,
1393 .emit_h = emit_h,1418 .emit_h = emit_h,
...@@ -6215,7 +6240,7 @@ fn buildOutputFromZig(...@@ -6215,7 +6240,7 @@ fn buildOutputFromZig(
6215 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(gpa, &.{6240 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(gpa, &.{
6216 sub_compilation.bin_file.?.emit.sub_path,6241 sub_compilation.bin_file.?.emit.sub_path,
6217 }),6242 }),
6218 .lock = sub_compilation.bin_file.toOwnedLock(),6243 .lock = sub_compilation.bin_file.?.toOwnedLock(),
6219 };6244 };
6220}6245}
62216246
...@@ -6317,13 +6342,16 @@ pub fn build_crt_file(...@@ -6317,13 +6342,16 @@ pub fn build_crt_file(
6317 try comp.updateSubCompilation(sub_compilation, misc_task_tag, prog_node);6342 try comp.updateSubCompilation(sub_compilation, misc_task_tag, prog_node);
63186343
6319 try comp.crt_files.ensureUnusedCapacity(gpa, 1);6344 try comp.crt_files.ensureUnusedCapacity(gpa, 1);
6345 comp.crt_files.putAssumeCapacityNoClobber(basename, try sub_compilation.toCrtFile());
6346}
63206347
6321 comp.crt_files.putAssumeCapacityNoClobber(basename, .{6348pub fn toCrtFile(comp: *Compilation) Allocator.Error!CRTFile {
6322 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(gpa, &.{6349 return .{
6323 sub_compilation.bin_file.?.emit.sub_path,6350 .full_object_path = try comp.local_cache_directory.join(comp.gpa, &.{
6351 comp.cache_use.whole.bin_sub_path.?,
6324 }),6352 }),
6325 .lock = sub_compilation.bin_file.toOwnedLock(),6353 .lock = comp.cache_use.whole.moveLock(),
6326 });6354 };
6327}6355}
63286356
6329pub fn addLinkLib(comp: *Compilation, lib_name: []const u8) !void {6357pub fn addLinkLib(comp: *Compilation, lib_name: []const u8) !void {
src/arch/aarch64/CodeGen.zig+1-1
...@@ -6332,7 +6332,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6332,7 +6332,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
63326332
6333/// TODO support scope overrides. Also note this logic is duplicated with `Module.wantSafety`.6333/// TODO support scope overrides. Also note this logic is duplicated with `Module.wantSafety`.
6334fn wantSafety(self: *Self) bool {6334fn wantSafety(self: *Self) bool {
6335 return switch (self.bin_file.options.optimize_mode) {6335 return switch (self.bin_file.comp.root_mod.optimize_mode) {
6336 .Debug => true,6336 .Debug => true,
6337 .ReleaseSafe => true,6337 .ReleaseSafe => true,
6338 .ReleaseFast => false,6338 .ReleaseFast => false,
src/arch/arm/CodeGen.zig+1-1
...@@ -6281,7 +6281,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6281,7 +6281,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62816281
6282/// TODO support scope overrides. Also note this logic is duplicated with `Module.wantSafety`.6282/// TODO support scope overrides. Also note this logic is duplicated with `Module.wantSafety`.
6283fn wantSafety(self: *Self) bool {6283fn wantSafety(self: *Self) bool {
6284 return switch (self.bin_file.options.optimize_mode) {6284 return switch (self.bin_file.comp.root_mod.optimize_mode) {
6285 .Debug => true,6285 .Debug => true,
6286 .ReleaseSafe => true,6286 .ReleaseSafe => true,
6287 .ReleaseFast => false,6287 .ReleaseFast => false,
src/arch/riscv64/CodeGen.zig+1-1
...@@ -2708,7 +2708,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -2708,7 +2708,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
27082708
2709/// TODO support scope overrides. Also note this logic is duplicated with `Module.wantSafety`.2709/// TODO support scope overrides. Also note this logic is duplicated with `Module.wantSafety`.
2710fn wantSafety(self: *Self) bool {2710fn wantSafety(self: *Self) bool {
2711 return switch (self.bin_file.options.optimize_mode) {2711 return switch (self.bin_file.comp.root_mod.optimize_mode) {
2712 .Debug => true,2712 .Debug => true,
2713 .ReleaseSafe => true,2713 .ReleaseSafe => true,
2714 .ReleaseFast => false,2714 .ReleaseFast => false,
src/arch/sparc64/CodeGen.zig+1-1
...@@ -4857,7 +4857,7 @@ fn truncRegister(...@@ -4857,7 +4857,7 @@ fn truncRegister(
48574857
4858/// TODO support scope overrides. Also note this logic is duplicated with `Module.wantSafety`.4858/// TODO support scope overrides. Also note this logic is duplicated with `Module.wantSafety`.
4859fn wantSafety(self: *Self) bool {4859fn wantSafety(self: *Self) bool {
4860 return switch (self.bin_file.options.optimize_mode) {4860 return switch (self.bin_file.comp.root_mod.optimize_mode) {
4861 .Debug => true,4861 .Debug => true,
4862 .ReleaseSafe => true,4862 .ReleaseSafe => true,
4863 .ReleaseFast => false,4863 .ReleaseFast => false,
src/arch/x86_64/CodeGen.zig+6-3
...@@ -25,7 +25,9 @@ const Emit = @import("Emit.zig");...@@ -25,7 +25,9 @@ const Emit = @import("Emit.zig");
25const Liveness = @import("../../Liveness.zig");25const Liveness = @import("../../Liveness.zig");
26const Lower = @import("Lower.zig");26const Lower = @import("Lower.zig");
27const Mir = @import("Mir.zig");27const Mir = @import("Mir.zig");
28const Package = @import("../../Package.zig");
28const Module = @import("../../Module.zig");29const Module = @import("../../Module.zig");
30const Zcu = Module;
29const InternPool = @import("../../InternPool.zig");31const InternPool = @import("../../InternPool.zig");
30const Alignment = InternPool.Alignment;32const Alignment = InternPool.Alignment;
31const Target = std.Target;33const Target = std.Target;
...@@ -56,6 +58,7 @@ bin_file: *link.File,...@@ -56,6 +58,7 @@ bin_file: *link.File,
56debug_output: DebugInfoOutput,58debug_output: DebugInfoOutput,
57target: *const std.Target,59target: *const std.Target,
58owner: Owner,60owner: Owner,
61mod: *Package.Module,
59err_msg: ?*ErrorMsg,62err_msg: ?*ErrorMsg,
60args: []MCValue,63args: []MCValue,
61va_info: union {64va_info: union {
...@@ -10906,7 +10909,7 @@ fn genCall(self: *Self, info: union(enum) {...@@ -10906,7 +10909,7 @@ fn genCall(self: *Self, info: union(enum) {
10906 if (self.bin_file.cast(link.File.Elf)) |elf_file| {10909 if (self.bin_file.cast(link.File.Elf)) |elf_file| {
10907 const sym_index = try elf_file.zigObjectPtr().?.getOrCreateMetadataForDecl(elf_file, func.owner_decl);10910 const sym_index = try elf_file.zigObjectPtr().?.getOrCreateMetadataForDecl(elf_file, func.owner_decl);
10908 const sym = elf_file.symbol(sym_index);10911 const sym = elf_file.symbol(sym_index);
10909 if (self.bin_file.options.pic) {10912 if (self.mod.pic) {
10910 const callee_reg: Register = switch (resolved_cc) {10913 const callee_reg: Register = switch (resolved_cc) {
10911 .SysV => callee: {10914 .SysV => callee: {
10912 if (!fn_info.is_var_args) break :callee .rax;10915 if (!fn_info.is_var_args) break :callee .rax;
...@@ -13819,7 +13822,7 @@ fn genLazySymbolRef(...@@ -13819,7 +13822,7 @@ fn genLazySymbolRef(
13819 const sym_index = elf_file.zigObjectPtr().?.getOrCreateMetadataForLazySymbol(elf_file, lazy_sym) catch |err|13822 const sym_index = elf_file.zigObjectPtr().?.getOrCreateMetadataForLazySymbol(elf_file, lazy_sym) catch |err|
13820 return self.fail("{s} creating lazy symbol", .{@errorName(err)});13823 return self.fail("{s} creating lazy symbol", .{@errorName(err)});
13821 const sym = elf_file.symbol(sym_index);13824 const sym = elf_file.symbol(sym_index);
13822 if (self.bin_file.options.pic) {13825 if (self.mod.pic) {
13823 switch (tag) {13826 switch (tag) {
13824 .lea, .call => try self.genSetReg(reg, Type.usize, .{13827 .lea, .call => try self.genSetReg(reg, Type.usize, .{
13825 .load_symbol = .{ .sym = sym.esym_index },13828 .load_symbol = .{ .sym = sym.esym_index },
...@@ -16062,7 +16065,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {...@@ -16062,7 +16065,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
16062 const const_mcv = try self.genTypedValue(.{ .ty = ty, .val = Value.fromInterned(ip_index) });16065 const const_mcv = try self.genTypedValue(.{ .ty = ty, .val = Value.fromInterned(ip_index) });
16063 switch (const_mcv) {16066 switch (const_mcv) {
16064 .lea_tlv => |tlv_sym| if (self.bin_file.cast(link.File.Elf)) |_| {16067 .lea_tlv => |tlv_sym| if (self.bin_file.cast(link.File.Elf)) |_| {
16065 if (self.bin_file.options.pic) {16068 if (self.mod.pic) {
16066 try self.spillRegisters(&.{ .rdi, .rax });16069 try self.spillRegisters(&.{ .rdi, .rax });
16067 } else {16070 } else {
16068 try self.spillRegisters(&.{.rax});16071 try self.spillRegisters(&.{.rax});
src/arch/x86_64/Emit.zig+3-3
...@@ -103,10 +103,10 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -103,10 +103,10 @@ pub fn emitMir(emit: *Emit) Error!void {
103 });103 });
104 },104 },
105 .linker_reloc => |data| if (emit.lower.bin_file.cast(link.File.Elf)) |elf_file| {105 .linker_reloc => |data| if (emit.lower.bin_file.cast(link.File.Elf)) |elf_file| {
106 const is_obj_or_static_lib = switch (emit.lower.bin_file.options.output_mode) {106 const is_obj_or_static_lib = switch (emit.lower.output_mode) {
107 .Exe => false,107 .Exe => false,
108 .Obj => true,108 .Obj => true,
109 .Lib => emit.lower.bin_file.options.link_mode == .Static,109 .Lib => emit.lower.link_mode == .Static,
110 };110 };
111 const atom = elf_file.symbol(data.atom_index).atom(elf_file).?;111 const atom = elf_file.symbol(data.atom_index).atom(elf_file).?;
112 const sym_index = elf_file.zigObjectPtr().?.symbol(data.sym_index);112 const sym_index = elf_file.zigObjectPtr().?.symbol(data.sym_index);
...@@ -114,7 +114,7 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -114,7 +114,7 @@ pub fn emitMir(emit: *Emit) Error!void {
114 if (sym.flags.needs_zig_got and !is_obj_or_static_lib) {114 if (sym.flags.needs_zig_got and !is_obj_or_static_lib) {
115 _ = try sym.getOrCreateZigGotEntry(sym_index, elf_file);115 _ = try sym.getOrCreateZigGotEntry(sym_index, elf_file);
116 }116 }
117 if (emit.lower.bin_file.options.pic) {117 if (emit.lower.pic) {
118 const r_type: u32 = if (sym.flags.needs_zig_got and !is_obj_or_static_lib)118 const r_type: u32 = if (sym.flags.needs_zig_got and !is_obj_or_static_lib)
119 link.File.Elf.R_X86_64_ZIG_GOTPCREL119 link.File.Elf.R_X86_64_ZIG_GOTPCREL
120 else if (sym.flags.needs_got)120 else if (sym.flags.needs_got)
src/arch/x86_64/Lower.zig+7-4
...@@ -1,6 +1,9 @@...@@ -1,6 +1,9 @@
1//! This file contains the functionality for lowering x86_64 MIR to Instructions1//! This file contains the functionality for lowering x86_64 MIR to Instructions
22
3bin_file: *link.File,3bin_file: *link.File,
4output_mode: std.builtin.OutputMode,
5link_mode: std.builtin.LinkMode,
6pic: bool,
4allocator: Allocator,7allocator: Allocator,
5mir: Mir,8mir: Mir,
6cc: std.builtin.CallingConvention,9cc: std.builtin.CallingConvention,
...@@ -336,10 +339,10 @@ fn isTls(sym: bits.Symbol, ctx: *link.File) bool {...@@ -336,10 +339,10 @@ fn isTls(sym: bits.Symbol, ctx: *link.File) bool {
336}339}
337340
338fn emit(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operand) Error!void {341fn emit(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operand) Error!void {
339 const is_obj_or_static_lib = switch (lower.bin_file.options.output_mode) {342 const is_obj_or_static_lib = switch (lower.output_mode) {
340 .Exe => false,343 .Exe => false,
341 .Obj => true,344 .Obj => true,
342 .Lib => lower.bin_file.options.link_mode == .Static,345 .Lib => lower.link_mode == .Static,
343 };346 };
344347
345 const emit_prefix = prefix;348 const emit_prefix = prefix;
...@@ -358,7 +361,7 @@ fn emit(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operand)...@@ -358,7 +361,7 @@ fn emit(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operand)
358361
359 if (isTls(sym, lower.bin_file)) {362 if (isTls(sym, lower.bin_file)) {
360 // TODO handle extern TLS vars, i.e., emit GD model363 // TODO handle extern TLS vars, i.e., emit GD model
361 if (lower.bin_file.options.pic) {364 if (lower.pic) {
362 // Here, we currently assume local dynamic TLS vars, and so365 // Here, we currently assume local dynamic TLS vars, and so
363 // we emit LD model.366 // we emit LD model.
364 _ = lower.reloc(.{ .linker_tlsld = sym });367 _ = lower.reloc(.{ .linker_tlsld = sym });
...@@ -403,7 +406,7 @@ fn emit(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operand)...@@ -403,7 +406,7 @@ fn emit(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operand)
403 }406 }
404407
405 _ = lower.reloc(.{ .linker_reloc = sym });408 _ = lower.reloc(.{ .linker_reloc = sym });
406 break :op if (lower.bin_file.options.pic) switch (mnemonic) {409 break :op if (lower.pic) switch (mnemonic) {
407 .lea => {410 .lea => {
408 break :op .{ .mem = Memory.rip(mem_op.sib.ptr_size, 0) };411 break :op .{ .mem = Memory.rip(mem_op.sib.ptr_size, 0) };
409 },412 },
src/libcxx.zig+2-12
...@@ -299,12 +299,7 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -299,12 +299,7 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {
299 try comp.updateSubCompilation(sub_compilation, .libcxx, prog_node);299 try comp.updateSubCompilation(sub_compilation, .libcxx, prog_node);
300300
301 assert(comp.libcxx_static_lib == null);301 assert(comp.libcxx_static_lib == null);
302 comp.libcxx_static_lib = Compilation.CRTFile{302 comp.libcxx_static_lib = try sub_compilation.toCrtFile();
303 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(comp.gpa, &.{
304 sub_compilation.bin_file.?.emit.sub_path,
305 }),
306 .lock = sub_compilation.bin_file.toOwnedLock(),
307 };
308}303}
309304
310pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {305pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {
...@@ -489,10 +484,5 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -489,10 +484,5 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {
489 try comp.updateSubCompilation(sub_compilation, .libcxxabi, prog_node);484 try comp.updateSubCompilation(sub_compilation, .libcxxabi, prog_node);
490485
491 assert(comp.libcxxabi_static_lib == null);486 assert(comp.libcxxabi_static_lib == null);
492 comp.libcxxabi_static_lib = Compilation.CRTFile{487 comp.libcxxabi_static_lib = try sub_compilation.toCrtFile();
493 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(comp.gpa, &[_][]const u8{
494 sub_compilation.bin_file.?.emit.sub_path,
495 }),
496 .lock = sub_compilation.bin_file.toOwnedLock(),
497 };
498}488}
src/libtsan.zig+1-6
...@@ -268,12 +268,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -268,12 +268,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
268 try comp.updateSubCompilation(sub_compilation, .libtsan, prog_node);268 try comp.updateSubCompilation(sub_compilation, .libtsan, prog_node);
269269
270 assert(comp.tsan_static_lib == null);270 assert(comp.tsan_static_lib == null);
271 comp.tsan_static_lib = Compilation.CRTFile{271 comp.tsan_static_lib = try sub_compilation.toCrtFile();
272 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(comp.gpa, &[_][]const u8{
273 sub_compilation.bin_file.?.emit.sub_path,
274 }),
275 .lock = sub_compilation.bin_file.toOwnedLock(),
276 };
277}272}
278273
279const tsan_sources = [_][]const u8{274const tsan_sources = [_][]const u8{
src/libunwind.zig+1-6
...@@ -151,12 +151,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -151,12 +151,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: *std.Progress.Node) !void {
151151
152 assert(comp.libunwind_static_lib == null);152 assert(comp.libunwind_static_lib == null);
153153
154 comp.libunwind_static_lib = Compilation.CRTFile{154 comp.libunwind_static_lib = try sub_compilation.toOwnedLock();
155 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(comp.gpa, &[_][]const u8{
156 sub_compilation.bin_file.?.emit.sub_path,
157 }),
158 .lock = sub_compilation.bin_file.toOwnedLock(),
159 };
160}155}
161156
162const unwind_src_list = [_][]const u8{157const unwind_src_list = [_][]const u8{
src/link/Elf/synthetic_sections.zig+52-21
...@@ -8,14 +8,16 @@ pub const DynamicSection = struct {...@@ -8,14 +8,16 @@ pub const DynamicSection = struct {
8 }8 }
99
10 pub fn addNeeded(dt: *DynamicSection, shared: *SharedObject, elf_file: *Elf) !void {10 pub fn addNeeded(dt: *DynamicSection, shared: *SharedObject, elf_file: *Elf) !void {
11 const gpa = elf_file.base.allocator;11 const comp = elf_file.base.comp;
12 const gpa = comp.gpa;
12 const off = try elf_file.insertDynString(shared.soname());13 const off = try elf_file.insertDynString(shared.soname());
13 try dt.needed.append(gpa, off);14 try dt.needed.append(gpa, off);
14 }15 }
1516
16 pub fn setRpath(dt: *DynamicSection, rpath_list: []const []const u8, elf_file: *Elf) !void {17 pub fn setRpath(dt: *DynamicSection, rpath_list: []const []const u8, elf_file: *Elf) !void {
17 if (rpath_list.len == 0) return;18 if (rpath_list.len == 0) return;
18 const gpa = elf_file.base.allocator;19 const comp = elf_file.base.comp;
20 const gpa = comp.gpa;
19 var rpath = std.ArrayList(u8).init(gpa);21 var rpath = std.ArrayList(u8).init(gpa);
20 defer rpath.deinit();22 defer rpath.deinit();
21 for (rpath_list, 0..) |path, i| {23 for (rpath_list, 0..) |path, i| {
...@@ -248,7 +250,8 @@ pub const ZigGotSection = struct {...@@ -248,7 +250,8 @@ pub const ZigGotSection = struct {
248250
249 pub fn addSymbol(zig_got: *ZigGotSection, sym_index: Symbol.Index, elf_file: *Elf) !Index {251 pub fn addSymbol(zig_got: *ZigGotSection, sym_index: Symbol.Index, elf_file: *Elf) !Index {
250 const comp = elf_file.base.comp;252 const comp = elf_file.base.comp;
251 const index = try zig_got.allocateEntry(elf_file.base.allocator);253 const gpa = comp.gpa;
254 const index = try zig_got.allocateEntry(gpa);
252 const entry = &zig_got.entries.items[index];255 const entry = &zig_got.entries.items[index];
253 entry.* = sym_index;256 entry.* = sym_index;
254 const symbol = elf_file.symbol(sym_index);257 const symbol = elf_file.symbol(sym_index);
...@@ -349,7 +352,9 @@ pub const ZigGotSection = struct {...@@ -349,7 +352,9 @@ pub const ZigGotSection = struct {
349 }352 }
350353
351 pub fn addRela(zig_got: ZigGotSection, elf_file: *Elf) !void {354 pub fn addRela(zig_got: ZigGotSection, elf_file: *Elf) !void {
352 try elf_file.rela_dyn.ensureUnusedCapacity(elf_file.base.allocator, zig_got.numRela());355 const comp = elf_file.base.comp;
356 const gpa = comp.gpa;
357 try elf_file.rela_dyn.ensureUnusedCapacity(gpa, zig_got.numRela());
353 for (zig_got.entries.items) |entry| {358 for (zig_got.entries.items) |entry| {
354 const symbol = elf_file.symbol(entry);359 const symbol = elf_file.symbol(entry);
355 const offset = symbol.zigGotAddress(elf_file);360 const offset = symbol.zigGotAddress(elf_file);
...@@ -481,7 +486,8 @@ pub const GotSection = struct {...@@ -481,7 +486,8 @@ pub const GotSection = struct {
481486
482 pub fn addGotSymbol(got: *GotSection, sym_index: Symbol.Index, elf_file: *Elf) !Index {487 pub fn addGotSymbol(got: *GotSection, sym_index: Symbol.Index, elf_file: *Elf) !Index {
483 const comp = elf_file.base.comp;488 const comp = elf_file.base.comp;
484 const index = try got.allocateEntry(elf_file.base.allocator);489 const gpa = comp.gpa;
490 const index = try got.allocateEntry(gpa);
485 const entry = &got.entries.items[index];491 const entry = &got.entries.items[index];
486 entry.tag = .got;492 entry.tag = .got;
487 entry.symbol_index = sym_index;493 entry.symbol_index = sym_index;
...@@ -501,8 +507,10 @@ pub const GotSection = struct {...@@ -501,8 +507,10 @@ pub const GotSection = struct {
501 }507 }
502508
503 pub fn addTlsLdSymbol(got: *GotSection, elf_file: *Elf) !void {509 pub fn addTlsLdSymbol(got: *GotSection, elf_file: *Elf) !void {
510 const comp = elf_file.base.comp;
511 const gpa = comp.gpa;
504 assert(got.flags.needs_tlsld);512 assert(got.flags.needs_tlsld);
505 const index = try got.allocateEntry(elf_file.base.allocator);513 const index = try got.allocateEntry(gpa);
506 const entry = &got.entries.items[index];514 const entry = &got.entries.items[index];
507 entry.tag = .tlsld;515 entry.tag = .tlsld;
508 entry.symbol_index = undefined; // unused516 entry.symbol_index = undefined; // unused
...@@ -511,7 +519,9 @@ pub const GotSection = struct {...@@ -511,7 +519,9 @@ pub const GotSection = struct {
511 }519 }
512520
513 pub fn addTlsGdSymbol(got: *GotSection, sym_index: Symbol.Index, elf_file: *Elf) !void {521 pub fn addTlsGdSymbol(got: *GotSection, sym_index: Symbol.Index, elf_file: *Elf) !void {
514 const index = try got.allocateEntry(elf_file.base.allocator);522 const comp = elf_file.base.comp;
523 const gpa = comp.gpa;
524 const index = try got.allocateEntry(gpa);
515 const entry = &got.entries.items[index];525 const entry = &got.entries.items[index];
516 entry.tag = .tlsgd;526 entry.tag = .tlsgd;
517 entry.symbol_index = sym_index;527 entry.symbol_index = sym_index;
...@@ -526,7 +536,9 @@ pub const GotSection = struct {...@@ -526,7 +536,9 @@ pub const GotSection = struct {
526 }536 }
527537
528 pub fn addGotTpSymbol(got: *GotSection, sym_index: Symbol.Index, elf_file: *Elf) !void {538 pub fn addGotTpSymbol(got: *GotSection, sym_index: Symbol.Index, elf_file: *Elf) !void {
529 const index = try got.allocateEntry(elf_file.base.allocator);539 const comp = elf_file.base.comp;
540 const gpa = comp.gpa;
541 const index = try got.allocateEntry(gpa);
530 const entry = &got.entries.items[index];542 const entry = &got.entries.items[index];
531 entry.tag = .gottp;543 entry.tag = .gottp;
532 entry.symbol_index = sym_index;544 entry.symbol_index = sym_index;
...@@ -541,7 +553,9 @@ pub const GotSection = struct {...@@ -541,7 +553,9 @@ pub const GotSection = struct {
541 }553 }
542554
543 pub fn addTlsDescSymbol(got: *GotSection, sym_index: Symbol.Index, elf_file: *Elf) !void {555 pub fn addTlsDescSymbol(got: *GotSection, sym_index: Symbol.Index, elf_file: *Elf) !void {
544 const index = try got.allocateEntry(elf_file.base.allocator);556 const comp = elf_file.base.comp;
557 const gpa = comp.gpa;
558 const index = try got.allocateEntry(gpa);
545 const entry = &got.entries.items[index];559 const entry = &got.entries.items[index];
546 entry.tag = .tlsdesc;560 entry.tag = .tlsdesc;
547 entry.symbol_index = sym_index;561 entry.symbol_index = sym_index;
...@@ -628,8 +642,9 @@ pub const GotSection = struct {...@@ -628,8 +642,9 @@ pub const GotSection = struct {
628642
629 pub fn addRela(got: GotSection, elf_file: *Elf) !void {643 pub fn addRela(got: GotSection, elf_file: *Elf) !void {
630 const comp = elf_file.base.comp;644 const comp = elf_file.base.comp;
645 const gpa = comp.gpa;
631 const is_dyn_lib = elf_file.isDynLib();646 const is_dyn_lib = elf_file.isDynLib();
632 try elf_file.rela_dyn.ensureUnusedCapacity(elf_file.base.allocator, got.numRela(elf_file));647 try elf_file.rela_dyn.ensureUnusedCapacity(gpa, got.numRela(elf_file));
633648
634 for (got.entries.items) |entry| {649 for (got.entries.items) |entry| {
635 const symbol = switch (entry.tag) {650 const symbol = switch (entry.tag) {
...@@ -847,6 +862,8 @@ pub const PltSection = struct {...@@ -847,6 +862,8 @@ pub const PltSection = struct {
847 }862 }
848863
849 pub fn addSymbol(plt: *PltSection, sym_index: Symbol.Index, elf_file: *Elf) !void {864 pub fn addSymbol(plt: *PltSection, sym_index: Symbol.Index, elf_file: *Elf) !void {
865 const comp = elf_file.base.comp;
866 const gpa = comp.gpa;
850 const index = @as(u32, @intCast(plt.symbols.items.len));867 const index = @as(u32, @intCast(plt.symbols.items.len));
851 const symbol = elf_file.symbol(sym_index);868 const symbol = elf_file.symbol(sym_index);
852 symbol.flags.has_plt = true;869 symbol.flags.has_plt = true;
...@@ -855,7 +872,7 @@ pub const PltSection = struct {...@@ -855,7 +872,7 @@ pub const PltSection = struct {
855 new_extra.plt = index;872 new_extra.plt = index;
856 symbol.setExtra(new_extra, elf_file);873 symbol.setExtra(new_extra, elf_file);
857 } else try symbol.addExtra(.{ .plt = index }, elf_file);874 } else try symbol.addExtra(.{ .plt = index }, elf_file);
858 try plt.symbols.append(elf_file.base.allocator, sym_index);875 try plt.symbols.append(gpa, sym_index);
859 }876 }
860877
861 pub fn size(plt: PltSection) usize {878 pub fn size(plt: PltSection) usize {
...@@ -895,7 +912,9 @@ pub const PltSection = struct {...@@ -895,7 +912,9 @@ pub const PltSection = struct {
895 }912 }
896913
897 pub fn addRela(plt: PltSection, elf_file: *Elf) !void {914 pub fn addRela(plt: PltSection, elf_file: *Elf) !void {
898 try elf_file.rela_plt.ensureUnusedCapacity(elf_file.base.allocator, plt.numRela());915 const comp = elf_file.base.comp;
916 const gpa = comp.gpa;
917 try elf_file.rela_plt.ensureUnusedCapacity(gpa, plt.numRela());
899 for (plt.symbols.items) |sym_index| {918 for (plt.symbols.items) |sym_index| {
900 const sym = elf_file.symbol(sym_index);919 const sym = elf_file.symbol(sym_index);
901 assert(sym.flags.import);920 assert(sym.flags.import);
...@@ -1010,6 +1029,8 @@ pub const PltGotSection = struct {...@@ -1010,6 +1029,8 @@ pub const PltGotSection = struct {
1010 }1029 }
10111030
1012 pub fn addSymbol(plt_got: *PltGotSection, sym_index: Symbol.Index, elf_file: *Elf) !void {1031 pub fn addSymbol(plt_got: *PltGotSection, sym_index: Symbol.Index, elf_file: *Elf) !void {
1032 const comp = elf_file.base.comp;
1033 const gpa = comp.gpa;
1013 const index = @as(u32, @intCast(plt_got.symbols.items.len));1034 const index = @as(u32, @intCast(plt_got.symbols.items.len));
1014 const symbol = elf_file.symbol(sym_index);1035 const symbol = elf_file.symbol(sym_index);
1015 symbol.flags.has_plt = true;1036 symbol.flags.has_plt = true;
...@@ -1019,7 +1040,7 @@ pub const PltGotSection = struct {...@@ -1019,7 +1040,7 @@ pub const PltGotSection = struct {
1019 new_extra.plt_got = index;1040 new_extra.plt_got = index;
1020 symbol.setExtra(new_extra, elf_file);1041 symbol.setExtra(new_extra, elf_file);
1021 } else try symbol.addExtra(.{ .plt_got = index }, elf_file);1042 } else try symbol.addExtra(.{ .plt_got = index }, elf_file);
1022 try plt_got.symbols.append(elf_file.base.allocator, sym_index);1043 try plt_got.symbols.append(gpa, sym_index);
1023 }1044 }
10241045
1025 pub fn size(plt_got: PltGotSection) usize {1046 pub fn size(plt_got: PltGotSection) usize {
...@@ -1077,6 +1098,8 @@ pub const CopyRelSection = struct {...@@ -1077,6 +1098,8 @@ pub const CopyRelSection = struct {
1077 }1098 }
10781099
1079 pub fn addSymbol(copy_rel: *CopyRelSection, sym_index: Symbol.Index, elf_file: *Elf) !void {1100 pub fn addSymbol(copy_rel: *CopyRelSection, sym_index: Symbol.Index, elf_file: *Elf) !void {
1101 const comp = elf_file.base.comp;
1102 const gpa = comp.gpa;
1080 const index = @as(u32, @intCast(copy_rel.symbols.items.len));1103 const index = @as(u32, @intCast(copy_rel.symbols.items.len));
1081 const symbol = elf_file.symbol(sym_index);1104 const symbol = elf_file.symbol(sym_index);
1082 symbol.flags.import = true;1105 symbol.flags.import = true;
...@@ -1089,7 +1112,7 @@ pub const CopyRelSection = struct {...@@ -1089,7 +1112,7 @@ pub const CopyRelSection = struct {
1089 new_extra.copy_rel = index;1112 new_extra.copy_rel = index;
1090 symbol.setExtra(new_extra, elf_file);1113 symbol.setExtra(new_extra, elf_file);
1091 } else try symbol.addExtra(.{ .copy_rel = index }, elf_file);1114 } else try symbol.addExtra(.{ .copy_rel = index }, elf_file);
1092 try copy_rel.symbols.append(elf_file.base.allocator, sym_index);1115 try copy_rel.symbols.append(gpa, sym_index);
10931116
1094 const shared_object = symbol.file(elf_file).?.shared_object;1117 const shared_object = symbol.file(elf_file).?.shared_object;
1095 if (shared_object.aliases == null) {1118 if (shared_object.aliases == null) {
...@@ -1129,7 +1152,9 @@ pub const CopyRelSection = struct {...@@ -1129,7 +1152,9 @@ pub const CopyRelSection = struct {
1129 }1152 }
11301153
1131 pub fn addRela(copy_rel: CopyRelSection, elf_file: *Elf) !void {1154 pub fn addRela(copy_rel: CopyRelSection, elf_file: *Elf) !void {
1132 try elf_file.rela_dyn.ensureUnusedCapacity(elf_file.base.allocator, copy_rel.numRela());1155 const comp = elf_file.base.comp;
1156 const gpa = comp.gpa;
1157 try elf_file.rela_dyn.ensureUnusedCapacity(gpa, copy_rel.numRela());
1133 for (copy_rel.symbols.items) |sym_index| {1158 for (copy_rel.symbols.items) |sym_index| {
1134 const sym = elf_file.symbol(sym_index);1159 const sym = elf_file.symbol(sym_index);
1135 assert(sym.flags.import and sym.flags.has_copy_rel);1160 assert(sym.flags.import and sym.flags.has_copy_rel);
...@@ -1162,7 +1187,8 @@ pub const DynsymSection = struct {...@@ -1162,7 +1187,8 @@ pub const DynsymSection = struct {
1162 }1187 }
11631188
1164 pub fn addSymbol(dynsym: *DynsymSection, sym_index: Symbol.Index, elf_file: *Elf) !void {1189 pub fn addSymbol(dynsym: *DynsymSection, sym_index: Symbol.Index, elf_file: *Elf) !void {
1165 const gpa = elf_file.base.allocator;1190 const comp = elf_file.base.comp;
1191 const gpa = comp.gpa;
1166 const index = @as(u32, @intCast(dynsym.entries.items.len + 1));1192 const index = @as(u32, @intCast(dynsym.entries.items.len + 1));
1167 const sym = elf_file.symbol(sym_index);1193 const sym = elf_file.symbol(sym_index);
1168 sym.flags.has_dynamic = true;1194 sym.flags.has_dynamic = true;
...@@ -1244,7 +1270,8 @@ pub const HashSection = struct {...@@ -1244,7 +1270,8 @@ pub const HashSection = struct {
1244 pub fn generate(hs: *HashSection, elf_file: *Elf) !void {1270 pub fn generate(hs: *HashSection, elf_file: *Elf) !void {
1245 if (elf_file.dynsym.count() == 1) return;1271 if (elf_file.dynsym.count() == 1) return;
12461272
1247 const gpa = elf_file.base.allocator;1273 const comp = elf_file.base.comp;
1274 const gpa = comp.gpa;
1248 const nsyms = elf_file.dynsym.count();1275 const nsyms = elf_file.dynsym.count();
12491276
1250 var buckets = try gpa.alloc(u32, nsyms);1277 var buckets = try gpa.alloc(u32, nsyms);
...@@ -1332,7 +1359,8 @@ pub const GnuHashSection = struct {...@@ -1332,7 +1359,8 @@ pub const GnuHashSection = struct {
1332 try cwriter.writeInt(u32, hash.num_bloom, .little);1359 try cwriter.writeInt(u32, hash.num_bloom, .little);
1333 try cwriter.writeInt(u32, bloom_shift, .little);1360 try cwriter.writeInt(u32, bloom_shift, .little);
13341361
1335 const gpa = elf_file.base.allocator;1362 const comp = elf_file.base.comp;
1363 const gpa = comp.gpa;
1336 const hashes = try gpa.alloc(u32, exports.len);1364 const hashes = try gpa.alloc(u32, exports.len);
1337 defer gpa.free(hashes);1365 defer gpa.free(hashes);
1338 const indices = try gpa.alloc(u32, exports.len);1366 const indices = try gpa.alloc(u32, exports.len);
...@@ -1434,7 +1462,8 @@ pub const VerneedSection = struct {...@@ -1434,7 +1462,8 @@ pub const VerneedSection = struct {
1434 }1462 }
1435 };1463 };
14361464
1437 const gpa = elf_file.base.allocator;1465 const comp = elf_file.base.comp;
1466 const gpa = comp.gpa;
1438 var verneed = std.ArrayList(VersionedSymbol).init(gpa);1467 var verneed = std.ArrayList(VersionedSymbol).init(gpa);
1439 defer verneed.deinit();1468 defer verneed.deinit();
1440 try verneed.ensureTotalCapacity(dynsyms.len);1469 try verneed.ensureTotalCapacity(dynsyms.len);
...@@ -1490,7 +1519,8 @@ pub const VerneedSection = struct {...@@ -1490,7 +1519,8 @@ pub const VerneedSection = struct {
1490 }1519 }
14911520
1492 fn addVerneed(vern: *VerneedSection, soname: []const u8, elf_file: *Elf) !*elf.Elf64_Verneed {1521 fn addVerneed(vern: *VerneedSection, soname: []const u8, elf_file: *Elf) !*elf.Elf64_Verneed {
1493 const gpa = elf_file.base.allocator;1522 const comp = elf_file.base.comp;
1523 const gpa = comp.gpa;
1494 const sym = try vern.verneed.addOne(gpa);1524 const sym = try vern.verneed.addOne(gpa);
1495 sym.* = .{1525 sym.* = .{
1496 .vn_version = 1,1526 .vn_version = 1,
...@@ -1508,7 +1538,8 @@ pub const VerneedSection = struct {...@@ -1508,7 +1538,8 @@ pub const VerneedSection = struct {
1508 version: [:0]const u8,1538 version: [:0]const u8,
1509 elf_file: *Elf,1539 elf_file: *Elf,
1510 ) !elf.Elf64_Vernaux {1540 ) !elf.Elf64_Vernaux {
1511 const gpa = elf_file.base.allocator;1541 const comp = elf_file.base.comp;
1542 const gpa = comp.gpa;
1512 const sym = try vern.vernaux.addOne(gpa);1543 const sym = try vern.vernaux.addOne(gpa);
1513 sym.* = .{1544 sym.* = .{
1514 .vna_hash = HashSection.hasher(version),1545 .vna_hash = HashSection.hasher(version),
src/main.zig-17
...@@ -5242,22 +5242,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -5242,22 +5242,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
5242 });5242 });
52435243
5244 const builtin_mod = root_mod.getBuiltinDependency();5244 const builtin_mod = root_mod.getBuiltinDependency();
5245 const std_mod = try Package.Module.create(arena, .{
5246 .global_cache_directory = global_cache_directory,
5247 .paths = .{
5248 .root = .{
5249 .root_dir = zig_lib_directory,
5250 .sub_path = "std",
5251 },
5252 .root_src_path = "std.zig",
5253 },
5254 .fully_qualified_name = "std",
5255 .cc_argv = &.{},
5256 .inherited = .{},
5257 .global = config,
5258 .parent = root_mod,
5259 .builtin_mod = builtin_mod,
5260 });
52615245
5262 const build_mod = try Package.Module.create(arena, .{5246 const build_mod = try Package.Module.create(arena, .{
5263 .global_cache_directory = global_cache_directory,5247 .global_cache_directory = global_cache_directory,
...@@ -5425,7 +5409,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -5425,7 +5409,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
5425 .config = config,5409 .config = config,
5426 .root_mod = root_mod,5410 .root_mod = root_mod,
5427 .main_mod = build_mod,5411 .main_mod = build_mod,
5428 .std_mod = std_mod,
5429 .emit_bin = emit_bin,5412 .emit_bin = emit_bin,
5430 .emit_h = null,5413 .emit_h = null,
5431 .self_exe_path = self_exe_path,5414 .self_exe_path = self_exe_path,
src/musl.zig+1-1
...@@ -280,7 +280,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr...@@ -280,7 +280,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
280 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(comp.gpa, &.{280 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(comp.gpa, &.{
281 sub_compilation.bin_file.?.emit.sub_path,281 sub_compilation.bin_file.?.emit.sub_path,
282 }),282 }),
283 .lock = sub_compilation.bin_file.toOwnedLock(),283 .lock = sub_compilation.bin_file.?.toOwnedLock(),
284 });284 });
285 },285 },
286 }286 }