macho: collect all exports into the export trie

This commit is contained in:
Jakub Konka 2023-03-21 21:31:24 +01:00
parent 1be8621815
commit 8bffe87e9e
2 changed files with 12 additions and 31 deletions

View file

@ -3340,36 +3340,19 @@ fn collectExportData(self: *MachO, trie: *Trie) !void {
const exec_segment = self.segments.items[self.header_segment_cmd_index.?];
const base_address = exec_segment.vmaddr;
if (self.base.options.output_mode == .Exe) {
for (&[_]SymbolWithLoc{
try self.getEntryPoint(),
self.getGlobal("__mh_execute_header").?,
}) |global| {
const sym = self.getSymbol(global);
const sym_name = self.getSymbolName(global);
log.debug(" (putting '{s}' defined at 0x{x})", .{ sym_name, sym.n_value });
try trie.put(gpa, .{
.name = sym_name,
.vmaddr_offset = sym.n_value - base_address,
.export_flags = macho.EXPORT_SYMBOL_FLAGS_KIND_REGULAR,
});
}
} else {
assert(self.base.options.output_mode == .Lib);
for (self.globals.items) |global| {
const sym = self.getSymbol(global);
for (self.globals.items) |global| {
const sym = self.getSymbol(global);
if (sym.undf()) continue;
if (!sym.ext()) continue;
if (sym.undf()) continue;
if (!sym.ext()) continue;
const sym_name = self.getSymbolName(global);
log.debug(" (putting '{s}' defined at 0x{x})", .{ sym_name, sym.n_value });
try trie.put(gpa, .{
.name = sym_name,
.vmaddr_offset = sym.n_value - base_address,
.export_flags = macho.EXPORT_SYMBOL_FLAGS_KIND_REGULAR,
});
}
const sym_name = self.getSymbolName(global);
log.debug(" (putting '{s}' defined at 0x{x})", .{ sym_name, sym.n_value });
try trie.put(gpa, .{
.name = sym_name,
.vmaddr_offset = sym.n_value - base_address,
.export_flags = macho.EXPORT_SYMBOL_FLAGS_KIND_REGULAR,
});
}
try trie.finalize(gpa);

View file

@ -2158,9 +2158,7 @@ pub const Zld = struct {
try trie.finalize(gpa);
}
fn writeDyldInfoData(
self: *Zld,
) !void {
fn writeDyldInfoData(self: *Zld) !void {
const gpa = self.gpa;
var rebase = Rebase{};