[GHC] #9873: Use CONF_GCC_LINKER_OPTS_STAGE2 only in stage2

GHC ghc-devs at haskell.org
Mon Dec 8 19:32:22 UTC 2014


#9873: Use CONF_GCC_LINKER_OPTS_STAGE2 only in stage2
-------------------------------------+-------------------------------------
       Reporter:  nomeata            |                   Owner:
           Type:  bug                |                  Status:  new
       Priority:  normal             |               Milestone:
      Component:  Build System       |                 Version:  7.9
       Keywords:                     |        Operating System:
   Architecture:  Unknown/Multiple   |  Unknown/Multiple
     Difficulty:  Unknown            |         Type of failure:
     Blocked By:                     |  None/Unknown
Related Tickets:                     |               Test Case:
                                     |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
 On ARM, we want to make sure that GHC uses the gold linker.

 In order to achieve that, we need to get `-fuse-ld=gold` into
 SettingsCCompilerLinkFlags in the settings.

 This field is filled with only CONF_GCC_LINKER_OPTS_STAGE2. So we want
 that
 flag to show up there.

 But this variable is used in other places as well. For example, the
 configuration of tinfo fails:

 {{{
 $ make libraries/terminfo/dist-boot/package-data.mk
 ===--- building phase 0
 make -r --no-print-directory -f ghc.mk phase=0 phase_0_builds
 libraries/terminfo/ghc.mk:3: libraries/terminfo/dist-boot/package-data.mk:
 Datei oder Verzeichnis nicht gefunden
 "inplace/bin/ghc-cabal" configure libraries/terminfo dist-boot "" --with-
 ghc="/usr/bin/ghc" --with-ghc-pkg="/usr/bin/ghc-pkg"  --package-
 db=/home/jojo/build/haskell/ghc/libraries/bootstrapping.conf --disable-
 library-for-ghci --enable-library-vanilla --disable-library-profiling
 --disable-shared --with-hscolour="/usr/bin/HsColour" --configure-
 option=CFLAGS=" -fno-stack-protector   " --configure-option=LDFLAGS="
 -fuse-ld=gold  " --configure-option=CPPFLAGS="   " --gcc-options=" -fno-
 stack-protector     -fuse-ld=gold  "   --constraint "binary == 0.7.1.0"
 --constraint "Cabal == 1.21.1.0"   --constraint "hpc == 0.6.0.2"
 --constraint "bin-package-db == 0.0.0.0"   --constraint "hoopl ==
 3.10.0.2"   --constraint "transformers == 0.4.2.0"   --constraint
 "terminfo == 0.4.0.0" --with-gcc="/usr/bin/gcc" --configure-option=--with-
 cc="/usr/bin/gcc" --with-ar="/usr/bin/ar" --with-alex="/usr/bin/alex"
 --with-happy="/usr/bin/happy"
 Configuring terminfo-0.4.0.0...
 configure: WARNING: unrecognized options: --with-compiler, --with-gcc
 checking for gcc... /usr/bin/gcc
 checking whether the C compiler works... yes
 checking for C compiler default output file name... a.out
 checking for suffix of executables...
 checking whether we are cross compiling... no
 checking for suffix of object files... o
 checking whether we are using the GNU C compiler... yes
 checking whether /usr/bin/gcc accepts -g... yes
 checking for /usr/bin/gcc option to accept ISO C89... none needed
 checking how to run the C preprocessor... /usr/bin/gcc -E
 checking for grep that handles long lines and -e... /bin/grep
 checking for egrep... /bin/grep -E
 checking for ANSI C header files... yes
 checking for sys/types.h... yes
 checking for sys/stat.h... yes
 checking for stdlib.h... yes
 checking for string.h... yes
 checking for memory.h... yes
 checking for strings.h... yes
 checking for inttypes.h... yes
 checking for stdint.h... yes
 checking for unistd.h... yes
 checking ncurses.h usability... yes
 checking ncurses.h presence... yes
 checking for ncurses.h... yes
 checking for setupterm in -ltinfo... yes
 configure: creating ./config.status
 config.status: creating terminfo.buildinfo
 configure: WARNING: unrecognized options: --with-compiler, --with-gcc
 ghc-cabal: Missing dependency on a foreign library:
 * Missing C library: tinfo
 This problem can usually be solved by installing the system package that
 provides this library (you may need the "-dev" version). If the library is
 already installed but in a non-standard location then you can use the
 flags
 --extra-include-dirs= and --extra-lib-dirs= to specify where it is.
 libraries/terminfo/ghc.mk:3: recipe for target 'libraries/terminfo/dist-
 boot/package-data.mk' failed
 make[1]: *** [libraries/terminfo/dist-boot/package-data.mk] Error 1
 Makefile:71: recipe for target 'libraries/terminfo/dist-boot/package-
 data.mk' failed
 make: *** [libraries/terminfo/dist-boot/package-data.mk] Error 2
 }}}

 The problem (unfortunately, not very visible) is that `ghc-cabal` calls
 `gcc` to test if the C libaries are available. It uses the linker flags
 that it’s being told to use from the host GHC (here: 7.6.3), which
 contains the usual:
 {{{
 $ ghc --info |fgrep 'C compiler flags'
  ,("C compiler flags"," -fno-stack-protector  -Wl,--hash-size=31 -Wl
 ,--reduce-memory-overheads")
 }}}

 But to that it adds `-fuse-ld-gold` because `ghc-cabal` is gets `" --gcc-
 options=" -fno-stack-protector     -fuse-ld=gold  "` passed.

 So the build system should not pass flags from
 `CONF_GCC_LINKER_OPTS_STAGE2` anywhere besides gcc when used *by the stage
 2 ghc* during linking.

 The chain of variables leading to this can be seen here:
 {{{
 $ git grep CONFIGURE_LDFLAGS
 rules/build-package-data.mk:$1_$2_CONFIGURE_LDFLAGS = $$(SRC_LD_OPTS)
 $$(CONF_GCC_LINKER_OPTS_STAGE$3) $$($1_LD_OPTS) $$($1_$2_LD_OPTS)
 rules/build-package-data.mk:$1_$2_CONFIGURE_OPTS += --configure-
 option=LDFLAGS="$$($1_$2_CONFIGURE_LDFLAGS)"
 rules/build-package-data.mk:$1_$2_CONFIGURE_OPTS += --gcc-
 options="$$($1_$2_CONFIGURE_CFLAGS) $$($1_$2_CONFIGURE_LDFLAGS)"
 }}}

 I’m currently experimenting with a patch that simply does not use
 `CONF_GCC_LINKER_OPTS_STAGE` anywhere besides when defining
 `SettingsCCompilerLinkFlags`, but I’m afraid that this might introduce new
 unwanted behaviour. But since `ghc-cabal` reads gcc-flags from `ghc
 --info`, maybe that channel of information is sufficient.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9873>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list