From c1f805b8569d1f66aed813a3b49820936618c9d5 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Mon, 29 Sep 2025 01:46:40 +0300 Subject: [PATCH] packaging: Build without symbolic interposition on GCC This turns out to be a big problem for performance of Bison generated code, that for whatever reason cannot be made internal to the shared library. This causes GCC to make a bunch of function calls go through PLT. Ideally these hot functions (like move/copy ctor) could become inline in upstream Bison. That will make sure that GCC can do interprocedular optimizations without -fno-semantic-interposition [^]. Considering that LLVM already does inlining and whatnot is a good motivation for this change. I don't know of any case where Nix relies on LD_PRELOAD tricks for the shared libraries in production use-cases. [^]: https://maskray.me/blog/2021-05-09-fno-semantic-interposition --- packaging/components.nix | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packaging/components.nix b/packaging/components.nix index b5fad4043..2be4fa61d 100644 --- a/packaging/components.nix +++ b/packaging/components.nix @@ -164,6 +164,24 @@ let }; mesonLibraryLayer = finalAttrs: prevAttrs: { + preConfigure = + let + interpositionFlags = [ + "-fno-semantic-interposition" + "-Wl,-Bsymbolic-functions" + ]; + in + # NOTE: By default GCC disables interprocedular optimizations (in particular inlining) for + # position-independent code and thus shared libraries. + # Since LD_PRELOAD tricks aren't worth losing out on optimizations, we disable it for good. + # This is not the case for Clang, where inlining is done by default even without -fno-semantic-interposition. + # https://reviews.llvm.org/D102453 + # https://fedoraproject.org/wiki/Changes/PythonNoSemanticInterpositionSpeedup + prevAttrs.preConfigure or "" + + lib.optionalString stdenv.cc.isGNU '' + export CFLAGS="''${CFLAGS:-} ${toString interpositionFlags}" + export CXXFLAGS="''${CXXFLAGS:-} ${toString interpositionFlags}" + ''; outputs = prevAttrs.outputs or [ "out" ] ++ [ "dev" ]; };