[GHC] #15847: GHCi cannot load .o built from c with -fPIC on i386 linux
#15847: GHCi cannot load .o built from c with -fPIC on i386 linux -------------------------------------+------------------------------------- Reporter: watashi | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Runtime | Version: 8.7 System (Linker) | Keywords: | Operating System: Linux Architecture: x86 | Type of failure: None/Unknown Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- GHCi cannot load .o built from c with -fPIC on i386 linux. On i386 linux, the PIC object code looks like: {{{ 000001ac <hs_remWord64>: 1ac: 53 push %ebx 1ad: 83 ec 08 sub $0x8,%esp 1b0: e8 fc ff ff ff call 1b1 <hs_remWord64+0x5> 1b1: R_386_PC32 __x86.get_pc_thunk.bx 1b5: 81 c3 02 00 00 00 add $0x2,%ebx 1b7: R_386_GOTPC _GLOBAL_OFFSET_TABLE_ 1bb: ff 74 24 1c pushl 0x1c(%esp) 1bf: ff 74 24 1c pushl 0x1c(%esp) 1c3: ff 74 24 1c pushl 0x1c(%esp) 1c7: ff 74 24 1c pushl 0x1c(%esp) 1cb: e8 fc ff ff ff call 1cc <hs_remWord64+0x20> 1cc: R_386_PLT32 __umoddi3 1d0: 83 c4 18 add $0x18,%esp 1d3: 5b pop %ebx 1d4: c3 ret }}} 1. the GOT symbol `_GLOBAL_OFFSET_TABLE_` may be undefined 2. the runtime linker doesn't support PIC-related i386 relocations like `R_386_GOTPC` or `R_386_PLT32` As a result, we will see errors like `unknown symbol '_GLOBAL_OFFSET_TABLE_'` or `unhandled ELF relocation`. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15847> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15847: GHCi cannot load .o built from c with -fPIC on i386 linux --------------------------------------------+------------------------------ Reporter: watashi | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System (Linker) | Version: 8.7 Resolution: | Keywords: Operating System: Linux | Architecture: x86 Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | --------------------------------------------+------------------------------ Comment (by Ben Gamari <ben@…>): In [changeset:"c98e25a4de88f12c6ded0a97fcf3ed8f4996b9ea/ghc" c98e25a4/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="c98e25a4de88f12c6ded0a97fcf3ed8f4996b9ea" 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 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15847#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC