diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index b4736bc960fa..6d8b9a0a7593 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -134,6 +134,7 @@ let else if targetPlatform.isLoongArch64 then "${sharedLibraryLoader}/lib/ld-linux-loongarch*.so.1" else if targetPlatform.isDarwin then "/usr/lib/dyld" else if targetPlatform.isFreeBSD then "${sharedLibraryLoader}/libexec/ld-elf.so.1" + else if targetPlatform.isOpenBSD then "${sharedLibraryLoader}/libexec/ld.so" else if hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1" else ""; diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/libc.nix b/pkgs/os-specific/bsd/openbsd/pkgs/libc.nix index 895b82ed5307..db49e28ec7e3 100644 --- a/pkgs/os-specific/bsd/openbsd/pkgs/libc.nix +++ b/pkgs/os-specific/bsd/openbsd/pkgs/libc.nix @@ -1,11 +1,13 @@ { lib, + stdenvNoLibc, symlinkJoin, libcMinimal, librthread, libm, librpcsvc, libutil, + rtld, version, }: @@ -27,13 +29,16 @@ symlinkJoin rec { (lib.getLib p) (lib.getMan p) ]) - [ - libcMinimal - libm - librthread - librpcsvc - libutil - ]; + ( + [ + libcMinimal + libm + librthread + librpcsvc + libutil + ] + ++ (lib.optional (!stdenvNoLibc.hostPlatform.isStatic) rtld) + ); postBuild = '' rm -r "$out/nix-support" diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/openbsdSetupHook/setup-hook.sh b/pkgs/os-specific/bsd/openbsd/pkgs/openbsdSetupHook/setup-hook.sh index e06dbda37c40..dbd016fcb59c 100644 --- a/pkgs/os-specific/bsd/openbsd/pkgs/openbsdSetupHook/setup-hook.sh +++ b/pkgs/os-specific/bsd/openbsd/pkgs/openbsdSetupHook/setup-hook.sh @@ -1,6 +1,11 @@ addOpenBSDMakeFlags() { prependToVar makeFlags "INCSDIR=${!outputDev}/include" prependToVar makeFlags "MANDIR=${!outputMan}/share/man" + # Variables are used to declare dependencies, but we handle them with cc-wrapper + prependToVar makeFlags "CRTBEGIN=" + prependToVar makeFlags "CRTEND=" + prependToVar makeFlags "LIBCRT0=" + prependToVar makeFlags "LIBC=" } fixOpenBSDInstallDirs() { diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/rtld/ldso-fix-makefile.patch b/pkgs/os-specific/bsd/openbsd/pkgs/rtld/ldso-fix-makefile.patch new file mode 100644 index 000000000000..b6155539e84c --- /dev/null +++ b/pkgs/os-specific/bsd/openbsd/pkgs/rtld/ldso-fix-makefile.patch @@ -0,0 +1,57 @@ +diff --git a/libexec/ld.so/Makefile b/libexec/ld.so/Makefile +index 7f8f6ef2961..469c34bb6de 100644 +--- a/libexec/ld.so/Makefile ++++ b/libexec/ld.so/Makefile +@@ -1,6 +1,5 @@ + # $OpenBSD: Makefile,v 1.88 2024/04/05 13:51:47 deraadt Exp $ + +-SUBDIR=ldconfig ldd + MAN= ld.so.1 + + .include +@@ -70,21 +69,15 @@ ELF_LDFLAGS+=--shared -Bsymbolic --no-undefined + + .ifdef RELATIVE_RELOC + CHECK_LDSO=c() { \ +- ! readelf -Wr $$1 | \ ++ ! $(READELF) -Wr $$1 | \ + egrep -qv '^($$|[ R])| (${RELATIVE_RELOC}) '; \ + }; c + .endif + +-test_prog= test-$(PROG) +-CLEANFILES+= test-$(PROG) + candidate= $(PROG).test + CLEANFILES+= ${candidate} + +-$(test_prog): +- printf '#include \n#include \nint main(int argc, char **argv){ pthread_attr_t attr; printf("%%s: ", argv[0]); pthread_attr_init(&attr); printf("%%s!\\n", argv[1] ? argv[1] : "foo"); }\n' | \ +- $(CC) -P -x c - -Wl,-dynamic-linker,./$(candidate) -o $@ -lpthread +- +-$(PROG): $(test_prog) ${VERSION_SCRIPT} $(OBJS) ${LD_SCRIPT} ++$(PROG): ${VERSION_SCRIPT} $(OBJS) ${LD_SCRIPT} + .if defined(SYSPATCH_PATH) + $(LD) -e _dl_start $(ELF_LDFLAGS) -o $(candidate) \ + `readelf -Ws ${SYSPATCH_PATH}/usr/libexec/${.TARGET} | \ +@@ -96,9 +89,6 @@ $(PROG): $(test_prog) ${VERSION_SCRIPT} $(OBJS) ${LD_SCRIPT} + .endif + .ifdef CHECK_LDSO + ${CHECK_LDSO} $(candidate) +-.endif +-.ifndef CROSSDIR +- ulimit -c 0; [ "`${.OBJDIR}/$(test_prog) ok`" = "${.OBJDIR}/$(test_prog): ok!" ] + .endif + cp $(candidate) $@ + .endif +@@ -113,10 +103,4 @@ CLEANFILES+= ld.so.a + all: ld.so.a + + ld.so.a: ${OBJS} ${.CURDIR}/Symbols.map ${test_prog} ${LD_SCRIPT} +- ar cqD $@ $? +- +-afterinstall: ld.so.a +- install -d -o root -g wheel -m 755 \ +- ${DESTDIR}/usr/share/relink/usr/libexec +- install -o ${BINOWN} -g ${BINGRP} -m ${NONBINMODE} \ +- ld.so.a ${DESTDIR}/usr/share/relink/usr/libexec/ld.so.a ++ $(AR) cqD $@ $? diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/rtld/package.nix b/pkgs/os-specific/bsd/openbsd/pkgs/rtld/package.nix new file mode 100644 index 000000000000..58fd1fd8ebd4 --- /dev/null +++ b/pkgs/os-specific/bsd/openbsd/pkgs/rtld/package.nix @@ -0,0 +1,31 @@ +{ + lib, + mkDerivation, +}: + +mkDerivation { + path = "libexec/ld.so"; + extraPaths = [ + "lib/libc/string" + "lib/csu/os-note-elf.h" + ]; + patches = [ + ./ldso-fix-makefile.patch + ]; + + libcMinimal = true; + + NIX_CFLAGS_COMPILE = "-Wno-error"; + + # DESTDIR is overridden in bsdSetupHook, just fixup afterwards + postInstall = '' + mv $out/bin $out/libexec + ''; + + outputs = [ + "out" + "man" + ]; + + meta.platforms = lib.platforms.openbsd; +}