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...@@ -225,7 +225,10 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib
225 try self.findNativeIncludeDirPosix(gpa, io, args);225 try self.findNativeIncludeDirPosix(gpa, io, args);
226 switch (builtin.target.os.tag) {226 switch (builtin.target.os.tag) {
227 .freebsd, .netbsd, .openbsd, .dragonfly => self.crt_dir = try gpa.dupe(u8, "/usr/lib"),227 .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 },
229 else => {},232 else => {},
230 }233 }
231 } else {234 } else {
...@@ -760,26 +763,36 @@ pub const CrtBasenames = struct {...@@ -760,26 +763,36 @@ pub const CrtBasenames = struct {
760 .linux => switch (mode) {763 .linux => switch (mode) {
761 .dynamic_lib => .{764 .dynamic_lib => .{
762 .crti = "crti.o",765 .crti = "crti.o",
766 .crtbegin = "crtbeginS.o",
767 .crtend = "crtendS.o",
763 .crtn = "crtn.o",768 .crtn = "crtn.o",
764 },769 },
765 .dynamic_exe => .{770 .dynamic_exe => .{
766 .crt0 = "crt1.o",771 .crt0 = "crt1.o",
767 .crti = "crti.o",772 .crti = "crti.o",
773 .crtbegin = "crtbegin.o",
774 .crtend = "crtend.o",
768 .crtn = "crtn.o",775 .crtn = "crtn.o",
769 },776 },
770 .dynamic_pie => .{777 .dynamic_pie => .{
771 .crt0 = "Scrt1.o",778 .crt0 = "Scrt1.o",
772 .crti = "crti.o",779 .crti = "crti.o",
780 .crtbegin = "crtbeginS.o",
781 .crtend = "crtendS.o",
773 .crtn = "crtn.o",782 .crtn = "crtn.o",
774 },783 },
775 .static_exe => .{784 .static_exe => .{
776 .crt0 = "crt1.o",785 .crt0 = "crt1.o",
777 .crti = "crti.o",786 .crti = "crti.o",
787 .crtbegin = "crtbegin.o",
788 .crtend = "crtend.o",
778 .crtn = "crtn.o",789 .crtn = "crtn.o",
779 },790 },
780 .static_pie => .{791 .static_pie => .{
781 .crt0 = "rcrt1.o",792 .crt0 = "rcrt1.o",
782 .crti = "crti.o",793 .crti = "crti.o",
794 .crtbegin = "crtbeginS.o",
795 .crtend = "crtendS.o",
783 .crtn = "crtn.o",796 .crtn = "crtn.o",
784 },797 },
785 },798 },
...@@ -994,6 +1007,7 @@ pub fn resolveCrtPaths(...@@ -994,6 +1007,7 @@ pub fn resolveCrtPaths(
994 .root_dir = Cache.Directory.cwd(),1007 .root_dir = Cache.Directory.cwd(),
995 .sub_path = lci.crt_dir orelse return error.LibCInstallationMissingCrtDir,1008 .sub_path = lci.crt_dir orelse return error.LibCInstallationMissingCrtDir,
996 };1009 };
1010
997 switch (target.os.tag) {1011 switch (target.os.tag) {
998 .dragonfly => {1012 .dragonfly => {
999 const gccv: []const u8 = if (target.os.version_range.semver.isAtLeast(.{1013 const gccv: []const u8 = if (target.os.version_range.semver.isAtLeast(.{
...@@ -1015,7 +1029,7 @@ pub fn resolveCrtPaths(...@@ -1015,7 +1029,7 @@ pub fn resolveCrtPaths(
1015 .crtn = if (crt_basenames.crtn) |basename| try crt_dir_path.join(arena, basename) else null,1029 .crtn = if (crt_basenames.crtn) |basename| try crt_dir_path.join(arena, basename) else null,
1016 };1030 };
1017 },1031 },
1018 .haiku, .serenity => {1032 .haiku, .serenity, .linux => {
1019 const gcc_dir_path: Path = .{1033 const gcc_dir_path: Path = .{
1020 .root_dir = Cache.Directory.cwd(),1034 .root_dir = Cache.Directory.cwd(),
1021 .sub_path = lci.gcc_dir orelse return error.LibCInstallationMissingCrtDir,1035 .sub_path = lci.gcc_dir orelse return error.LibCInstallationMissingCrtDir,