| ... | ... | @@ -149,7 +149,6 @@ pub const Node = union(enum) { |
| 149 | 149 | header, |
| 150 | 150 | /// Images and archives only. |
| 151 | 151 | signature, |
| 152 | | |
| 153 | 152 | /// Archives only. |
| 154 | 153 | archive_member_header: Member.Index, |
| 155 | 154 | archive_member: Member.Index, |
| ... | ... | @@ -159,6 +158,7 @@ pub const Node = union(enum) { |
| 159 | 158 | optional_header, |
| 160 | 159 | /// Image only |
| 161 | 160 | data_directories, |
| 161 | |
| 162 | 162 | section_table, |
| 163 | 163 | // Archives and objects only |
| 164 | 164 | symbol_table, |
| ... | ... | @@ -1201,6 +1201,15 @@ fn isArchive(coff: *const Coff) bool { |
| 1201 | 1201 | }; |
| 1202 | 1202 | } |
| 1203 | 1203 | |
| 1204 | fn isObj(coff: *const Coff) bool { |
| 1205 | return coff.base.comp.config.output_mode == .Obj; |
| 1206 | } |
| 1207 | |
| 1208 | fn zcuSectionParent(coff: *Coff) MappedFile.Node.Index { |
| 1209 | assert(coff.base.comp.zcu != null); |
| 1210 | return if (coff.isArchive()) Node.known.zcu_member else Node.known.file; |
| 1211 | } |
| 1212 | |
| 1204 | 1213 | fn initHeaders( |
| 1205 | 1214 | coff: *Coff, |
| 1206 | 1215 | machine: std.coff.IMAGE.FILE.MACHINE, |
| ... | ... | @@ -1261,7 +1270,7 @@ fn initHeaders( |
| 1261 | 1270 | const archive_signature = "!<arch>\n"; |
| 1262 | 1271 | |
| 1263 | 1272 | const signature_ni = Node.known.signature; |
| 1264 | | assert(signature_ni == try coff.mf.addLastChildNode(gpa, if (is_image) header_ni else Node.known.file, .{ |
| 1273 | assert(signature_ni == try coff.mf.addLastChildNode(gpa, if (is_image or !is_archive) header_ni else Node.known.file, .{ |
| 1265 | 1274 | .size = if (is_image) |
| 1266 | 1275 | msdos_stub.len + pe_signature.len |
| 1267 | 1276 | else if (is_archive) |
| ... | ... | @@ -2448,12 +2457,7 @@ fn addSection(coff: *Coff, name: []const u8, flags: std.coff.SectionHeader.Flags |
| 2448 | 2457 | @sizeOf(std.coff.SectionHeader) * section_table_len, |
| 2449 | 2458 | ); |
| 2450 | 2459 | |
| 2451 | | const parent_ni = if (coff.isArchive()) |
| 2452 | | Node.known.zcu_member |
| 2453 | | else |
| 2454 | | Node.known.file; |
| 2455 | | |
| 2456 | | const ni = try coff.mf.addLastChildNode(gpa, parent_ni, .{ |
| 2460 | const ni = try coff.mf.addLastChildNode(gpa, coff.zcuSectionParent(), .{ |
| 2457 | 2461 | .alignment = coff.mf.flags.block_size, |
| 2458 | 2462 | .moved = true, |
| 2459 | 2463 | .bubbles_moved = false, |
| ... | ... | @@ -2652,7 +2656,7 @@ pub fn addReloc( |
| 2652 | 2656 | const new_size = new_num_relocations * std.coff.Relocation.sizeOf(); |
| 2653 | 2657 | if (section.relocation_table_ni == .none) { |
| 2654 | 2658 | try coff.nodes.ensureUnusedCapacity(gpa, 1); |
| 2655 | | section.relocation_table_ni = try coff.mf.addLastChildNode(gpa, Node.known.zcu_member, .{ |
| 2659 | section.relocation_table_ni = try coff.mf.addLastChildNode(gpa, coff.zcuSectionParent(), .{ |
| 2656 | 2660 | .size = new_size, |
| 2657 | 2661 | .alignment = .@"2", |
| 2658 | 2662 | .moved = true, |
| ... | ... | @@ -3308,7 +3312,7 @@ fn flushGlobal(coff: *Coff, pt: Zcu.PerThread, gmi: Node.GlobalMapIndex) !void { |
| 3308 | 3312 | const si = gmi.symbol(coff); |
| 3309 | 3313 | try coff.pendingSymbolTableEntry(si); |
| 3310 | 3314 | |
| 3311 | | if (si.get(coff).ni != .none) |
| 3315 | if (coff.isArchive() and si.get(coff).ni != .none) |
| 3312 | 3316 | try coff.ensureMemberSymbol( |
| 3313 | 3317 | gn.name, |
| 3314 | 3318 | coff.getNode(Node.known.zcu_member).archive_member, |
| ... | ... | @@ -3542,7 +3546,7 @@ fn flushMoved(coff: *Coff, ni: MappedFile.Node.Index) !void { |
| 3542 | 3546 | .data_directories, |
| 3543 | 3547 | .section_table, |
| 3544 | 3548 | .placeholder, |
| 3545 | | => if (coff.isImage()) unreachable, |
| 3549 | => assert(!coff.isImage()), |
| 3546 | 3550 | .symbol_table => { |
| 3547 | 3551 | coff.targetStore( |
| 3548 | 3552 | &coff.headerPtr().pointer_to_symbol_table, |