aboutsummaryrefslogtreecommitdiff
path: root/src/libs
diff options
context:
space:
mode:
authorAlex Rønne Petersen <alex@alexrp.com>2025-05-10 17:52:35 +0200
committerAlex Rønne Petersen <alex@alexrp.com>2025-05-11 11:15:23 +0200
commit4c2f1e01a7911f9f1d793156459d6df6c76edf68 (patch)
treeafb5cb8c0a5e5e767f75fb0594847b5bd3247199 /src/libs
parent62821292180ce442f81a3a600e883d5011d6b5c8 (diff)
downloadzig-4c2f1e01a7911f9f1d793156459d6df6c76edf68.tar.gz
zig-4c2f1e01a7911f9f1d793156459d6df6c76edf68.zip
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.
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/freebsd.zig19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libs/freebsd.zig b/src/libs/freebsd.zig
index 9aa4066649..c7365ede4a 100644
--- a/src/libs/freebsd.zig
+++ b/src/libs/freebsd.zig
@@ -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);