[source]

compiler/main/SysTools.hs

Note [How GHC finds toolchain utilities]

[note link]

SysTools.initSysProgs figures out exactly where all the auxiliary programs are, and initialises mutable variables to make it easy to call them. To do this, it makes use of definitions in Config.hs, which is a Haskell file containing variables whose value is figured out by the build system.

Config.hs contains two sorts of things

cGCC,         The *names* of the programs
cCPP            e.g.  cGCC = gcc
cUNLIT                cCPP = gcc -E
etc           They do *not* include paths
cUNLIT_DIR   The *path* to the directory containing unlit, split etc
cSPLIT_DIR   *relative* to the root of the build tree,
                 for use when running *in-place* in a build tree (only)

Another hair-brained scheme for simplifying the current tool location nightmare in GHC: Simon originally suggested using another configuration file along the lines of GCC’s specs file - which is fine except that it means adding code to read yet another configuration file. What I didn’t notice is that the current package.conf is general enough to do this:

Package
{name = “tools”, import_dirs = [], source_dirs = [],
library_dirs = [], hs_libraries = [], extra_libraries = [], include_dirs = [], c_includes = [], package_deps = [], extra_ghc_opts = [“-pgmc/usr/bin/gcc”,”-pgml${topdir}/bin/unlit”, … etc.], extra_cc_opts = [], extra_ld_opts = []}

Which would have the advantage that we get to collect together in one place the path-specific package stuff with the path-specific tool stuff.

End of NOTES

Note [-Bsymbolic assumptions by GHC]

[note link]

GHC has a few assumptions about interaction of relocations in NCG and linker:

  1. -Bsymbolic resolves internal references when the shared library is linked, which is important for performance.
  2. When there is a reference to data in a shared library from the main program, the runtime linker relocates the data object into the main program using an R_*_COPY relocation.
  3. If we used -Bsymbolic, then this results in multiple copies of the data object, because some references have already been resolved to point to the original instance. This is bad!

We work around [3.] for native compiled code by avoiding the generation of R_*_COPY relocations.

Unregisterised compiler can’t evade R_*_COPY relocations easily thus we disable -Bsymbolic linking there.

See related tickets: #4210, #15338