[GHC] #13771: ghc fails to build on openSUSE

GHC ghc-devs at haskell.org
Thu Jun 1 13:04:29 UTC 2017


#13771: ghc fails to build on openSUSE
---------------------------------+--------------------------------------
        Reporter:  msuchanek     |                Owner:  (none)
            Type:  bug           |               Status:  new
        Priority:  normal        |            Milestone:
       Component:  Compiler      |              Version:  8.0.2
      Resolution:                |             Keywords:
Operating System:  Linux         |         Architecture:  x86_64 (amd64)
 Type of failure:  None/Unknown  |            Test Case:
      Blocked By:                |             Blocking:
 Related Tickets:                |  Differential Rev(s):
       Wiki Page:                |
---------------------------------+--------------------------------------

Comment (by msuchanek):

 ok, so as I understand the issue distributions are moving towards
 compiling with -fPIE -pie or whatever is the current flag for whatever
 reason. It seems on SUSE these flags are added to rpm flags on the build
 service meaning system binaries are built with them but locally compiled
 binaries are not.

 Adding these flags requires that object files must be built with -fPIC and
 gcc complains if it is not the case and refuses to link binaries.

 == Issue: gcc started using PIE on system with ghc installed

 ==== simulation:
 {{{
 # mv /usr/bin/gcc /usr/bin/gcc.real
 cat > /usr/bin/gcc <<GCC
 #!/bin/sh
 function check_pie () {
 while [ "$#" -gt 0 ] ; do
   case "$1" in
     -no-pie) return 1 ;;
   esac
   shift
 done
 return 0
 }

 pie=""

 check_pie "$@" && pie="-fPIE -pie"

 exec /usr/bin/gcc.real $pie "$@"
 GCC
 }}}
 === symptom:
 {{{
 $ cat HelloWorld.hs
 main = putStrLn "Hello World"
 }}}
 {{{
 $ ghc HelloWorld.hs
 [1 of 1] Compiling Main             ( HelloWorld.hs, HelloWorld.o )
 Linking HelloWorld ...
 /usr/lib64/gcc/x86_64-suse-linux/6/../../../../x86_64-suse-linux/bin/ld:
 HelloWorld.o: relocation R_X86_64_32S against `stg_bh_upd_frame_info' can
 not be used when making a shared object;
 recompile with -fPIC
 HelloWorld.o: error adding symbols: Bad value
 collect2: error: ld returned 1 exit status
 }}}
 HelloWorld.o is not relocatable. Doing as asked gives this:
 {{{
 ghc -fPIC HelloWorld.hs
 [1 of 1] Compiling Main             ( HelloWorld.hs, HelloWorld.o )
 Linking HelloWorld ...
 /usr/lib64/gcc/x86_64-suse-linux/6/../../../../x86_64-suse-linux/bin/ld:
 /usr/lib64/ghc-7.10.3/base_HQfYBxpPvuw8OunzQu6JGM/libHSbase-4.8.2.0-HQfYBxpPvuw8OunzQu6JGM.a(Base__116.o):
 relocation R_X86_64_32S against `stg_bh_upd_frame_info' can not be used
 when making a shared object;
 recompile with -fPIC
 /usr/lib64/ghc-7.10.3/base_HQfYBxpPvuw8OunzQu6JGM/libHSbase-4.8.2.0-HQfYBxpPvuw8OunzQu6JGM.a:
 error adding symbols: Bad value
 collect2: error: ld returned 1 exit status
 }}}
 HelloWorld.o is relocatable but system libraries are not.
 === workaround (provided gcc supports -no-pie):
 {{{
 ghc -optl -no-pie HelloWorld.hs
 [1 of 1] Compiling Main             ( HelloWorld.hs, HelloWorld.o )
 Linking HelloWorld ...
 }}}
 This issue should be detected at bootstrap time before building in-tree
 ghc-pwd and workaround applied if possible. Otherwise build fails and user
 is left with broken ghc installed and no possibility to rebuild it.

 == Issue: gcc uses PIE by default while building/installing ghc
 This probably arises from -fPIC not being the default ghc option while it
 is the default gcc option.
 ==== simulation:

 {{{
 cat hello_world.c
 #include <stdio.h>

 int main(int argc, char** argv)
 {
   puts("Hello World!");
 }
 }}}

 {{{
 $ gcc -fno-pic -c -Wall hello_world.c -o hello_world.o
 $ gcc hello_world.o -o hello_world
 /usr/lib64/gcc/x86_64-suse-linux/6/../../../../x86_64-suse-linux/bin/ld:
 hello_world.o: relocation R_X86_64_32 against `.rodata' can not be used
 when making a shared object; recompile with -fPIC
 hello_world.o: error adding symbols: Bad value
 collect2: error: ld returned 1 exit status
 $ gcc -no-pie hello_world.o -o hello_world
 $ ./hello_world
 Hello World!
 }}}

 So gcc defaulting to PIE should be detected at bootstrap and at binary
 distribution installation and -fPIC should be added as default ghc flag.

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


More information about the ghc-tickets mailing list