aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/Symbol.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-07-20 06:41:30 +0200
committerJakub Konka <kubkon@jakubkonka.com>2024-07-22 12:06:02 +0200
commit2b84592858fe004fcae1372f7a5f97e10a81c2e3 (patch)
treef0ebc5be3d85396d423e837b023057f6258a194a /src/link/MachO/Symbol.zig
parent5d9fd5bcdeb9f7a1af50b0eaffd22b61f3e440a6 (diff)
downloadzig-2b84592858fe004fcae1372f7a5f97e10a81c2e3.tar.gz
zig-2b84592858fe004fcae1372f7a5f97e10a81c2e3.zip
macho: run more things in parallel
Diffstat (limited to 'src/link/MachO/Symbol.zig')
-rw-r--r--src/link/MachO/Symbol.zig34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/link/MachO/Symbol.zig b/src/link/MachO/Symbol.zig
index 72cd55bf5a..99f49f1112 100644
--- a/src/link/MachO/Symbol.zig
+++ b/src/link/MachO/Symbol.zig
@@ -23,6 +23,8 @@ nlist_idx: u32 = 0,
/// Misc flags for the symbol packaged as packed struct for compression.
flags: Flags = .{},
+sect_flags: std.atomic.Value(u8) = std.atomic.Value(u8).init(0),
+
visibility: Visibility = .local,
extra: u32 = 0,
@@ -69,6 +71,14 @@ pub fn getOutputSectionIndex(symbol: Symbol, macho_file: *MachO) u8 {
return symbol.out_n_sect;
}
+pub fn getSectionFlags(symbol: Symbol) SectionFlags {
+ return @bitCast(symbol.sect_flags.load(.seq_cst));
+}
+
+pub fn setSectionFlags(symbol: *Symbol, flags: SectionFlags) void {
+ _ = symbol.sect_flags.fetchOr(@bitCast(flags), .seq_cst);
+}
+
pub fn getFile(symbol: Symbol, macho_file: *MachO) ?File {
return macho_file.getFile(symbol.file);
}
@@ -116,9 +126,9 @@ pub fn getAddress(symbol: Symbol, opts: struct {
stubs: bool = true,
}, macho_file: *MachO) u64 {
if (opts.stubs) {
- if (symbol.flags.stubs) {
+ if (symbol.getSectionFlags().stubs) {
return symbol.getStubsAddress(macho_file);
- } else if (symbol.flags.objc_stubs) {
+ } else if (symbol.getSectionFlags().objc_stubs) {
return symbol.getObjcStubsAddress(macho_file);
}
}
@@ -127,25 +137,25 @@ pub fn getAddress(symbol: Symbol, opts: struct {
}
pub fn getGotAddress(symbol: Symbol, macho_file: *MachO) u64 {
- if (!symbol.flags.has_got) return 0;
+ if (!symbol.getSectionFlags().has_got) return 0;
const extra = symbol.getExtra(macho_file);
return macho_file.got.getAddress(extra.got, macho_file);
}
pub fn getStubsAddress(symbol: Symbol, macho_file: *MachO) u64 {
- if (!symbol.flags.stubs) return 0;
+ if (!symbol.getSectionFlags().stubs) return 0;
const extra = symbol.getExtra(macho_file);
return macho_file.stubs.getAddress(extra.stubs, macho_file);
}
pub fn getObjcStubsAddress(symbol: Symbol, macho_file: *MachO) u64 {
- if (!symbol.flags.objc_stubs) return 0;
+ if (!symbol.getSectionFlags().objc_stubs) return 0;
const extra = symbol.getExtra(macho_file);
return macho_file.objc_stubs.getAddress(extra.objc_stubs, macho_file);
}
pub fn getObjcSelrefsAddress(symbol: Symbol, macho_file: *MachO) u64 {
- if (!symbol.flags.objc_stubs) return 0;
+ if (!symbol.getSectionFlags().objc_stubs) return 0;
const extra = symbol.getExtra(macho_file);
const file = symbol.getFile(macho_file).?;
return switch (file) {
@@ -155,7 +165,7 @@ pub fn getObjcSelrefsAddress(symbol: Symbol, macho_file: *MachO) u64 {
}
pub fn getTlvPtrAddress(symbol: Symbol, macho_file: *MachO) u64 {
- if (!symbol.flags.tlv_ptr) return 0;
+ if (!symbol.getSectionFlags().tlv_ptr) return 0;
const extra = symbol.getExtra(macho_file);
return macho_file.tlv_ptr.getAddress(extra.tlv_ptr, macho_file);
}
@@ -167,14 +177,14 @@ const GetOrCreateZigGotEntryResult = struct {
pub fn getOrCreateZigGotEntry(symbol: *Symbol, symbol_index: Index, macho_file: *MachO) !GetOrCreateZigGotEntryResult {
assert(!macho_file.base.isRelocatable());
- assert(symbol.flags.needs_zig_got);
- if (symbol.flags.has_zig_got) return .{ .found_existing = true, .index = symbol.getExtra(macho_file).zig_got };
+ assert(symbol.getSectionFlags().needs_zig_got);
+ if (symbol.getSectionFlags().has_zig_got) return .{ .found_existing = true, .index = symbol.getExtra(macho_file).zig_got };
const index = try macho_file.zig_got.addSymbol(symbol_index, macho_file);
return .{ .found_existing = false, .index = index };
}
pub fn getZigGotAddress(symbol: Symbol, macho_file: *MachO) u64 {
- if (!symbol.flags.has_zig_got) return 0;
+ if (!symbol.getSectionFlags().has_zig_got) return 0;
const extras = symbol.getExtra(macho_file);
return macho_file.zig_got.entryAddress(extras.zig_got, macho_file);
}
@@ -384,7 +394,9 @@ pub const Flags = packed struct {
/// Whether the symbol makes into the output symtab or not.
output_symtab: bool = false,
+};
+pub const SectionFlags = packed struct(u8) {
/// Whether the symbol contains __got indirection.
needs_got: bool = false,
has_got: bool = false,
@@ -401,6 +413,8 @@ pub const Flags = packed struct {
/// Whether the symbol contains __objc_stubs indirection.
objc_stubs: bool = false,
+
+ _: u1 = 0,
};
pub const Visibility = enum {