Skip to content

Commit a9568ed

Browse files
authored
Merge pull request #25898 from jacobly0/elfv2-progress
Elf2: more progress
2 parents 7b325e0 + 61a1cef commit a9568ed

File tree

8 files changed

+838
-247
lines changed

8 files changed

+838
-247
lines changed

lib/std/Io/Writer.zig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,10 +2282,6 @@ pub const Discarding = struct {
22822282

22832283
pub fn sendFile(w: *Writer, file_reader: *File.Reader, limit: Limit) FileError!usize {
22842284
if (File.Handle == void) return error.Unimplemented;
2285-
switch (builtin.zig_backend) {
2286-
else => {},
2287-
.stage2_aarch64 => return error.Unimplemented,
2288-
}
22892285
const d: *Discarding = @alignCast(@fieldParentPtr("writer", w));
22902286
d.count += w.end;
22912287
w.end = 0;

lib/std/Progress.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ const noop_impl = builtin.single_threaded or switch (builtin.os.tag) {
427427
.wasi, .freestanding => true,
428428
else => false,
429429
} or switch (builtin.zig_backend) {
430-
.stage2_aarch64 => true,
431430
else => false,
432431
};
433432

lib/std/fs/File.zig

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,10 +739,7 @@ pub const Writer = struct {
739739
return .{
740740
.vtable = &.{
741741
.drain = drain,
742-
.sendFile = switch (builtin.zig_backend) {
743-
else => sendFile,
744-
.stage2_aarch64 => Io.Writer.unimplementedSendFile,
745-
},
742+
.sendFile = sendFile,
746743
},
747744
.buffer = buffer,
748745
};

src/codegen/aarch64/Select.zig

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9569,11 +9569,15 @@ pub const Value = struct {
95699569
.zr
95709570
else
95719571
return false;
9572-
if (part_ra != .zr) {
9573-
const live_vi = isel.live_registers.getPtr(part_ra);
9574-
assert(live_vi.* == .free);
9575-
live_vi.* = .allocating;
9576-
}
9572+
const part_lock: RegLock = switch (part_ra) {
9573+
else => isel.lockReg(part_ra),
9574+
.zr => .empty,
9575+
};
9576+
defer switch (opts.expected_live_registers.get(part_ra)) {
9577+
_ => {},
9578+
.allocating => unreachable,
9579+
.free => part_lock.unlock(isel),
9580+
};
95779581
if (opts.wrap) |int_info| switch (int_info.bits) {
95789582
else => unreachable,
95799583
1...7, 9...15, 17...31 => |bits| try isel.emit(switch (int_info.signedness) {
@@ -9604,15 +9608,6 @@ pub const Value = struct {
96049608
64 => {},
96059609
};
96069610
try isel.loadReg(part_ra, part_size, part_vi.signedness(isel), base_ra, opts.offset);
9607-
if (part_ra != .zr) {
9608-
const live_vi = isel.live_registers.getPtr(part_ra);
9609-
assert(live_vi.* == .allocating);
9610-
switch (opts.expected_live_registers.get(part_ra)) {
9611-
_ => {},
9612-
.allocating => unreachable,
9613-
.free => live_vi.* = .free,
9614-
}
9615-
}
96169611
return true;
96179612
}
96189613
var used = false;

src/codegen/x86_64/Emit.zig

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
881881
end_offset - 4,
882882
@enumFromInt(reloc.target.index),
883883
reloc.off - 4,
884-
.{ .X86_64 = .PC32 },
884+
.{ .X86_64 = .PLT32 },
885885
) else if (emit.bin_file.cast(.macho)) |macho_file| {
886886
const zo = macho_file.getZigObject().?;
887887
const atom = zo.symbols.items[emit.atom_index].getAtom(macho_file).?;
@@ -916,7 +916,13 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
916916
.r_info = @as(u64, reloc.target.index) << 32 | @intFromEnum(r_type),
917917
.r_addend = reloc.off - 4,
918918
}, zo);
919-
} else return emit.fail("TODO implement {s} reloc for {s}", .{
919+
} else if (emit.bin_file.cast(.elf2)) |elf| try elf.addReloc(
920+
@enumFromInt(emit.atom_index),
921+
end_offset - 4,
922+
@enumFromInt(reloc.target.index),
923+
reloc.off - 4,
924+
.{ .X86_64 = if (emit.pic) .TLSLD else unreachable },
925+
) else return emit.fail("TODO implement {s} reloc for {s}", .{
920926
@tagName(reloc.target.type), @tagName(emit.bin_file.tag),
921927
}),
922928
.tlv => if (emit.bin_file.cast(.elf)) |elf_file| {
@@ -933,7 +939,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
933939
end_offset - 4,
934940
@enumFromInt(reloc.target.index),
935941
reloc.off,
936-
.{ .X86_64 = .TPOFF32 },
942+
.{ .X86_64 = if (emit.pic) .DTPOFF32 else .TPOFF32 },
937943
) else if (emit.bin_file.cast(.macho)) |macho_file| {
938944
const zo = macho_file.getZigObject().?;
939945
const atom = zo.symbols.items[emit.atom_index].getAtom(macho_file).?;

src/link.zig

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ pub const File = struct {
10691069
errdefer archive.file.close();
10701070
loadInput(base, .{ .archive = archive }) catch |err| switch (err) {
10711071
error.BadMagic, error.UnexpectedEndOfFile => {
1072-
if (base.tag != .elf) return err;
1072+
if (base.tag != .elf and base.tag != .elf2) return err;
10731073
try loadGnuLdScript(base, path, query, archive.file);
10741074
archive.file.close();
10751075
return;
@@ -1091,7 +1091,7 @@ pub const File = struct {
10911091
errdefer dso.file.close();
10921092
loadInput(base, .{ .dso = dso }) catch |err| switch (err) {
10931093
error.BadMagic, error.UnexpectedEndOfFile => {
1094-
if (base.tag != .elf) return err;
1094+
if (base.tag != .elf and base.tag != .elf2) return err;
10951095
try loadGnuLdScript(base, path, query, dso.file);
10961096
dso.file.close();
10971097
return;
@@ -1101,8 +1101,9 @@ pub const File = struct {
11011101
}
11021102

11031103
fn loadGnuLdScript(base: *File, path: Path, parent_query: UnresolvedInput.Query, file: fs.File) anyerror!void {
1104-
const diags = &base.comp.link_diags;
1105-
const gpa = base.comp.gpa;
1104+
const comp = base.comp;
1105+
const diags = &comp.link_diags;
1106+
const gpa = comp.gpa;
11061107
const stat = try file.stat();
11071108
const size = std.math.cast(u32, stat.size) orelse return error.FileTooBig;
11081109
const buf = try gpa.alloc(u8, size);
@@ -1124,7 +1125,11 @@ pub const File = struct {
11241125
@panic("TODO");
11251126
} else {
11261127
if (fs.path.isAbsolute(arg.path)) {
1127-
const new_path = Path.initCwd(try gpa.dupe(u8, arg.path));
1128+
const new_path = Path.initCwd(path: {
1129+
comp.mutex.lock();
1130+
defer comp.mutex.unlock();
1131+
break :path try comp.arena.dupe(u8, arg.path);
1132+
});
11281133
switch (Compilation.classifyFileExt(arg.path)) {
11291134
.shared_library => try openLoadDso(base, new_path, query),
11301135
.object => try openLoadObject(base, new_path),

0 commit comments

Comments
 (0)