[commit: ghc] master: Explicitly pass -fno-PIC to C compiler on linux (c98e25a)

git at git.haskell.org git at git.haskell.org
Tue Dec 11 23:22:14 UTC 2018


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/c98e25a4de88f12c6ded0a97fcf3ed8f4996b9ea/ghc

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

commit c98e25a4de88f12c6ded0a97fcf3ed8f4996b9ea
Author: Zejun Wu <watashi at watashi.ws>
Date:   Tue Dec 11 13:49:12 2018 -0500

    Explicitly pass -fno-PIC to C compiler on linux
    
    Recent gcc on some linux ditributions may have -fPIC on by default
    
    ```
    $ uname -a
    Linux watashi-arch32 4.18.5-arch1-1.0-ARCH #1 SMP PREEMPT Tue Aug 28
    20:45:30 CEST 2018 i686 GNU/Linux
    $ gcc --version
    gcc (GCC) 7.3.1 20180312
    $ touch dummy.c
    $ gcc -Q -v dummy.c 2>&1 | grep PIC
    options enabled:  -fPIC -fPIE -faggressive-loop-optimizations
    ```
    
    This results in following error for i686:
    
    ```
    $ TEST=T13366 make test
    ...
    c-iserv.bin:
    /home/watashi/github/ghc/libraries/ghc-prim/dist-install/build/HSghc-pri
    m-0.5.3.o:
    unknown symbol `_GLOBAL_OFFSET_TABLE_'
    ghc-stage2: unable to load package `ghc-prim-0.5.3'
    ...
    ```
    
    As our runtime linker doesn't support R_386_GOTPC relocations at all
    (#15847).
    Also while we don't have such problem on x86_64, it's not desired to
    build PIC objects either.
    
    Test Plan: `TEST=T13366 make test` passed on
    {rGHC82a716431cc680392e332bc2b1a1fd0d7faa4cd8}
    
    Reviewers: simonmar, bgamari, austin
    
    Reviewed By: simonmar
    
    Subscribers: rwbarton, carter
    
    GHC Trac Issues: #15848
    
    Differential Revision: https://phabricator.haskell.org/D5288


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

c98e25a4de88f12c6ded0a97fcf3ed8f4996b9ea
 compiler/main/DynFlags.hs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index 6c4ee86..be347d9 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -5510,7 +5510,9 @@ picCCOpts dflags = pieOpts ++ picOpts
       -- http://ghc.haskell.org/trac/ghc/wiki/Commentary/PositionIndependentCode
        | gopt Opt_PIC dflags || WayDyn `elem` ways dflags ->
           ["-fPIC", "-U__PIC__", "-D__PIC__"]
-       | otherwise                             -> []
+      -- gcc may be configured to have PIC on by default, let's be
+      -- explicit here, see Trac #15847
+       | otherwise -> ["-fno-PIC"]
 
     pieOpts
       | gopt Opt_PICExecutable dflags       = ["-pie"]



More information about the ghc-commits mailing list