driver: skip -Bsymbolic on unregisterised targets (Trac #15338)

Authored by trofi on Jul 16 2018, 3:38 PM.


driver: skip -Bsymbolic on unregisterised targets (Trac Trac #15338)

Trac Trac #15338 is yet another example where -Bsymbolic breaks
semantics of a C program: global variable duplication happens
and unsafePerformIO creates two stdout copies.

When -Bsymbolic is not used both C compiler and linker agree
on how global variables are handled. In case of sh4 it consists
on a few assertions:

  1. global variable is exported from shared library
  2. code is referred to this variable via GOT-like mechanism to allow interposition
  3. global variable is present .bss section on an executable (as an R_*_COPY relocation: symbol contents is copied at executable startup time)
  4. and symbol in executable interposes symbol in shared library.

This way both code in shared library and code in executable refer
to a copy of global variable in .bss section of an executable.

Unfortunately -Bsymbolic option breaks assumption [2.] and generates
direct references to the symbol. This causes mismatch between
values seen from executable and values seen from shared library code.

This change disables '-Bsymbolic' for unregisterised targets.

Signed-off-by: Sergei Trofimovich <>

Test Plan: test 'ghc-pkg --version | cat' to emit data

Reviewers: simonmar, bgamari, jrtc27

Reviewed By: jrtc27

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: Trac #15338

Differential Revision: