| ... | @@ -897,7 +897,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -897,7 +897,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 897 | } else null; | 897 | } else null; |
| 898 | const gc_sections = self.base.options.gc_sections orelse false; | 898 | const gc_sections = self.base.options.gc_sections orelse false; |
| 899 | | 899 | |
| 900 | if (self.base.options.output_mode == .Obj and self.zig_object_index == null) { | 900 | if (self.isObject() and self.zig_object_index == null) { |
| 901 | // TODO this will become -r route I guess. For now, just copy the object file. | 901 | // TODO this will become -r route I guess. For now, just copy the object file. |
| 902 | assert(self.base.file == null); // TODO uncomment once we implement -r | 902 | assert(self.base.file == null); // TODO uncomment once we implement -r |
| 903 | const the_object_path = blk: { | 903 | const the_object_path = blk: { |
| ... | @@ -1364,7 +1364,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1364,7 +1364,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1364 | | 1364 | |
| 1365 | // If we haven't already, create a linker-generated input file comprising of | 1365 | // If we haven't already, create a linker-generated input file comprising of |
| 1366 | // linker-defined synthetic symbols only such as `_DYNAMIC`, etc. | 1366 | // linker-defined synthetic symbols only such as `_DYNAMIC`, etc. |
| 1367 | if (self.linker_defined_index == null) { | 1367 | if (self.linker_defined_index == null and !self.isObject()) { |
| 1368 | const index = @as(File.Index, @intCast(try self.files.addOne(gpa))); | 1368 | const index = @as(File.Index, @intCast(try self.files.addOne(gpa))); |
| 1369 | self.files.set(index, .{ .linker_defined = .{ .index = index } }); | 1369 | self.files.set(index, .{ .linker_defined = .{ .index = index } }); |
| 1370 | self.linker_defined_index = index; | 1370 | self.linker_defined_index = index; |
| ... | @@ -1377,6 +1377,11 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1377,6 +1377,11 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1377 | // symbol for potential resolution at load-time. | 1377 | // symbol for potential resolution at load-time. |
| 1378 | self.resolveSymbols(); | 1378 | self.resolveSymbols(); |
| 1379 | self.markEhFrameAtomsDead(); | 1379 | self.markEhFrameAtomsDead(); |
| | 1380 | |
| | 1381 | if (self.isObject()) { |
| | 1382 | return self.flushObject(comp); |
| | 1383 | } |
| | 1384 | |
| 1380 | try self.convertCommonSymbols(); | 1385 | try self.convertCommonSymbols(); |
| 1381 | self.markImportsExports(); | 1386 | self.markImportsExports(); |
| 1382 | | 1387 | |
| ... | @@ -1470,6 +1475,13 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1470,6 +1475,13 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1470 | } | 1475 | } |
| 1471 | } | 1476 | } |
| 1472 | | 1477 | |
| | 1478 | pub fn flushObject(self: *Elf, comp: *Compilation) link.File.FlushError!void { |
| | 1479 | _ = comp; |
| | 1480 | try self.initSections(); |
| | 1481 | try self.writeShdrTable(); |
| | 1482 | try self.writeHeader(); |
| | 1483 | } |
| | 1484 | |
| 1473 | const ParseError = error{ | 1485 | const ParseError = error{ |
| 1474 | UnknownFileType, | 1486 | UnknownFileType, |
| 1475 | InvalidCpuArch, | 1487 | InvalidCpuArch, |
| ... | @@ -2766,7 +2778,7 @@ fn writeHeader(self: *Elf) !void { | ... | @@ -2766,7 +2778,7 @@ fn writeHeader(self: *Elf) !void { |
| 2766 | index += 4; | 2778 | index += 4; |
| 2767 | | 2779 | |
| 2768 | const e_entry = if (self.entry_index) |entry_index| self.symbol(entry_index).value else 0; | 2780 | const e_entry = if (self.entry_index) |entry_index| self.symbol(entry_index).value else 0; |
| 2769 | const phdr_table_offset = self.phdrs.items[self.phdr_table_index.?].p_offset; | 2781 | const phdr_table_offset = if (self.phdr_table_index) |phndx| self.phdrs.items[phndx].p_offset else 0; |
| 2770 | switch (self.ptr_width) { | 2782 | switch (self.ptr_width) { |
| 2771 | .p32 => { | 2783 | .p32 => { |
| 2772 | mem.writeInt(u32, hdr_buf[index..][0..4], @as(u32, @intCast(e_entry)), endian); | 2784 | mem.writeInt(u32, hdr_buf[index..][0..4], @as(u32, @intCast(e_entry)), endian); |
| ... | @@ -4845,6 +4857,10 @@ pub fn isStatic(self: Elf) bool { | ... | @@ -4845,6 +4857,10 @@ pub fn isStatic(self: Elf) bool { |
| 4845 | return self.base.options.link_mode == .Static; | 4857 | return self.base.options.link_mode == .Static; |
| 4846 | } | 4858 | } |
| 4847 | | 4859 | |
| | 4860 | pub fn isObject(self: Elf) bool { |
| | 4861 | return self.base.options.effectiveOutputMode() == .Obj; |
| | 4862 | } |
| | 4863 | |
| 4848 | pub fn isExe(self: Elf) bool { | 4864 | pub fn isExe(self: Elf) bool { |
| 4849 | return self.base.options.effectiveOutputMode() == .Exe; | 4865 | return self.base.options.effectiveOutputMode() == .Exe; |
| 4850 | } | 4866 | } |