aboutsummaryrefslogtreecommitdiff
path: root/src/link/Elf.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-02-13 16:42:28 +0100
committerJakub Konka <kubkon@jakubkonka.com>2024-02-13 20:33:01 +0100
commite401930fa862e3b9b3eedc8eb405c501fbf3de30 (patch)
treedad8558d3ccf98880a4c7f8f6ecb443b52a34247 /src/link/Elf.zig
parentc22bb3805821d7ffe60e048f1efe362aad703668 (diff)
downloadzig-e401930fa862e3b9b3eedc8eb405c501fbf3de30.tar.gz
zig-e401930fa862e3b9b3eedc8eb405c501fbf3de30.zip
elf: store relative offsets in atom and symbol
Diffstat (limited to 'src/link/Elf.zig')
-rw-r--r--src/link/Elf.zig16
1 files changed, 3 insertions, 13 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
index 7f421d5d26..7ef4684765 100644
--- a/src/link/Elf.zig
+++ b/src/link/Elf.zig
@@ -1332,7 +1332,6 @@ pub fn flushModule(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node)
try self.sortPhdrs();
try self.allocateNonAllocSections();
self.allocateSpecialPhdrs();
- self.allocateAtoms();
self.allocateLinkerDefinedSymbols();
// Dump the state for easy debugging.
@@ -1352,7 +1351,7 @@ pub fn flushModule(self: *Elf, arena: Allocator, prog_node: *std.Progress.Node)
if (shdr.sh_type == elf.SHT_NOBITS) continue;
const code = try zig_object.codeAlloc(self, atom_index);
defer gpa.free(code);
- const file_offset = shdr.sh_offset + atom_ptr.value - shdr.sh_addr;
+ const file_offset = shdr.sh_offset + atom_ptr.value;
atom_ptr.resolveRelocsAlloc(self, code) catch |err| switch (err) {
// TODO
error.RelaxFail, error.InvalidInstruction, error.CannotEncode => {
@@ -2907,7 +2906,7 @@ pub fn writeElfHeader(self: *Elf) !void {
mem.writeInt(u32, hdr_buf[index..][0..4], 1, endian);
index += 4;
- const e_entry = if (self.entry_index) |entry_index| self.symbol(entry_index).value else 0;
+ const e_entry = if (self.entry_index) |entry_index| self.symbol(entry_index).address(.{}, self) else 0;
const phdr_table_offset = if (self.phdr_table_index) |phndx| self.phdrs.items[phndx].p_offset else 0;
switch (self.ptr_width) {
.p32 => {
@@ -4402,15 +4401,6 @@ fn allocateSpecialPhdrs(self: *Elf) void {
}
}
-pub fn allocateAtoms(self: *Elf) void {
- if (self.zigObjectPtr()) |zig_object| {
- zig_object.allocateTlvAtoms(self);
- }
- for (self.objects.items) |index| {
- self.file(index).?.object.allocateAtoms(self);
- }
-}
-
fn writeAtoms(self: *Elf) !void {
const gpa = self.base.comp.gpa;
@@ -4464,7 +4454,7 @@ fn writeAtoms(self: *Elf) !void {
const atom_ptr = self.atom(atom_index).?;
assert(atom_ptr.flags.alive);
- const offset = math.cast(usize, atom_ptr.value - shdr.sh_addr - base_offset) orelse
+ const offset = math.cast(usize, atom_ptr.value - base_offset) orelse
return error.Overflow;
const size = math.cast(usize, atom_ptr.size) orelse return error.Overflow;