aboutsummaryrefslogtreecommitdiff
path: root/src/link/Elf
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2023-09-04 11:23:19 +0200
committerJakub Konka <kubkon@jakubkonka.com>2023-09-04 11:23:19 +0200
commitbc37c95e56b00f011a2cfb0b0795f234829c59da (patch)
treed196863fe5a9980113871e091a9452c4b07b5a6e /src/link/Elf
parent009a349779186548480823140dd1f8758d600221 (diff)
downloadzig-bc37c95e56b00f011a2cfb0b0795f234829c59da.tar.gz
zig-bc37c95e56b00f011a2cfb0b0795f234829c59da.zip
elf: simplify accessors to symbols, atoms, etc
Diffstat (limited to 'src/link/Elf')
-rw-r--r--src/link/Elf/Atom.zig38
1 files changed, 17 insertions, 21 deletions
diff --git a/src/link/Elf/Atom.zig b/src/link/Elf/Atom.zig
index bfdc2a81ca..7edb36f0a4 100644
--- a/src/link/Elf/Atom.zig
+++ b/src/link/Elf/Atom.zig
@@ -20,35 +20,31 @@ pub const Reloc = struct {
prev_vaddr: u64,
};
-pub fn getSymbolIndex(self: Atom) ?u32 {
+pub fn symbolIndex(self: *const Atom) ?u32 {
if (self.sym_index == 0) return null;
return self.sym_index;
}
-pub fn getSymbol(self: Atom, elf_file: *const Elf) elf.Elf64_Sym {
- return elf_file.getSymbol(self.getSymbolIndex().?);
+pub fn symbol(self: *const Atom, elf_file: *Elf) *elf.Elf64_Sym {
+ return elf_file.symbol(self.symbolIndex().?);
}
-pub fn getSymbolPtr(self: Atom, elf_file: *Elf) *elf.Elf64_Sym {
- return elf_file.getSymbolPtr(self.getSymbolIndex().?);
-}
-
-pub fn getName(self: Atom, elf_file: *const Elf) []const u8 {
- return elf_file.getSymbolName(self.getSymbolIndex().?);
+pub fn name(self: *const Atom, elf_file: *Elf) []const u8 {
+ return elf_file.symbolName(self.symbolIndex().?);
}
/// If entry already exists, returns index to it.
/// Otherwise, creates a new entry in the Global Offset Table for this Atom.
-pub fn getOrCreateOffsetTableEntry(self: Atom, elf_file: *Elf) !u32 {
- const sym_index = self.getSymbolIndex().?;
+pub fn getOrCreateOffsetTableEntry(self: *const Atom, elf_file: *Elf) !u32 {
+ const sym_index = self.symbolIndex().?;
if (elf_file.got_table.lookup.get(sym_index)) |index| return index;
const index = try elf_file.got_table.allocateEntry(elf_file.base.allocator, sym_index);
elf_file.got_table_count_dirty = true;
return index;
}
-pub fn getOffsetTableAddress(self: Atom, elf_file: *Elf) u64 {
- const sym_index = self.getSymbolIndex().?;
+pub fn getOffsetTableAddress(self: *const Atom, elf_file: *Elf) u64 {
+ const sym_index = self.symbolIndex().?;
const got_entry_index = elf_file.got_table.lookup.get(sym_index).?;
const target = elf_file.base.options.target;
const ptr_bits = target.ptrBitWidth();
@@ -60,11 +56,11 @@ pub fn getOffsetTableAddress(self: Atom, elf_file: *Elf) u64 {
/// Returns how much room there is to grow in virtual address space.
/// File offset relocation happens transparently, so it is not included in
/// this calculation.
-pub fn capacity(self: Atom, elf_file: *const Elf) u64 {
- const self_sym = self.getSymbol(elf_file);
+pub fn capacity(self: *const Atom, elf_file: *Elf) u64 {
+ const self_sym = self.symbol(elf_file);
if (self.next_index) |next_index| {
- const next = elf_file.getAtom(next_index);
- const next_sym = next.getSymbol(elf_file);
+ const next = elf_file.atom(next_index);
+ const next_sym = next.symbol(elf_file);
return next_sym.st_value - self_sym.st_value;
} else {
// We are the last block. The capacity is limited only by virtual address space.
@@ -72,12 +68,12 @@ pub fn capacity(self: Atom, elf_file: *const Elf) u64 {
}
}
-pub fn freeListEligible(self: Atom, elf_file: *const Elf) bool {
+pub fn freeListEligible(self: *const Atom, elf_file: *Elf) bool {
// No need to keep a free list node for the last block.
const next_index = self.next_index orelse return false;
- const next = elf_file.getAtom(next_index);
- const self_sym = self.getSymbol(elf_file);
- const next_sym = next.getSymbol(elf_file);
+ const next = elf_file.atom(next_index);
+ const self_sym = self.symbol(elf_file);
+ const next_sym = next.symbol(elf_file);
const cap = next_sym.st_value - self_sym.st_value;
const ideal_cap = Elf.padToIdeal(self_sym.st_size);
if (cap <= ideal_cap) return false;