Skip to content

Commit 3699cb3

Browse files
committed
Work around GHC 9.6 problem with -fplugin while linking
1 parent baf6f8e commit 3699cb3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

haskell/private/actions/link.bzl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,23 @@ def link_binary(
136136
args.add_all(hs.toolchain.ghcopts)
137137
args.add_all(compiler_flags)
138138

139+
# NOTE When linking, GHC < 9.6 ignores -fplugin= arguments.
140+
#
141+
# GHC >= 9.6, however, tries to locate a package providing the given module.
142+
#
143+
# Failing to find a corresponding package it tries to find a source file with
144+
# the given name and .hs, .lhs, .hsig or .lhsig extension.
145+
#
146+
# Passing appropriate -package-db and -plugin-package-id flags for
147+
# the given plugin causes GHC to try building a dynamic library instead of
148+
# an executable which fails in the linking step with:
149+
#
150+
# > error: main2.o: requires unsupported dynamic reloc 11; recompile with -fPIC
151+
#
152+
# Since compilation is already done at this stage, we simply clear all plugins
153+
# here so they do not have any effect.
154+
args.add("-fclear-plugins")
155+
139156
# By default, GHC will produce mostly-static binaries, i.e. in which all
140157
# Haskell code is statically linked and foreign libraries and system
141158
# dependencies are dynamically linked. If linkstatic is false, i.e. the user
@@ -351,6 +368,18 @@ def link_library_dynamic(hs, cc, posix, dep_info, extra_srcs, object_files, my_p
351368
args.add_all(["-shared", "-dynamic"])
352369
args.add_all(hs.toolchain.ghcopts)
353370
args.add_all(compiler_flags)
371+
372+
# NOTE When linking, GHC < 9.6 ignores -fplugin= arguments.
373+
#
374+
# GHC >= 9.6, however, tries to locate a package providing the given module.
375+
#
376+
# Failing to find a corresponding package it tries to find a source file with
377+
# the given name and .hs, .lhs, .hsig or .lhsig extension.
378+
#
379+
# Since compilation is already done at this stage, we simply clear all plugins
380+
# here so they do not have any effect.
381+
args.add("-fclear-plugins")
382+
354383
extra_prefix = empty_lib_prefix
355384

356385
(pkg_info_inputs, pkg_info_args) = pkg_info_to_compile_flags(

0 commit comments

Comments
 (0)