aboutsummaryrefslogtreecommitdiff
path: root/src/link
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-09-13 19:51:19 +0200
committerJakub Konka <kubkon@jakubkonka.com>2023-09-13 21:51:43 +0200
commitce88df497c096f5a35200d975de855ba4502a4d8 (patch)
tree05c1f0f612f5149c0a258377d704fef81389dcaa /src/link
parentdbde746f9d95f2dbc8872e2d6283c2db64ac7519 (diff)
downloadzig-ce88df497c096f5a35200d975de855ba4502a4d8.tar.gz
zig-ce88df497c096f5a35200d975de855ba4502a4d8.zip
elf: do not store Symbol's index in Symbol
Diffstat (limited to 'src/link')
-rw-r--r--src/link/Elf.zig17
-rw-r--r--src/link/Elf/Atom.zig20
-rw-r--r--src/link/Elf/Symbol.zig8
3 files changed, 26 insertions, 19 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
index 0867fe017b..ce14ce3f52 100644
--- a/src/link/Elf.zig
+++ b/src/link/Elf.zig
@@ -1082,9 +1082,10 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;
break :blk null;
};
- if (compiler_rt_path) |path| {
- try positionals.append(.{ .path = path });
- }
+ _ = compiler_rt_path;
+ // if (compiler_rt_path) |path| {
+ // try positionals.append(.{ .path = path });
+ // }
for (positionals.items) |obj| {
const in_file = try std.fs.cwd().openFile(obj.path, .{});
@@ -1643,11 +1644,11 @@ fn scanRelocs(self: *Elf) !void {
try self.reportUndefined(&undefs);
- for (self.symbols.items) |*sym| {
+ for (self.symbols.items, 0..) |*sym, sym_index| {
if (sym.flags.needs_got) {
log.debug("'{s}' needs GOT", .{sym.name(self)});
// TODO how can we tell we need to write it again, aka the entry is dirty?
- const gop = try sym.getOrCreateGotEntry(self);
+ const gop = try sym.getOrCreateGotEntry(@intCast(sym_index), self);
try self.got.writeEntry(self, gop.index);
}
}
@@ -2695,7 +2696,7 @@ fn updateDeclCode(
esym.st_value = atom_ptr.value;
sym.flags.needs_got = true;
- const gop = try sym.getOrCreateGotEntry(self);
+ const gop = try sym.getOrCreateGotEntry(sym_index, self);
try self.got.writeEntry(self, gop.index);
}
@@ -2930,7 +2931,7 @@ fn updateLazySymbol(self: *Elf, sym: link.File.LazySymbol, symbol_index: Symbol.
local_esym.st_value = atom_ptr.value;
local_sym.flags.needs_got = true;
- const gop = try local_sym.getOrCreateGotEntry(self);
+ const gop = try local_sym.getOrCreateGotEntry(symbol_index, self);
try self.got.writeEntry(self, gop.index);
const section_offset = atom_ptr.value - self.phdrs.items[phdr_index].p_vaddr;
@@ -3801,7 +3802,7 @@ pub fn addSymbol(self: *Elf) !Symbol.Index {
break :blk index;
}
};
- self.symbols.items[index] = .{ .index = index };
+ self.symbols.items[index] = .{};
return index;
}
diff --git a/src/link/Elf/Atom.zig b/src/link/Elf/Atom.zig
index 6dc95daf75..43a8913c4b 100644
--- a/src/link/Elf/Atom.zig
+++ b/src/link/Elf/Atom.zig
@@ -322,11 +322,12 @@ pub fn scanRelocs(self: Atom, elf_file: *Elf, undefs: anytype) !void {
if (rel.r_type() == elf.R_X86_64_NONE) continue;
- const symbol = switch (file_ptr) {
- .zig_module => |x| elf_file.symbol(x.symbol(rel.r_sym())),
- .object => |x| elf_file.symbol(x.symbols.items[rel.r_sym()]),
+ const symbol_index = switch (file_ptr) {
+ .zig_module => |x| x.symbol(rel.r_sym()),
+ .object => |x| x.symbols.items[rel.r_sym()],
else => unreachable,
};
+ const symbol = elf_file.symbol(symbol_index);
// Check for violation of One Definition Rule for COMDATs.
if (symbol.file(elf_file) == null) {
@@ -340,7 +341,7 @@ pub fn scanRelocs(self: Atom, elf_file: *Elf, undefs: anytype) !void {
}
// Report an undefined symbol.
- try self.reportUndefined(elf_file, symbol, rel, undefs);
+ try self.reportUndefined(elf_file, symbol, symbol_index, rel, undefs);
// While traversing relocations, mark symbols that require special handling such as
// pointer indirection via GOT, or a stub trampoline via PLT.
@@ -379,7 +380,14 @@ pub fn scanRelocs(self: Atom, elf_file: *Elf, undefs: anytype) !void {
}
// This function will report any undefined non-weak symbols that are not imports.
-fn reportUndefined(self: Atom, elf_file: *Elf, sym: *const Symbol, rel: elf.Elf64_Rela, undefs: anytype) !void {
+fn reportUndefined(
+ self: Atom,
+ elf_file: *Elf,
+ sym: *const Symbol,
+ sym_index: Symbol.Index,
+ rel: elf.Elf64_Rela,
+ undefs: anytype,
+) !void {
const rel_esym = switch (elf_file.file(self.file_index).?) {
.zig_module => |x| x.elfSym(rel.r_sym()).*,
.object => |x| x.symtab[rel.r_sym()],
@@ -392,7 +400,7 @@ fn reportUndefined(self: Atom, elf_file: *Elf, sym: *const Symbol, rel: elf.Elf6
!sym.flags.import and
esym.st_shndx == elf.SHN_UNDEF)
{
- const gop = try undefs.getOrPut(sym.index);
+ const gop = try undefs.getOrPut(sym_index);
if (!gop.found_existing) {
gop.value_ptr.* = std.ArrayList(Atom.Index).init(elf_file.base.allocator);
}
diff --git a/src/link/Elf/Symbol.zig b/src/link/Elf/Symbol.zig
index 42b9b81ef9..c70d0b8229 100644
--- a/src/link/Elf/Symbol.zig
+++ b/src/link/Elf/Symbol.zig
@@ -1,7 +1,5 @@
//! Represents a defined symbol.
-index: Index = 0,
-
/// Allocated address value of this symbol.
value: u64 = 0,
@@ -117,10 +115,10 @@ const GetOrCreateGotEntryResult = struct {
index: GotSection.Index,
};
-pub fn getOrCreateGotEntry(symbol: *Symbol, elf_file: *Elf) !GetOrCreateGotEntryResult {
+pub fn getOrCreateGotEntry(symbol: *Symbol, symbol_index: Index, elf_file: *Elf) !GetOrCreateGotEntryResult {
assert(symbol.flags.needs_got);
if (symbol.flags.has_got) return .{ .found_existing = true, .index = symbol.extra(elf_file).?.got };
- const index = try elf_file.got.addGotSymbol(symbol.index, elf_file);
+ const index = try elf_file.got.addGotSymbol(symbol_index, elf_file);
symbol.flags.has_got = true;
return .{ .found_existing = false, .index = index };
}
@@ -270,7 +268,7 @@ fn format2(
_ = options;
_ = unused_fmt_string;
const symbol = ctx.symbol;
- try writer.print("%{d} : {s} : @{x}", .{ symbol.index, symbol.fmtName(ctx.elf_file), symbol.value });
+ try writer.print("%{d} : {s} : @{x}", .{ symbol.esym_index, symbol.fmtName(ctx.elf_file), symbol.value });
if (symbol.file(ctx.elf_file)) |file_ptr| {
if (symbol.isAbs(ctx.elf_file)) {
if (symbol.elfSym(ctx.elf_file).st_shndx == elf.SHN_UNDEF) {