authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-09-12 15:49:50-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2026-09-19 13:02:11-04:00
log5a4fda7e36e9862d6c0fd8fe15d7bd5cefa2f6e9
tree2df9429ca824a9aa33b713ec582a606606a8c97a
parent3f6a02acdda41190eab7d57a9f037df9d4853631

Coff: use a section merge instead of manually rewriting attributes for .tls


1 files changed, 7 insertions(+), 9 deletions(-)

src/link/Coff.zig+7-9
......@@ -2263,6 +2263,11 @@ pub fn initBuiltins(coff: *Coff) !void {
22632263 }
22642264
22652265 defer coff.flushSectionMerges() catch unreachable;
2266 if (coff.isImage()) {
2267 // In images, the .tls section is a read-only template
2268 try coff.section_merges.put(gpa, .@".tls", .@".rdata");
2269 }
2270
22662271 if (coff.isImage() and target.isMinGW() and comp.config.link_libc) {
22672272 try coff.symbols.ensureUnusedCapacity(gpa, 8);
22682273 try coff.globals.ensureUnusedCapacity(gpa, 2);
......@@ -3543,20 +3548,13 @@ fn objectSectionMapIndex(
35433548) !Node.ObjectSectionMapIndex {
35443549 const gpa = coff.base.comp.gpa;
35453550 const name_slice = name.toSlice(coff);
3546 // TODO: Should this be a section merge instead?
3547 const effective_attributes = if (coff.isImage() and std.mem.startsWith(u8, name_slice, ".tls")) attr: {
3548 // In images, the .tls section is a read-only template
3549 var attr = attributes;
3550 attr.write = false;
3551 break :attr attr;
3552 } else attributes;
35533551
35543552 const object_section_gop = try coff.object_section_table.getOrPut(gpa, name);
35553553 const osmi: Node.ObjectSectionMapIndex = @fromBackingInt(@intCast(object_section_gop.index));
35563554 const sym = if (!object_section_gop.found_existing) sym: {
35573555 try coff.ensureUnusedStringCapacity(name_slice.len);
35583556 const parent_name = coff.getOrPutStringAssumeCapacity(coff.objectSectionParentName(name_slice));
3559 const parent = (try coff.pseudoSectionMapIndex(parent_name, alignment, effective_attributes)).symbol(coff);
3557 const parent = (try coff.pseudoSectionMapIndex(parent_name, alignment, attributes)).symbol(coff);
35603558 try coff.nodes.ensureUnusedCapacity(gpa, 1);
35613559 try coff.symbols.ensureUnusedCapacity(gpa, 1);
35623560 const parent_ni = parent.node(coff);
......@@ -3608,7 +3606,7 @@ fn objectSectionMapIndex(
36083606 name,
36093607 .object,
36103608 .fromFlags(sym.section_number.header(coff).flags),
3611 effective_attributes,
3609 attributes,
36123610 );
36133611
36143612 return osmi;