elf: move getStartStopBasename into Object

This commit is contained in:
Jakub Konka 2024-08-02 18:32:07 +02:00
parent 41e9b8b6c8
commit 8ca809d928
3 changed files with 14 additions and 12 deletions

View File

@ -5252,14 +5252,6 @@ pub fn isCIdentifier(name: []const u8) bool {
return true;
}
pub fn getStartStopBasename(self: *Elf, shdr: elf.Elf64_Shdr) ?[]const u8 {
const name = self.getShString(shdr.sh_name);
if (shdr.sh_flags & elf.SHF_ALLOC != 0 and name.len > 0) {
if (isCIdentifier(name)) return name;
}
return null;
}
pub fn addThunk(self: *Elf) !Thunk.Index {
const index = @as(Thunk.Index, @intCast(self.thunks.items.len));
const th = try self.thunks.addOne(self.base.comp.gpa);

View File

@ -95,8 +95,9 @@ pub fn initSymbols(self: *LinkerDefined, elf_file: *Elf) !void {
var start_stop_count: usize = 0;
for (elf_file.objects.items) |index| {
for (elf_file.file(index).?.object.shdrs.items) |shdr| {
if (elf_file.getStartStopBasename(shdr)) |_| {
const object = elf_file.file(index).?.object;
for (object.shdrs.items) |shdr| {
if (object.getStartStopBasename(shdr)) |_| {
start_stop_count += 2; // __start_, __stop_
}
}
@ -140,8 +141,9 @@ pub fn initSymbols(self: *LinkerDefined, elf_file: *Elf) !void {
}
for (elf_file.objects.items) |index| {
for (elf_file.file(index).?.object.shdrs.items) |shdr| {
if (elf_file.getStartStopBasename(shdr)) |name| {
const object = elf_file.file(index).?.object;
for (object.shdrs.items) |shdr| {
if (object.getStartStopBasename(shdr)) |name| {
const start_name = try std.fmt.allocPrintZ(gpa, "__start_{s}", .{name});
defer gpa.free(start_name);
const stop_name = try std.fmt.allocPrintZ(gpa, "__stop_{s}", .{name});

View File

@ -1444,6 +1444,14 @@ pub fn comdatGroup(self: *Object, index: Elf.ComdatGroup.Index) *Elf.ComdatGroup
return &self.comdat_groups.items[index];
}
pub fn getStartStopBasename(self: Object, shdr: elf.Elf64_Shdr) ?[]const u8 {
const name = self.getString(shdr.sh_name);
if (shdr.sh_flags & elf.SHF_ALLOC != 0 and name.len > 0) {
if (Elf.isCIdentifier(name)) return name;
}
return null;
}
pub fn format(
self: *Object,
comptime unused_fmt_string: []const u8,