Opened 13 months ago

Closed 12 months ago

Last modified 7 weeks ago

#12759 closed bug (fixed)

Latest Debian GCC breaks GHC

Reported by: erikd Owned by:
Priority: normal Milestone: 8.0.2
Component: Compiler Version: 8.0.1
Keywords: Cc: bgamari, slyfox
Operating System: Linux Architecture: Unknown/Multiple
Type of failure: Other Test Case:
Blocked By: Blocking:
Related Tickets: #12755, #11834, #9007 Differential Rev(s): Phab:D2707
Wiki Page:

Description

Just got gcc (Debian 6.2.0-9) 6.2.0 20161019 in a recent upgrade (Debian Testing) and now:

> cat hello.hs 
main :: IO ()
main = putStrLn "Hello"

> ghc hello.hs -o hello
[1 of 1] Compiling Main             ( hello.hs, hello.o )
Linking hello ...
/usr/bin/ld: hello.o: relocation R_X86_64_32S against symbol `stg_bh_upd_frame_info' \
can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/lib/ghc-8.0/lib/base-4.9.0.0/libHSbase-4.9.0.0.a(Base__166.o): \
relocation R_X86_64_32S against symbol `stg_bh_upd_frame_info' can not be used when \
making a shared object; recompile with -fPIC
....

The previous version of gcc in Debian Testing (gcc (Debian 6.2.0-6) 6.2.0 20161010) is fine.

Attachments (1)

_log.txt.xz (204.6 KB) - added by msuchanek 6 months ago.
log of failed ghc build

Download all attachments as: .zip

Change History (27)

comment:2 Changed 13 months ago by erikd

Debain allows parallel installs of GCC, so for now I've worked around this issue by switching the default compiler to gcc-5 (gcc-5 (Debian 5.4.1-3) 5.4.1 20161019).

comment:3 Changed 13 months ago by George

Summary: Latest Debian GCC breajs GHCLatest Debian GCC breaks GHC

comment:4 Changed 13 months ago by erikd

The Debian package for GHC 8.0 now carries two patches:

--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -3631,14 +3631,8 @@
 default_PIC :: Platform -> [GeneralFlag]
 default_PIC platform =
   case (platformOS platform, platformArch platform) of
-    (OSDarwin, ArchX86_64) -> [Opt_PIC]
-    (OSOpenBSD, ArchX86_64) -> [Opt_PIC] -- Due to PIE support in
-                                         -- OpenBSD since 5.3 release
-                                         -- (1 May 2013) we need to
-                                         -- always generate PIC. See
-                                         -- #10597 for more
-                                         -- information.
-    _                      -> []
+    (OSLinux, ArchPPC)     -> []
+    _                      -> [Opt_PIC]
 
 -- General flags that are switched on/off when other general flags are switched
 -- on

and

Description: Pass -no-pie along with -Wl,-r
 GHC uncoditionally passes `-Wl,-r' to gcc in `compiler/main/DriverPipeline.hs'.
 This fails in cases where PIE is enabled by default with the following error:
 .
   /usr/bin/ld: -r and -pie may not be used together
 .
 Fix the above error by passing `-no-pie' along with `-Wl,-r' to the compiler.
Author: Ilias Tsitsimpis <i.tsitsimpis@gmail.com>
Bug: https://ghc.haskell.org/trac/ghc/ticket/11834
Bug-Debian: https://bugs.debian.org/712228
Forwarded: no

