Skip to content

Commit 54335de

Browse files
committed
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 parent 2175195 commit 54335de

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/libs/freebsd.zig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

0 commit comments

Comments
 (0)