authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-05-10 17:52:35+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-05-11 11:15:23+02:00
log4c2f1e01a7911f9f1d793156459d6df6c76edf68
treeafb5cb8c0a5e5e767f75fb0594847b5bd3247199
parent62821292180ce442f81a3a600e883d5011d6b5c8
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

freebsd: Create strong references to __progname and environ in stub libc.so.

These symbols are defined in the statically-linked startup code. The real libc.so.7 contains strong references to them, so they need to be put into the dynamic symbol table.

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

src/libs/freebsd.zig+19
......@@ -668,6 +668,25 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
668668
669669 try stubs_writer.writeAll(".data\n");
670670
671 // FreeBSD's `libc.so.7` contains strong references to `__progname` and `environ` which are
672 // defined in the statically-linked startup code. Those references cause the linker to put
673 // the symbols in the dynamic symbol table. We need to create dummy references to them here
674 // to get the same effect.
675 if (std.mem.eql(u8, lib.name, "c")) {
676 try stubs_writer.print(
677 \\.balign {d}
678 \\.globl __progname
679 \\.globl environ
680 \\{s} __progname
681 \\{s} environ
682 \\
683 , .{
684 target.ptrBitWidth() / 8,
685 wordDirective(target),
686 wordDirective(target),
687 });
688 }
689
671690 const obj_inclusions_len = try inc_reader.readInt(u16, .little);
672691
673692 var sizes = try arena.alloc(u16, metadata.all_versions.len);