Skip to content

Don't record LDFLAGS in the installed package ld-options - #138

Open
seb128 wants to merge 2 commits into
xmonad:masterfrom
seb128:no-ldflag-record
Open

seb128 wants to merge 2 commits into
xmonad:masterfrom
seb128:no-ldflag-record

Conversation

@seb128

@seb128 seb128 commented Oct 8, 2026

Copy link
Copy Markdown

The ld-options of X11.buildinfo end up in the registered package and are used whenever something links against X11, including the temporary shared objects GHC links to run Template Haskell. Including the LDFLAGS used to build X11 there leaks the build environment of X11 to all its reverse dependencies.

On Ubuntu, where the default LDFLAGS include -Wl,-Bsymbolic-functions, that option is appended after the -Wl,-Bsymbolic GHC uses to link shared objects and overrides it. Data symbols (closures) then become preemptible and the R_X86_64_PC32 relocations emitted by the native code generator fail to link, e.g. when building taffybar:

relocation R_X86_64_PC32 against symbol `..._closure' can not be used
when making a shared object; recompile with -fPIC

The X library search path found by configure is still recorded via X_LIBS and extra-lib-dirs. Link flags meant for building X11 itself can be passed through the usual Cabal options (e.g. --ld-option or --ghc-options=-optl...), which is what distribution tooling such as Debian's haskell-devscripts already does.

The ld-options of X11.buildinfo end up in the registered package and are
used whenever something links against X11, including the temporary
shared objects GHC links to run Template Haskell. Including the LDFLAGS
used to build X11 there leaks the build environment of X11 to all its
reverse dependencies.

On Ubuntu, where the default LDFLAGS include -Wl,-Bsymbolic-functions,
that option is appended after the -Wl,-Bsymbolic GHC uses to link shared
objects and overrides it. Data symbols (closures) then become preemptible
and the R_X86_64_PC32 relocations emitted by the native code generator
fail to link, e.g. when building taffybar:

  relocation R_X86_64_PC32 against symbol `..._closure' can not be used
  when making a shared object; recompile with -fPIC

The X library search path found by configure is still recorded via
X_LIBS and extra-lib-dirs. Link flags meant for building X11 itself can
be passed through the usual Cabal options (e.g. --ld-option or
--ghc-options=-optl...), which is what distribution tooling such as
Debian's haskell-devscripts already does.

@liskin liskin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, although I admit I definitely don't have enough context to foresee all the implications. Seems to me this will ignore LDFLAGS for building the X11 library itself as well, but maybe that's okay?

Looking through GitHub and Google, there are a few other Haskell packages that still include LDFLAGS in their buildinfo, but there are also many that don't and presumably they're fine.

Comment thread X11.buildinfo.in Outdated
@@ -3,6 +3,6 @@
--
buildable: @BUILD_PACKAGE_BOOL@
cc-options: @X_CFLAGS@ @CPPFLAGS@

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we perhaps drop these as well?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Yes, LDFLAGS no longer apply to linking X11 itself, but Cabal doesn't otherwise use LDFLAGS for GHC links, so this line was the only route. The useful bit, the X library search path found by configure, is still recorded through X_LIBS/extra-lib-dirs. Anyone who needs an extra -L for a non-X library can use --extra-lib-dirs, which is the usual Cabal way.

Good point on CPPFLAGS, same leak, so I pushed a commit dropping it too. The X include path is kept: configure.ac only adds X_CFLAGS/-I$x_includes to CPPFLAGS for its own checks, and AC_PATH_XTRA already puts -I$x_includes in X_CFLAGS.

Same as for LDFLAGS: cc-options are also applied to packages depending on
X11, so recording the CPPFLAGS used at configure time leaks them to the
reverse dependencies.

The X include path is not lost: configure.ac only appends X_CFLAGS and
-I$x_includes to CPPFLAGS for its own checks, and AC_PATH_XTRA already
includes -I$x_includes in X_CFLAGS, which is still recorded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants