[commit: ghc] ghc-7.10: driver: pass '-fPIC' option to all CC invocations (0e7e611)

git at git.haskell.org git at git.haskell.org
Fri Jul 10 09:37:18 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-7.10
Link       : http://ghc.haskell.org/trac/ghc/changeset/0e7e611470a7c70ef5a3c84be01eeac8fddadf94/ghc

>---------------------------------------------------------------

commit 0e7e611470a7c70ef5a3c84be01eeac8fddadf94
Author: Sergei Trofimovich <siarheit at google.com>
Date:   Wed Jun 24 22:10:47 2015 +0100

    driver: pass '-fPIC' option to all CC invocations
    
    Reported by mitchty:
    
      When porting ghc to alpine linux (rumors say they build
      all binaries as Position Independent Executables
      to leverage global ASLR) linker issued obscure errors:
    
    Tiny example:
        $ echo 'main = print "hello"' > a.hs
        $ ghc -fforce-recomp a.hs -fPIC -dynamic -optl-pie -o a
            ld: /tmp/ghc2142_0/ghc2142_5.o: relocation R_X86_64_32 against `ZCMain_main_closure'
                can not be used when making a shared object; recompile with -fPIC
            /tmp/ghc2142_0/ghc2142_5.o: error adding symbols: Bad value
            collect2: error: ld returned 1 exit status
    
    There is two entry points in CC driver:
        'runPhase' (CC) and 'mkExtraObj'
    
    'mkExtraObj' does not handle most of 'runPhase's complexity.
    Ideally it should.
    
    This patch only adds -fPIC propagation to 'mkExtraObj'.
    
    Please merge to stable branch.
    
    Signed-off-by: Sergei Trofimovich <siarheit at google.com>


>---------------------------------------------------------------

0e7e611470a7c70ef5a3c84be01eeac8fddadf94
 compiler/main/DriverPipeline.hs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index 6d597f9..623f356 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -1623,12 +1623,14 @@ mkExtraObj dflags extn xs
       oFile <- newTempName dflags "o"
       writeFile cFile xs
       let rtsDetails = getPackageDetails dflags rtsPackageKey
+          pic_c_flags = picCCOpts dflags
       SysTools.runCc dflags
                      ([Option        "-c",
                        FileOption "" cFile,
                        Option        "-o",
                        FileOption "" oFile]
-                      ++ map (FileOption "-I") (includeDirs rtsDetails))
+                      ++ map (FileOption "-I") (includeDirs rtsDetails)
+                      ++ map Option pic_c_flags)
       return oFile
 
 -- When linking a binary, we need to create a C main() function that



More information about the ghc-commits mailing list