mirror of
https://github.com/ziglang/zig.git
synced 2026-02-07 06:57:13 +00:00
elf: move getStartStopBasename into Object
This commit is contained in:
parent
41e9b8b6c8
commit
8ca809d928
@ -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);
|
||||
|
||||
@ -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});
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user