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 {...@@ -2263,6 +2263,11 @@ pub fn initBuiltins(coff: *Coff) !void {
2263 }2263 }
22642264
2265 defer coff.flushSectionMerges() catch unreachable;2265 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
2266 if (coff.isImage() and target.isMinGW() and comp.config.link_libc) {2271 if (coff.isImage() and target.isMinGW() and comp.config.link_libc) {
2267 try coff.symbols.ensureUnusedCapacity(gpa, 8);2272 try coff.symbols.ensureUnusedCapacity(gpa, 8);
2268 try coff.globals.ensureUnusedCapacity(gpa, 2);2273 try coff.globals.ensureUnusedCapacity(gpa, 2);
...@@ -3543,20 +3548,13 @@ fn objectSectionMapIndex(...@@ -3543,20 +3548,13 @@ fn objectSectionMapIndex(
3543) !Node.ObjectSectionMapIndex {3548) !Node.ObjectSectionMapIndex {
3544 const gpa = coff.base.comp.gpa;3549 const gpa = coff.base.comp.gpa;
3545 const name_slice = name.toSlice(coff);3550 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
3554 const object_section_gop = try coff.object_section_table.getOrPut(gpa, name);3552 const object_section_gop = try coff.object_section_table.getOrPut(gpa, name);
3555 const osmi: Node.ObjectSectionMapIndex = @fromBackingInt(@intCast(object_section_gop.index));3553 const osmi: Node.ObjectSectionMapIndex = @fromBackingInt(@intCast(object_section_gop.index));
3556 const sym = if (!object_section_gop.found_existing) sym: {3554 const sym = if (!object_section_gop.found_existing) sym: {
3557 try coff.ensureUnusedStringCapacity(name_slice.len);3555 try coff.ensureUnusedStringCapacity(name_slice.len);
3558 const parent_name = coff.getOrPutStringAssumeCapacity(coff.objectSectionParentName(name_slice));3556 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);
3560 try coff.nodes.ensureUnusedCapacity(gpa, 1);3558 try coff.nodes.ensureUnusedCapacity(gpa, 1);
3561 try coff.symbols.ensureUnusedCapacity(gpa, 1);3559 try coff.symbols.ensureUnusedCapacity(gpa, 1);
3562 const parent_ni = parent.node(coff);3560 const parent_ni = parent.node(coff);
...@@ -3608,7 +3606,7 @@ fn objectSectionMapIndex(...@@ -3608,7 +3606,7 @@ fn objectSectionMapIndex(
3608 name,3606 name,
3609 .object,3607 .object,
3610 .fromFlags(sym.section_number.header(coff).flags),3608 .fromFlags(sym.section_number.header(coff).flags),
3611 effective_attributes,3609 attributes,
3612 );3610 );
36133611
3614 return osmi;3612 return osmi;