elf: report fatal linker error for unhandled relocation types

This commit is contained in:
Jakub Konka 2023-09-28 14:06:12 +02:00
parent a63ce5a37c
commit af00ac53b5
3 changed files with 15 additions and 9 deletions

View File

@ -4098,7 +4098,7 @@ const ErrorWithNotes = struct {
}
};
fn addErrorWithNotes(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes {
pub fn addErrorWithNotes(self: *Elf, note_count: usize) error{OutOfMemory}!ErrorWithNotes {
try self.misc_errors.ensureUnusedCapacity(self.base.allocator, 1);
return self.addErrorWithNotesAssumeCapacity(note_count);
}

View File

@ -388,7 +388,17 @@ pub fn scanRelocs(self: Atom, elf_file: *Elf, undefs: anytype) !void {
elf.R_X86_64_PC32 => {},
else => @panic("TODO"),
else => {
var err = try elf_file.addErrorWithNotes(1);
try err.addMsg(elf_file, "fatal linker error: unhandled relocation type {}", .{
fmtRelocType(rel.r_type()),
});
try err.addNote(elf_file, "in {}:{s} at offset 0x{x}", .{
self.file(elf_file).?.fmtPath(),
self.name(elf_file),
rel.r_offset,
});
},
}
}
}
@ -512,10 +522,7 @@ pub fn resolveRelocs(self: Atom, elf_file: *Elf, code: []u8) !void {
try cwriter.writeIntLittle(i32, @as(i32, @intCast(G + GOT + A - P)));
},
else => {
log.err("TODO: unhandled relocation type {}", .{fmtRelocType(rel.r_type())});
@panic("TODO unhandled relocation type");
},
else => {},
}
}
}

View File

@ -233,8 +233,7 @@ fn getOutputSectionIndex(self: *Object, elf_file: *Elf, shdr: elf.Elf64_Shdr) er
const is_alloc = flags & elf.SHF_ALLOC != 0;
const is_write = flags & elf.SHF_WRITE != 0;
const is_exec = flags & elf.SHF_EXECINSTR != 0;
const is_tls = flags & elf.SHF_TLS != 0;
if (!is_alloc or is_tls) {
if (!is_alloc) {
log.err("{}: output section {s} not found", .{ self.fmtPath(), name });
@panic("TODO: missing output section!");
}
@ -243,7 +242,7 @@ fn getOutputSectionIndex(self: *Object, elf_file: *Elf, shdr: elf.Elf64_Shdr) er
if (is_exec) phdr_flags |= elf.PF_X;
const phdr_index = try elf_file.allocateSegment(.{
.size = Elf.padToIdeal(shdr.sh_size),
.alignment = if (is_tls) shdr.sh_addralign else elf_file.page_size,
.alignment = elf_file.page_size,
.flags = phdr_flags,
});
const shndx = try elf_file.allocateAllocSection(.{