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.
This commit is contained in:
Alex Rønne Petersen 2025-05-10 17:52:35 +02:00
parent 6282129218
commit 4c2f1e01a7
No known key found for this signature in database

View file

@ -668,6 +668,25 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
try stubs_writer.writeAll(".data\n");
// FreeBSD's `libc.so.7` contains strong references to `__progname` and `environ` which are
// defined in the statically-linked startup code. Those references cause the linker to put
// the symbols in the dynamic symbol table. We need to create dummy references to them here
// to get the same effect.
if (std.mem.eql(u8, lib.name, "c")) {
try stubs_writer.print(
\\.balign {d}
\\.globl __progname
\\.globl environ
\\{s} __progname
\\{s} environ
\\
, .{
target.ptrBitWidth() / 8,
wordDirective(target),
wordDirective(target),
});
}
const obj_inclusions_len = try inc_reader.readInt(u16, .little);
var sizes = try arena.alloc(u16, metadata.all_versions.len);