Index: b/compiler/main/DriverPipeline.hs
===================================================================
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -2145,7 +2145,8 @@ joinObjectFiles dflags o_files output_fn
       osInfo = platformOS (targetPlatform dflags)
       ld_r args cc = SysTools.runLink dflags ([
                        SysTools.Option "-nostdlib",
-                       SysTools.Option "-Wl,-r"
+                       SysTools.Option "-Wl,-r",
+                       SysTools.Option "-no-pie"
                      ]
                      ++ (if any (cc ==) [Clang, AppleClang, AppleClang51]
                           then []

Obviously these patches, in their current state, are not suitable for inclusion in GHC. It looks like the use of PIC and PIE needs to be detected at configure/compile time.

comment:5 Changed 13 months ago by erikd

With the above two patches, over 100 of the tests in the testsuie fail (mostly the TH related tests).

Dropping those patches and configuring GHC as suggested by @hvr:

./configure \
    CONF_CC_OPTS_STAGE2=-fno-PIE \
    CONF_GCC_LINKER_OPTS_STAGE2=-no-pie \
    CONF_LD_LINKER_OPTS_STAGE2=-no-pie

results in a GHC that passes all tests.

comment:6 Changed 13 months ago by clint

-fno-PIE causes things using hsc2hs to break horribly

comment:7 Changed 13 months ago by bgamari

Cc: bgamari added

I am also seeing this now.

comment:8 Changed 13 months ago by erikd

I grabbed the source for "magic", unpacked them and tried to build them. hsc2hs failed so I added -v to the command line and this is what I got:

> /usr/lib/ghc-8.0/bin/hsc2hs -v '--cc=/usr/bin/gcc' '--ld=/usr/bin/gcc'
  '--cflag=-fno-PIE' '--cflag=-fno-stack-protector' '--lflag=-fno-PIE' 
  '--lflag=-fno-stack-protector' '--cflag=-D__GLASGOW_HASKELL__=800' 
  '--cflag=-Dlinux_BUILD_OS=1' '--cflag=-Dx86_64_BUILD_ARCH=1' 
  '--cflag=-Dlinux_HOST_OS=1' '--cflag=-Dx86_64_HOST_ARCH=1' 
  '--cflag=-Idist/build/autogen''--cflag=-include' 
  '--cflag=dist/build/autogen/cabal_macros.h' '--lflag=-lmagic'
  '--cflag=-I/usr/lib/ghc-8.0/lib/base-4.9.0.0/include'
  '--cflag=-I/usr/lib/ghc-8.0/lib/integer-gmp-1.0.0.1/include'
  '--cflag=-I/usr/lib/ghc-8.0/lib/include' 
  '--lflag=-L/usr/lib/ghc-8.0/lib/base-4.9.0.0' 
  '--lflag=-Wl,-R,/usr/lib/ghc-8.0/lib/base-4.9.0.0' 
  '--lflag=-L/usr/lib/ghc-8.0/lib/integer-gmp-1.0.0.1' 
  '--lflag=-Wl,-R,/usr/lib/ghc-8.0/lib/integer-gmp-1.0.0.1'
  '--lflag=-lgmp' '--lflag=-L/usr/lib/ghc-8.0/lib/ghc-prim-0.5.0.0' 
  '--lflag=-Wl,-R,/usr/lib/ghc-8.0/lib/ghc-prim-0.5.0.0' 
  '--lflag=-L/usr/lib/ghc-8.0/lib/rts'
  '--lflag=-Wl,-R,/usr/lib/ghc-8.0/lib/rts' '--lflag=-lm' 
  '--lflag=-lrt' '--lflag=-ldl' '--lflag=-lffi' 
  -o dist/build/Magic/Data.hs Magic/Data.hsc

Executing: /usr/bin/gcc -c dist/build/Magic/Data_hsc_make.c -o 
   dist/build/Magic/Data_hsc_make.o -fno-stack-protector -fno-PIE 
  -fno-stack-protector -D__GLASGOW_HASKELL__=800 -Dlinux_BUILD_OS=1 
  -Dx86_64_BUILD_ARCH=1 -Dlinux_HOST_OS=1 -Dx86_64_HOST_ARCH=1 
  -Idist/build/autogen -include dist/build/autogen/cabal_macros.h 
  -I/usr/lib/ghc-8.0/lib/base-4.9.0.0/include 
  -I/usr/lib/ghc-8.0/lib/integer-gmp-1.0.0.1/include 
  -I/usr/lib/ghc-8.0/lib/include -I/usr/lib/ghc-8.0/lib/include/

Executing: /usr/bin/gcc -c dist/build/Magic/Data_hsc_utils.c -o 
  dist/build/Magic/Data_hsc_utils.o -fno-stack-protector -fno-PIE 
  -fno-stack-protector -D__GLASGOW_HASKELL__=800 -Dlinux_BUILD_OS=1 
  -Dx86_64_BUILD_ARCH=1 -Dlinux_HOST_OS=1 -Dx86_64_HOST_ARCH=1 
  -Idist/build/autogen -include dist/build/autogen/cabal_macros.h 
  -I/usr/lib/ghc-8.0/lib/base-4.9.0.0/include 
  -I/usr/lib/ghc-8.0/lib/integer-gmp-1.0.0.1/include 
  -I/usr/lib/ghc-8.0/lib/include -I/usr/lib/ghc-8.0/lib/include/

Executing: /usr/bin/gcc dist/build/Magic/Data_hsc_make.o 
  dist/build/Magic/Data_hsc_utils.o -o dist/build/Magic/Data_hsc_make 
  -fno-PIE -fno-stack-protector -lmagic -L/usr/lib/ghc-8.0/lib/base-4.9.0.0 
  -Wl,-R,/usr/lib/ghc-8.0/lib/base-4.9.0.0 
  -L/usr/lib/ghc-8.0/lib/integer-gmp-1.0.0.1 
  -Wl,-R,/usr/lib/ghc-8.0/lib/integer-gmp-1.0.0.1 -lgmp 
  -L/usr/lib/ghc-8.0/lib/ghc-prim-0.5.0.0 
  -Wl,-R,/usr/lib/ghc-8.0/lib/ghc-prim-0.5.0.0 -L/usr/lib/ghc-8.0/lib/rts 
  -Wl,-R,/usr/lib/ghc-8.0/lib/rts -lm -lrt -ldl -lffi

/usr/bin/ld: dist/build/Magic/Data_hsc_make.o: relocation R_X86_64_32 against 
  `.rodata' can not be used when making a shared object; recompile with -fPIC

comment:9 Changed 13 months ago by erikd

The interesting bits of ghc --info:

 [("Project name","The Glorious Glasgow Haskell Compilation System")
 ,("GCC extra via C opts"," -fwrapv -fno-builtin")
 ,("C compiler command","/usr/bin/gcc")
 ,("C compiler flags","-fno-PIE -fno-stack-protector")
 ,("C compiler link flags","-no-pie")
 ,("Haskell CPP command","/usr/bin/gcc")
 ,("Haskell CPP flags","-E -undef -traditional")
 ,("ld command","/usr/bin/ld")
 ,("ld flags","-no-pie")
 ,("ld supports compact unwind","YES")
 ,("ld supports build-id","YES")
 ,("ld supports filelist","NO")
 ,("ld is GNU ld","YES")
 ,("ar command","/usr/bin/ar")
 ,("ar flags","q")
 ,("ar supports at file","YES")
 ,("touch command","touch")
 ,("dllwrap command","/bin/false")
 ,("windres command","/bin/false")
 ,("libtool command","libtool")
 ,("perl command","/usr/bin/perl")
 ,("cross compiling","NO")
 ,("target os","OSLinux")
 ,("target arch","ArchX86_64")
 ,("target word size","8")
 ,("target has GNU nonexec stack","True")
 ,("target has .ident directive","True")
 ,("target has subsections via symbols","False")
 ,("Unregisterised","NO")
 ,("LLVM llc command","/usr/bin/llc-3.7")
 ,("LLVM opt command","/usr/bin/opt-3.7")
...

comment:10 Changed 13 months ago by erikd

According to @hvr, this is likely a cabal bug that has been fixed (https://git.haskell.org/packages/Cabal.git/commitdiff/c30b179a73d9fd3f6edcdda5e881523cd6edd46a) but not released yet.

comment:11 Changed 13 months ago by bgamari

So I spent quite a while today working through building a tree with the new compiler. It turns out there are a number of build system issues which get in the way of this which I've fixed in Phab:D2672, Phab:D2673, and Phab:D2674. With these patches you can simply configure with,

$ ./configure \
    CONF_GCC_LINKER_OPTS_STAGE0=-no-pie \
    CONF_LD_LINKER_OPTS_STAGE0=-no-pie \
    CONF_HC_OPTS_STAGE0=-optl=-no-pie

and build as usual.

It's not entirely clear here why the Haskell compiler options shouldn't just include CONF_LD_LINKER_OPTS_* with the appropriate prefix but I didn't want to change that today so instead I just passed CONF_GCC_LINKER_OPTS_STAGE0 explicitly.

Note that it is only necessary to pass -no-pie to the stage0 link; the later stages should build with -fPIC as this is the new compiler's default.

Last edited 7 months ago by bgamari (previous) (diff)

comment:12 Changed 13 months ago by rwbarton

It's not entirely clear here why the Haskell compiler options shouldn't just include CONF_LD_LINKER_OPTS_* with the appropriate prefix but I didn't want to change that today so instead I just passed CONF_HC_OPTS_STAGE0 explicitly.

You mean CONF_GCC_LINKER_OPTS_STAGE0 :)

comment:13 Changed 12 months ago by Ben Gamari <ben@…>

In bae4a55b/ghc:

Pass -no-pie to GCC

Certain distributions (e.g. Debian and Ubuntu) have enabled PIE be
default in their GCC packaging. This breaks our abuse of GCC as a linker
which requires that we pass -Wl,-r, which is incompatible with
PIE (since the former implies that we are generating a relocatable
object file and the latter an executable).

Test Plan: Validate

Reviewers: hvr, austin

Subscribers: rwbarton, thomie, erikd

Differential Revision: https://phabricator.haskell.org/D2691

GHC Trac Issues: #12759

comment:14 Changed 12 months ago by rwbarton

Note that this is still open because of ticket:12755#comment:4, I guess (-no-pie setting should be configurable via settings file).

comment:15 Changed 12 months ago by Ben Gamari <ben@…>

In d421a7e2/ghc:

Pass -no-pie to GCC

Certain distributions (e.g. Debian and Ubuntu) have enabled PIE be
default in their GCC packaging. This breaks our abuse of GCC as a linker
which requires that we pass -Wl,-r, which is incompatible with
PIE (since the former implies that we are generating a relocatable
object file and the latter an executable).

This is a second attempt at D2691. This attempt constrasts with D2691 in that
it preserves the "does gcc support -no-pie" flag in settings, allowing this to
be reconfigured by `configure` during installation of a binary distribution.
Thanks for @rwbarton for drawing attention to this issue.

Test Plan: Validate

Reviewers: austin, hvr, erikd

Reviewed By: erikd

Subscribers: thomie, rwbarton, erikd

Differential Revision: https://phabricator.haskell.org/D2693

GHC Trac Issues: #12759

comment:16 Changed 12 months ago by bgamari

Resolution: fixed
Status: newclosed

comment:17 Changed 12 months ago by bgamari

Differential Rev(s): Phab:D2707
Resolution: fixed
Status: closednew

It seems that the configure check introduced previously isn't robust enough due to some GCC silliness. Prior to 4.8 GCC apparently only warns when faced with an unknown flag, exiting with exit code 0. The Go people ran into this same issue and they checked this using the stderr output. Phab:D2707 does the same.

Last edited 12 months ago by bgamari (previous) (diff)

comment:18 Changed 12 months ago by Ben Gamari <ben@…>

In 011af2b/ghc:

configure: Verify that GCC recognizes -no-pie flag

It seems like GCC versions prior to 4.8 exit with code 0 when faced with
an unrecognized flag. Silly compilers.

Test Plan: Validate

Reviewers: hvr, austin, ggreif

Reviewed By: ggreif

Subscribers: thomie, erikd

Differential Revision: https://phabricator.haskell.org/D2707

GHC Trac Issues: #12759

comment:19 Changed 12 months ago by bgamari

Resolution: fixed
Status: newclosed
Last edited 12 months ago by bgamari (previous) (diff)

comment:20 Changed 12 months ago by erikd

@bgamari, you did mean 8.0 didn't you?

comment:21 Changed 12 months ago by bgamari

@erikd, nope, 9.0. Fixing tomorrows compilers today! ;)

comment:22 Changed 12 months ago by bgamari

Changed 6 months ago by msuchanek

Attachment: _log.txt.xz added

log of failed ghc build

comment:23 Changed 6 months ago by msuchanek

This is still broken in 8.0.2

[ 43s] + /usr/bin/xz -dc /home/abuild/rpmbuild/SOURCES/ghc-8.0.2-src.tar.xz ... [ 48s] checking whether GCC supports -no-pie... yes ... [ 1985s] /usr/lib64/gcc/x86_64-suse-linux/6/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/ghc-8.0.2/rts/dist/build/libHSrts.a(AutoApply.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC [ 1985s] /usr/lib64/gcc/x86_64-suse-linux/6/../../../../x86_64-suse-linux/bin/ld: final link failed: Nonrepresentable section on output [ 1985s] collect2: error: ld returned 1 exit status [ 1985s] gcc' failed in phase Linker'. (Exit code: 1) [ 1985s] make[1]: * [utils/ghc-cabal/ghc.mk:89: utils/ghc-cabal/dist-install/build/tmp/ghc-cabal] Error 1

comment:24 Changed 6 months ago by slyfox

Cc: slyfox added

msuchanek, I suggest filing new bug so we could investigate why host ghc was failing to build stage2 for you.

comment:25 Changed 3 months ago by Ben Gamari <ben@…>

In 3625728/ghc:

Add support for producing position-independent executables

Previously due to #12759 we disabled PIE support entirely. However, this
breaks the user's ability to produce PIEs. Add an explicit flag, -fPIE,
allowing the user to build PIEs.

Test Plan: Validate

Reviewers: rwbarton, austin, simonmar

Subscribers: trommler, simonmar, trofi, jrtc27, thomie

GHC Trac Issues: #12759, #13702

Differential Revision: https://phabricator.haskell.org/D3589

comment:26 Changed 7 weeks ago by bgamari

For the record, old (pre-8.0.2) compiler installations can be retrofitted to work with newer gccs by locating the compiler's settings file (e.g. /usr/lib/ghc-7.10.3/settings) and adding -no-pie to C compiler link flags.

Note: See TracTickets for help on using tickets.