diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2021-07-23 17:06:19 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2021-07-23 17:06:19 +0200 |
| commit | 5533f77054acad376f2fce0d529569a7449e9949 (patch) | |
| tree | eba6945383fefa59a8858f7eec8beee3cfca7731 /src/link | |
| parent | 1beda818e1c10bde98b35759b3c131a864be58d9 (diff) | |
| parent | e5b476209a1215a03164890d331e2013f20882a6 (diff) | |
| download | zig-5533f77054acad376f2fce0d529569a7449e9949.tar.gz zig-5533f77054acad376f2fce0d529569a7449e9949.zip | |
Merge remote-tracking branch 'origin/master' into zld-incremental-2
Diffstat (limited to 'src/link')
| -rw-r--r-- | src/link/Coff.zig | 25 | ||||
| -rw-r--r-- | src/link/Elf.zig | 20 | ||||
| -rw-r--r-- | src/link/MachO.zig | 13 | ||||
| -rw-r--r-- | src/link/Wasm.zig | 13 |
4 files changed, 43 insertions, 28 deletions
diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 50ad6bc1a0..0bae2cc6cc 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -17,9 +17,9 @@ const link = @import("../link.zig"); const build_options = @import("build_options"); const Cache = @import("../Cache.zig"); const mingw = @import("../mingw.zig"); -const llvm_backend = @import("../codegen/llvm.zig"); const Air = @import("../Air.zig"); const Liveness = @import("../Liveness.zig"); +const LlvmObject = @import("../codegen/llvm.zig").Object; const allocation_padding = 4 / 3; const minimum_text_block_size = 64 * allocation_padding; @@ -37,7 +37,7 @@ pub const base_tag: link.File.Tag = .coff; const msdos_stub = @embedFile("msdos-stub.bin"); /// If this is not null, an object file is created by LLVM and linked with LLD afterwards. -llvm_object: ?*llvm_backend.Object = null, +llvm_object: ?*LlvmObject = null, base: link.File, ptr_width: PtrWidth, @@ -132,7 +132,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio const self = try createEmpty(allocator, options); errdefer self.base.destroy(); - self.llvm_object = try llvm_backend.Object.create(allocator, sub_path, options); + self.llvm_object = try LlvmObject.create(allocator, options); return self; } @@ -657,10 +657,7 @@ fn writeOffsetTableEntry(self: *Coff, index: usize) !void { } pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, liveness: Liveness) !void { - if (build_options.skip_non_native and - builtin.object_format != .coff and - builtin.object_format != .pe) - { + if (build_options.skip_non_native and builtin.object_format != .coff) { @panic("Attempted to compile for object format that was disabled by build configuration"); } if (build_options.have_llvm) { @@ -697,7 +694,7 @@ pub fn updateFunc(self: *Coff, module: *Module, func: *Module.Fn, air: Air, live } pub fn updateDecl(self: *Coff, module: *Module, decl: *Module.Decl) !void { - if (build_options.skip_non_native and builtin.object_format != .coff and builtin.object_format != .pe) { + if (build_options.skip_non_native and builtin.object_format != .coff) { @panic("Attempted to compile for object format that was disabled by build configuration"); } if (build_options.have_llvm) { @@ -823,8 +820,11 @@ pub fn flushModule(self: *Coff, comp: *Compilation) !void { const tracy = trace(@src()); defer tracy.end(); - if (build_options.have_llvm) - if (self.llvm_object) |llvm_object| return try llvm_object.flushModule(comp); + if (build_options.have_llvm) { + if (self.llvm_object) |llvm_object| { + return try llvm_object.flushModule(comp); + } + } if (self.text_section_size_dirty) { // Write the new raw size in the .text header @@ -1398,8 +1398,9 @@ pub fn updateDeclLineNumber(self: *Coff, module: *Module, decl: *Module.Decl) !v } pub fn deinit(self: *Coff) void { - if (build_options.have_llvm) - if (self.llvm_object) |ir_module| ir_module.deinit(self.base.allocator); + if (build_options.have_llvm) { + if (self.llvm_object) |llvm_object| llvm_object.destroy(self.base.allocator); + } self.text_block_free_list.deinit(self.base.allocator); self.offset_table.deinit(self.base.allocator); diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 315dfb563b..c95af23026 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -25,9 +25,9 @@ const target_util = @import("../target.zig"); const glibc = @import("../glibc.zig"); const musl = @import("../musl.zig"); const Cache = @import("../Cache.zig"); -const llvm_backend = @import("../codegen/llvm.zig"); const Air = @import("../Air.zig"); const Liveness = @import("../Liveness.zig"); +const LlvmObject = @import("../codegen/llvm.zig").Object; const default_entry_addr = 0x8000000; @@ -38,7 +38,7 @@ base: File, ptr_width: PtrWidth, /// If this is not null, an object file is created by LLVM and linked with LLD afterwards. -llvm_object: ?*llvm_backend.Object = null, +llvm_object: ?*LlvmObject = null, /// Stored in native-endian format, depending on target endianness needs to be bswapped on read/write. /// Same order as in the file. @@ -235,7 +235,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio const self = try createEmpty(allocator, options); errdefer self.base.destroy(); - self.llvm_object = try llvm_backend.Object.create(allocator, sub_path, options); + self.llvm_object = try LlvmObject.create(allocator, options); return self; } @@ -301,9 +301,9 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Elf { } pub fn deinit(self: *Elf) void { - if (build_options.have_llvm) - if (self.llvm_object) |ir_module| - ir_module.deinit(self.base.allocator); + if (build_options.have_llvm) { + if (self.llvm_object) |llvm_object| llvm_object.destroy(self.base.allocator); + } self.sections.deinit(self.base.allocator); self.program_headers.deinit(self.base.allocator); @@ -750,8 +750,8 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void { if (build_options.have_llvm) if (self.llvm_object) |llvm_object| return try llvm_object.flushModule(comp); - // TODO This linker code currently assumes there is only 1 compilation unit and it corresponds to the - // Zig source code. + // TODO This linker code currently assumes there is only 1 compilation unit and it + // corresponds to the Zig source code. const module = self.base.options.module orelse return error.LinkingWithoutZigSourceUnimplemented; const target_endian = self.base.options.target.cpu.arch.endian(); @@ -1289,6 +1289,10 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { // TODO: remove when stage2 can build compiler_rt.zig if (!build_options.is_stage1) break :blk null; + // In the case of build-obj we include the compiler-rt symbols directly alongside + // the symbols of the root source file, in the same compilation unit. + if (is_obj) break :blk null; + if (is_exe_or_dyn_lib) { break :blk comp.compiler_rt_static_lib.?.full_object_path; } else { diff --git a/src/link/MachO.zig b/src/link/MachO.zig index a8749c1dfb..21f4e9c33c 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -29,21 +29,22 @@ const CodeSignature = @import("MachO/CodeSignature.zig"); const Compilation = @import("../Compilation.zig"); const DebugSymbols = @import("MachO/DebugSymbols.zig"); const Dylib = @import("MachO/Dylib.zig"); +const File = link.File; const Object = @import("MachO/Object.zig"); const Liveness = @import("../Liveness.zig"); +const LlvmObject = @import("../codegen/llvm.zig").Object; const LoadCommand = commands.LoadCommand; const Module = @import("../Module.zig"); -const File = link.File; +const SegmentCommand = commands.SegmentCommand; pub const TextBlock = @import("MachO/TextBlock.zig"); const Trie = @import("MachO/Trie.zig"); -const SegmentCommand = commands.SegmentCommand; pub const base_tag: File.Tag = File.Tag.macho; base: File, /// If this is not null, an object file is created by LLVM and linked with LLD afterwards. -llvm_object: ?*llvm_backend.Object = null, +llvm_object: ?*LlvmObject = null, /// Debug symbols bundle (or dSym). d_sym: ?DebugSymbols = null, @@ -333,7 +334,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio const self = try createEmpty(allocator, options); errdefer self.base.destroy(); - self.llvm_object = try llvm_backend.Object.create(allocator, sub_path, options); + self.llvm_object = try LlvmObject.create(allocator, options); return self; } @@ -3305,6 +3306,10 @@ fn writeSymbolTable(self: *MachO) !void { } pub fn deinit(self: *MachO) void { + if (build_options.have_llvm) { + if (self.llvm_object) |llvm_object| llvm_object.destroy(self.base.allocator); + } + if (self.d_sym) |*ds| { ds.deinit(self.base.allocator); } diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index f478d2ee47..2ed6576033 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -19,7 +19,7 @@ const build_options = @import("build_options"); const wasi_libc = @import("../wasi_libc.zig"); const Cache = @import("../Cache.zig"); const TypedValue = @import("../TypedValue.zig"); -const llvm_backend = @import("../codegen/llvm.zig"); +const LlvmObject = @import("../codegen/llvm.zig").Object; const Air = @import("../Air.zig"); const Liveness = @import("../Liveness.zig"); @@ -27,7 +27,7 @@ pub const base_tag = link.File.Tag.wasm; base: link.File, /// If this is not null, an object file is created by LLVM and linked with LLD afterwards. -llvm_object: ?*llvm_backend.Object = null, +llvm_object: ?*LlvmObject = null, /// List of all function Decls to be written to the output file. The index of /// each Decl in this list at the time of writing the binary is used as the /// function index. In the event where ext_funcs' size is not 0, the index of @@ -121,7 +121,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio const self = try createEmpty(allocator, options); errdefer self.base.destroy(); - self.llvm_object = try llvm_backend.Object.create(allocator, sub_path, options); + self.llvm_object = try LlvmObject.create(allocator, options); return self; } @@ -153,6 +153,9 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Wasm { } pub fn deinit(self: *Wasm) void { + if (build_options.have_llvm) { + if (self.llvm_object) |llvm_object| llvm_object.destroy(self.base.allocator); + } for (self.symbols.items) |decl| { decl.fn_link.wasm.functype.deinit(self.base.allocator); decl.fn_link.wasm.code.deinit(self.base.allocator); @@ -642,7 +645,9 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { break :blk full_obj_path; } else null; - const compiler_rt_path: ?[]const u8 = if (self.base.options.include_compiler_rt) + const is_obj = self.base.options.output_mode == .Obj; + + const compiler_rt_path: ?[]const u8 = if (self.base.options.include_compiler_rt and !is_obj) comp.compiler_rt_static_lib.?.full_object_path else null; |
