authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-07-04 10:31:59+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-07-04 21:01:43+01:00
logcda6f552d5d4a996df69981dac7c9d9b3c066537
tree3480f8008b2d382ad64a45feb0190a1e974bb9a8
parenta5d5c097f55d7a1b53055310e2d150b23e56eebb
signaturelock-open Commit is signed but in an unrecognized format.

cbe: don't mark exported values/Decls as extern


1 files changed, 19 insertions(+), 4 deletions(-)

src/link/C.zig+19-4
......@@ -536,11 +536,22 @@ pub fn flushModule(self: *C, arena: Allocator, prog_node: std.Progress.Node) !vo
536536 try f.all_buffers.ensureUnusedCapacity(gpa, 1 + (self.anon_decls.count() + self.decl_table.count()) * 2);
537537 f.appendBufAssumeCapacity(self.lazy_code_buf.items);
538538 for (self.anon_decls.keys(), self.anon_decls.values()) |anon_decl, decl_block| f.appendCodeAssumeCapacity(
539 self.exported_values.contains(anon_decl),
539 if (self.exported_values.contains(anon_decl))
540 .default
541 else switch (zcu.intern_pool.indexToKey(anon_decl)) {
542 .extern_func => .zig_extern,
543 .variable => |variable| if (variable.is_extern) .zig_extern else .static,
544 else => .static,
545 },
540546 self.getString(decl_block.code),
541547 );
542548 for (self.decl_table.keys(), self.decl_table.values()) |decl_index, decl_block| f.appendCodeAssumeCapacity(
543 self.exported_decls.contains(decl_index),
549 if (self.exported_decls.contains(decl_index))
550 .default
551 else if (zcu.declPtr(decl_index).isExtern(zcu))
552 .zig_extern
553 else
554 .static,
544555 self.getString(decl_block.code),
545556 );
546557
......@@ -572,9 +583,13 @@ const Flush = struct {
572583 f.file_size += buf.len;
573584 }
574585
575 fn appendCodeAssumeCapacity(f: *Flush, is_extern: bool, code: []const u8) void {
586 fn appendCodeAssumeCapacity(f: *Flush, storage: enum { default, zig_extern, static }, code: []const u8) void {
576587 if (code.len == 0) return;
577 f.appendBufAssumeCapacity(if (is_extern) "\nzig_extern " else "\nstatic ");
588 f.appendBufAssumeCapacity(switch (storage) {
589 .default => "\n",
590 .zig_extern => "\nzig_extern ",
591 .static => "\nstatic ",
592 });
578593 f.appendBufAssumeCapacity(code);
579594 }
580595