From 77977286d80c9bfb77cbf80989d41c59d66dccf8 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sun, 3 Mar 2024 17:50:31 +0100 Subject: [PATCH] postgresql: move libecpq to lib output This library is used by other packages, so should be in the lib output. By removing unused sections, libecpg will not contain any references to other outputs and thus does not increase the closure for the lib output anymore. This will also help massively when splitting a dev output later. As a side-effect, this also unbreaks pkgsMusl.postgresql_12_jit and pkgsMusl.postgresql_13_jit. For, at least to me, unknown reasons, those build fine now. --- pkgs/servers/sql/postgresql/generic.nix | 42 ++++++++++++++----- .../patches/export-dynamic-darwin-15-.patch | 13 ++++++ 2 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 pkgs/servers/sql/postgresql/patches/export-dynamic-darwin-15-.patch diff --git a/pkgs/servers/sql/postgresql/generic.nix b/pkgs/servers/sql/postgresql/generic.nix index a8610c8e487b..fc6087cde870 100644 --- a/pkgs/servers/sql/postgresql/generic.nix +++ b/pkgs/servers/sql/postgresql/generic.nix @@ -23,7 +23,7 @@ let # JIT , jitSupport - , nukeReferences, patchelf, llvmPackages + , nukeReferences, patchelf, llvmPackages, overrideCC # PL/Python , pythonSupport ? false @@ -43,7 +43,14 @@ let pname = "postgresql"; - stdenv' = if jitSupport then llvmPackages.stdenv else stdenv; + stdenv' = + if jitSupport then + overrideCC llvmPackages.stdenv (llvmPackages.stdenv.cc.override { + # LLVM bintools are not used by default, but are needed to make -flto work below. + bintools = llvmPackages.bintools; + }) + else + stdenv; in stdenv'.mkDerivation (finalAttrs: { inherit version; pname = pname + lib.optionalString jitSupport "-jit"; @@ -53,10 +60,15 @@ let inherit hash; }; + __structuredAttrs = true; + hardeningEnable = lib.optionals (!stdenv'.cc.isClang) [ "pie" ]; outputs = [ "out" "lib" "doc" "man" ]; setOutputFlags = false; # $out retains configureFlags :-/ + outputChecks.lib = { + disallowedReferences = [ "out" "doc" "man" ]; + }; buildInputs = [ zlib @@ -87,9 +99,17 @@ let buildFlags = [ "world" ]; - # Makes cross-compiling work when xml2-config can't be executed on the host. - # Fixed upstream in https://github.com/postgres/postgres/commit/0bc8cebdb889368abdf224aeac8bc197fe4c9ae6 - env.NIX_CFLAGS_COMPILE = lib.optionalString (olderThan "13") "-I${libxml2.dev}/include/libxml2"; + # libpgcommon.a and libpgport.a contain all paths returned by pg_config and are linked + # into all binaries. However, almost no binaries actually use those paths. The following + # flags will remove unused sections from all shared libraries and binaries - including + # those paths. This avoids a lot of circular dependency problems with different outputs, + # and allows splitting them cleanly. + env.CFLAGS = "-fdata-sections -ffunction-sections" + + (if stdenv'.cc.isClang then " -flto" else " -fmerge-constants -Wl,--gc-sections") + + lib.optionalString (stdenv'.isDarwin && jitSupport) " -fuse-ld=lld" + # Makes cross-compiling work when xml2-config can't be executed on the host. + # Fixed upstream in https://github.com/postgres/postgres/commit/0bc8cebdb889368abdf224aeac8bc197fe4c9ae6 + + lib.optionalString (olderThan "13") " -I${libxml2.dev}/include/libxml2"; configureFlags = [ "--with-openssl" @@ -106,7 +126,10 @@ let ++ lib.optionals gssSupport [ "--with-gssapi" ] ++ lib.optionals pythonSupport [ "--with-python" ] ++ lib.optionals jitSupport [ "--with-llvm" ] - ++ lib.optionals stdenv'.isLinux [ "--with-pam" ]; + ++ lib.optionals stdenv'.isLinux [ "--with-pam" ] + # This could be removed once the upstream issue is resolved: + # https://postgr.es/m/flat/427c7c25-e8e1-4fc5-a1fb-01ceff185e5b%40technowledgy.de + ++ lib.optionals (stdenv'.isDarwin && atLeast "16") [ "LDFLAGS_EX_BE=-Wl,-export_dynamic" ]; patches = [ (if atLeast "16" then ./patches/relative-to-symlinks-16+.patch else ./patches/relative-to-symlinks.patch) @@ -123,6 +146,8 @@ let map fetchurl (lib.attrValues muslPatches) ) ++ lib.optionals stdenv'.isLinux [ (if atLeast "13" then ./patches/socketdir-in-run-13+.patch else ./patches/socketdir-in-run.patch) + ] ++ lib.optionals (stdenv'.isDarwin && olderThan "16") [ + ./patches/export-dynamic-darwin-15-.patch ]; installTargets = [ "install-world" ]; @@ -137,7 +162,6 @@ let '' moveToOutput "lib/libpgcommon*.a" "$out" moveToOutput "lib/libpgport*.a" "$out" - moveToOutput "lib/libecpg*" "$out" # Prevent a retained dependency on gcc-wrapper. substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/ld ld @@ -254,9 +278,7 @@ let # resulting LLVM IR isn't platform-independent this doesn't give you much. # In fact, I tried to test the result in a VM-test, but as soon as JIT was used to optimize # a query, postgres would coredump with `Illegal instruction`. - broken = (jitSupport && stdenv.hostPlatform != stdenv.buildPlatform) - # Allmost all tests fail FATAL errors for v12 and v13 - || (jitSupport && stdenv.hostPlatform.isMusl && olderThan "14"); + broken = jitSupport && !stdenv.hostPlatform.canExecute stdenv.buildPlatform; }; }); diff --git a/pkgs/servers/sql/postgresql/patches/export-dynamic-darwin-15-.patch b/pkgs/servers/sql/postgresql/patches/export-dynamic-darwin-15-.patch new file mode 100644 index 000000000000..fa0f4be4de7f --- /dev/null +++ b/pkgs/servers/sql/postgresql/patches/export-dynamic-darwin-15-.patch @@ -0,0 +1,13 @@ +See https://postgr.es/m/eb249761-56e2-4e42-a2c5-b9ae18c1ca1f%40technowledgy.de +--- +--- a/src/makefiles/Makefile.darwin ++++ b/src/makefiles/Makefile.darwin +@@ -5,6 +5,8 @@ DLSUFFIX = .so + # env var name to use in place of LD_LIBRARY_PATH + ld_library_path_var = DYLD_LIBRARY_PATH + ++export_dynamic = -Wl,-export_dynamic ++ + ifdef PGXS + BE_DLLLIBS = -bundle_loader $(bindir)/postgres + else