Skip to content

Commit 776a6e0

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 60a1b44 commit 776a6e0

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
@@ -663,6 +663,25 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
663663

664664
try stubs_writer.writeAll(".data\n");
665665

666+
// FreeBSD's `libc.so.7` contains strong references to `__progname` and `environ` which are
667+
// defined in the statically-linked startup code. Those references cause the linker to put
668+
// the symbols in the dynamic symbol table. We need to create dummy references to them here
669+
// to get the same effect.
670+
if (std.mem.eql(u8, lib.name, "c")) {
671+
try stubs_writer.print(
672+
\\.balign {d}
673+
\\.globl __progname
674+
\\.globl environ
675+
\\{s} __progname
676+
\\{s} environ
677+
\\
678+
, .{
679+
target.ptrBitWidth() / 8,
680+
wordDirective(target),
681+
wordDirective(target),
682+
});
683+
}
684+
666685
const obj_inclusions_len = try inc_reader.readInt(u16, .little);
667686

668687
var sizes = try arena.alloc(u16, metadata.all_versions.len);

0 commit comments

Comments
 (0)