Skip to content

Commit

Permalink
elf: fix emitting relocs in .eh_frame section
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Sep 20, 2024
1 parent e721943 commit b3d3a67
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Elf/eh_frame.zig
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ pub const Cie = struct {
if (cie_rel.r_type() != other_rel.r_type()) return false;
if (cie_rel.r_addend != other_rel.r_addend) return false;

const cie_sym = cie.getObject(elf_file).symbols.items[cie_rel.r_sym()];
const other_sym = other.getObject(elf_file).symbols.items[other_rel.r_sym()];
if (!std.mem.eql(u8, std.mem.asBytes(&cie_sym), std.mem.asBytes(&other_sym))) return false;
const cie_object = elf_file.getFile(cie.file).?.object;
const cie_ref = cie_object.resolveSymbol(cie_rel.r_sym(), elf_file);
const other_object = elf_file.getFile(other.file).?.object;
const other_ref = other_object.resolveSymbol(other_rel.r_sym(), elf_file);
if (!cie_ref.eql(other_ref)) return false;
}
return true;
}
Expand Down Expand Up @@ -485,17 +487,19 @@ pub fn writeEhFrameRelocs(elf_file: *Elf, writer: anytype) !void {
for (object.cies.items) |cie| {
if (!cie.alive) continue;
for (cie.getRelocs(elf_file)) |rel| {
const sym = object.symbols.items[rel.r_sym()];
const out_rel = emitReloc(elf_file, cie, sym, rel);
const sym_ref = object.resolveSymbol(rel.r_sym(), elf_file);
const sym = elf_file.getSymbol(sym_ref).?;
const out_rel = emitReloc(elf_file, cie, sym.*, rel);
try writer.writeStruct(out_rel);
}
}

for (object.fdes.items) |fde| {
if (!fde.alive) continue;
for (fde.getRelocs(elf_file)) |rel| {
const sym = object.symbols.items[rel.r_sym()];
const out_rel = emitReloc(elf_file, fde, sym, rel);
const sym_ref = object.resolveSymbol(rel.r_sym(), elf_file);
const sym = elf_file.getSymbol(sym_ref).?;
const out_rel = emitReloc(elf_file, fde, sym.*, rel);
try writer.writeStruct(out_rel);
}
}
Expand Down

0 comments on commit b3d3a67

Please sign in to comment.