pkgsStatic.{libpq,postgresql}: fix linking against libpq.a

This can be observed when building
haskellPackages.postgresql-libpq-pkgconfig. This is currently pinned to
postgresql_16 in pkgsStatic, but when unpinning it, it will fail with
the mentioned error on master. With this fix, it successfully builds
with postgresql_17 / libpq.
This commit is contained in:
Wolfgang Walther
2025-04-05 20:00:14 +02:00
parent dd5fd6cc22
commit 9f3bea8dca
2 changed files with 18 additions and 0 deletions
+9
View File
@@ -288,6 +288,15 @@ let
# those paths. This avoids a lot of circular dependency problems with different outputs,
# and allows splitting them cleanly.
CFLAGS = "-fdata-sections -ffunction-sections -flto";
# This flag was introduced upstream in:
# https://github.com/postgres/postgres/commit/b6c7cfac88c47a9194d76f3d074129da3c46545a
# It causes errors when linking against libpq.a in pkgsStatic:
# undefined reference to `pg_encoding_to_char'
# Unsetting the flag fixes it. The upstream reasoning to introduce it is about the risk
# to have initdb load a libpq.so from a different major version and how to avoid that.
# This doesn't apply to us with Nix.
NIX_CFLAGS_COMPILE = "-UUSE_PRIVATE_ENCODING_FUNCS";
}
// lib.optionalAttrs perlSupport { PERL = lib.getExe perl; }
// lib.optionalAttrs pythonSupport { PYTHON = lib.getExe python3; }
+9
View File
@@ -91,6 +91,15 @@ stdenv.mkDerivation (finalAttrs: {
"-fdata-sections -ffunction-sections"
+ (if stdenv.cc.isClang then " -flto" else " -fmerge-constants -Wl,--gc-sections");
# This flag was introduced upstream in:
# https://github.com/postgres/postgres/commit/b6c7cfac88c47a9194d76f3d074129da3c46545a
# It causes errors when linking against libpq.a in pkgsStatic:
# undefined reference to `pg_encoding_to_char'
# Unsetting the flag fixes it. The upstream reasoning to introduce it is about the risk
# to have initdb load a libpq.so from a different major version and how to avoid that.
# This doesn't apply to us with Nix.
env.NIX_CFLAGS_COMPILE = "-UUSE_PRIVATE_ENCODING_FUNCS";
configureFlags =
[
"--enable-debug"