Skip to content

Commit

Permalink
elf: handle _end synthetic symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Jul 10, 2023
1 parent f27463d commit 584e4ac
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dso_handle_index: ?u32 = null,
gnu_eh_frame_hdr_index: ?u32 = null,
rela_iplt_start_index: ?u32 = null,
rela_iplt_end_index: ?u32 = null,
end_index: ?u32 = null,
start_stop_indexes: std.ArrayListUnmanaged(u32) = .{},

entry_index: ?u32 = null,
Expand Down Expand Up @@ -1404,6 +1405,17 @@ fn allocateSyntheticSymbols(self: *Elf) void {
end_sym.shndx = shndx;
}

// _end
{
const end_symbol = self.getSymbol(self.end_index.?);
for (self.sections.items(.shdr), 0..) |shdr, shndx| {
if (shdr.sh_flags & elf.SHF_ALLOC != 0) {
end_symbol.value = shdr.sh_addr + shdr.sh_size;
end_symbol.shndx = @intCast(shndx);
}
}
}

// __start_*, __stop_*
{
var index: usize = 0;
Expand Down Expand Up @@ -1759,6 +1771,7 @@ fn resolveSyntheticSymbols(self: *Elf) !void {
self.preinit_array_end_index = try internal.addSyntheticGlobal("__preinit_array_end", self);
self.got_index = try internal.addSyntheticGlobal("_GLOBAL_OFFSET_TABLE_", self);
self.plt_index = try internal.addSyntheticGlobal("_PROCEDURE_LINKAGE_TABLE_", self);
self.end_index = try internal.addSyntheticGlobal("_end", self);

if (self.options.eh_frame_hdr) {
self.gnu_eh_frame_hdr_index = try internal.addSyntheticGlobal("__GNU_EH_FRAME_HDR", self);
Expand Down

0 comments on commit 584e4ac

Please sign in to comment.