authorgravatar for directmusic94@gmail.comJoseph Lyncheski <directmusic94@gmail.com> 2026-07-14 14:29:39-05:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-26 13:15:36+02:00
logc269a604b66005cd089cb7e84d91bcfa5333edaf
tree9c52c11aecbcb905355621ea496118cb616ce3ae
parent78e3b1c7383bf7126876b6367192aef17d3d92b9

fix: crtbegin/crtend not being linked on linux (#32064)


1 files changed, 16 insertions(+), 2 deletions(-)

lib/std/zig/LibCInstallation.zig+16-2
......@@ -225,7 +225,10 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib
225225 try self.findNativeIncludeDirPosix(gpa, io, args);
226226 switch (builtin.target.os.tag) {
227227 .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try gpa.dupe(u8, "/usr/lib"),
228 .linux => try self.findNativeCrtDirPosix(gpa, io, args),
228 .linux => {
229 try self.findNativeCrtDirPosix(gpa, io, args);
230 try self.findNativeGccDirPosix(gpa, io, args);
231 },
229232 else => {},
230233 }
231234 } else {
......@@ -760,26 +763,36 @@ pub const CrtBasenames = struct {
760763 .linux => switch (mode) {
761764 .dynamic_lib => .{
762765 .crti = "crti.o",
766 .crtbegin = "crtbeginS.o",
767 .crtend = "crtendS.o",
763768 .crtn = "crtn.o",
764769 },
765770 .dynamic_exe => .{
766771 .crt0 = "crt1.o",
767772 .crti = "crti.o",
773 .crtbegin = "crtbegin.o",
774 .crtend = "crtend.o",
768775 .crtn = "crtn.o",
769776 },
770777 .dynamic_pie => .{
771778 .crt0 = "Scrt1.o",
772779 .crti = "crti.o",
780 .crtbegin = "crtbeginS.o",
781 .crtend = "crtendS.o",
773782 .crtn = "crtn.o",
774783 },
775784 .static_exe => .{
776785 .crt0 = "crt1.o",
777786 .crti = "crti.o",
787 .crtbegin = "crtbegin.o",
788 .crtend = "crtend.o",
778789 .crtn = "crtn.o",
779790 },
780791 .static_pie => .{
781792 .crt0 = "rcrt1.o",
782793 .crti = "crti.o",
794 .crtbegin = "crtbeginS.o",
795 .crtend = "crtendS.o",
783796 .crtn = "crtn.o",
784797 },
785798 },
......@@ -994,6 +1007,7 @@ pub fn resolveCrtPaths(
9941007 .root_dir = Cache.Directory.cwd(),
9951008 .sub_path = lci.crt_dir orelse return error.LibCInstallationMissingCrtDir,
9961009 };
1010
9971011 switch (target.os.tag) {
9981012 .dragonfly => {
9991013 const gccv: []const u8 = if (target.os.version_range.semver.isAtLeast(.{
......@@ -1015,7 +1029,7 @@ pub fn resolveCrtPaths(
10151029 .crtn = if (crt_basenames.crtn) |basename| try crt_dir_path.join(arena, basename) else null,
10161030 };
10171031 },
1018 .haiku, .serenity => {
1032 .haiku, .serenity, .linux => {
10191033 const gcc_dir_path: Path = .{
10201034 .root_dir = Cache.Directory.cwd(),
10211035 .sub_path = lci.gcc_dir orelse return error.LibCInstallationMissingCrtDir,