diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-08-27 07:31:29 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-08-29 11:39:35 +0200 |
| commit | 42e0850d78e63fcc602dd0e167ac90dfb3cfec02 (patch) | |
| tree | 62cbed417608fcffc6c7ef4f3bda6045d067f00a /src/link/MachO/Atom.zig | |
| parent | 84853c5c56e87a7ee6c5392756b0773b650d283c (diff) | |
| download | zig-42e0850d78e63fcc602dd0e167ac90dfb3cfec02.tar.gz zig-42e0850d78e63fcc602dd0e167ac90dfb3cfec02.zip | |
macho: save indexes to all sections of interest
Diffstat (limited to 'src/link/MachO/Atom.zig')
| -rw-r--r-- | src/link/MachO/Atom.zig | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/src/link/MachO/Atom.zig b/src/link/MachO/Atom.zig index 411c42c4dd..73099184e0 100644 --- a/src/link/MachO/Atom.zig +++ b/src/link/MachO/Atom.zig @@ -244,13 +244,16 @@ pub fn getOutputSection(zld: *Zld, sect: macho.section_64) !?u8 { .{}, ); } else if (mem.eql(u8, sectname, "__data")) { - break :blk zld.getSectionByName("__DATA", "__data") orelse try MachO.initSection( - gpa, - zld, - "__DATA", - "__data", - .{}, - ); + if (zld.data_section_index == null) { + zld.data_section_index = try MachO.initSection( + gpa, + zld, + "__DATA", + "__data", + .{}, + ); + } + break :blk zld.data_section_index.?; } } break :blk zld.getSectionByName(segname, sectname) orelse try MachO.initSection( @@ -264,6 +267,35 @@ pub fn getOutputSection(zld: *Zld, sect: macho.section_64) !?u8 { else => break :blk null, } }; + + // TODO we can do this directly in the selection logic above. + // Or is it not worth it? + if (zld.data_const_section_index == null) { + if (zld.getSectionByName("__DATA_CONST", "__const")) |index| { + zld.data_const_section_index = index; + } + } + if (zld.thread_vars_section_index == null) { + if (zld.getSectionByName("__DATA", "__thread_vars")) |index| { + zld.thread_vars_section_index = index; + } + } + if (zld.thread_data_section_index == null) { + if (zld.getSectionByName("__DATA", "__thread_data")) |index| { + zld.thread_data_section_index = index; + } + } + if (zld.thread_bss_section_index == null) { + if (zld.getSectionByName("__DATA", "__thread_bss")) |index| { + zld.thread_bss_section_index = index; + } + } + if (zld.bss_section_index == null) { + if (zld.getSectionByName("__DATA", "__bss")) |index| { + zld.bss_section_index = index; + } + } + return res; } @@ -662,9 +694,9 @@ pub fn getRelocTargetAddress(zld: *Zld, target: SymbolWithLoc, is_tlv: bool) !u6 // * wrt to __thread_data if defined, then // * wrt to __thread_bss const sect_id: u16 = sect_id: { - if (zld.getSectionByName("__DATA", "__thread_data")) |i| { + if (zld.thread_data_section_index) |i| { break :sect_id i; - } else if (zld.getSectionByName("__DATA", "__thread_bss")) |i| { + } else if (zld.thread_bss_section_index) |i| { break :sect_id i; } else { log.err("threadlocal variables present but no initializer sections found", .{}); |
