[commit: ghc] wip/T16212-fixed, wip/sgraf-no-exnstr: Don't use X86_64_ELF_NONPIC_HACK for +RTS -xp (6e96aa2)

git at git.haskell.org git at git.haskell.org
Fri Feb 1 05:55:16 UTC 2019


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

On branches: wip/T16212-fixed,wip/sgraf-no-exnstr
Link       : http://ghc.haskell.org/trac/ghc/changeset/6e96aa2d503ddeeef1fa1f37b45d5c744522b64d/ghc

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

commit 6e96aa2d503ddeeef1fa1f37b45d5c744522b64d
Author: Zejun Wu <watashi at fb.com>
Date:   Fri Dec 28 20:48:31 2018 -0800

    Don't use X86_64_ELF_NONPIC_HACK for +RTS -xp
    
    Summary:
    When `+RTS -xp` is passed, when don't need the X86_64_ELF_NONPIC_HACK,
    becasue the relocation offset should only be out of range if
    
    * the object file was not compiled with `-fPIC -fexternal-dynamic-refs`;
    * ghc generates non-pic code while it should (e.g. #15723)
    
    In either case, we should print an error message rather that silently
    attempt to use a hacky workaround that may not work.
    
    This could have made debugging #15723 and #15729 much easier.
    
    Test Plan:
    Run this in a case where ghci used to crash becasue of T15723. Now we
    see helpful message like:
    
    ```
    ghc-iserv-prof: R_X86_64_PC32 relocation out of range:
    stmzm2zi4zi4zi1zmJQn4hNPyYjP5m9AcbI88Ve_ControlziConcurrentziSTMziTMVar_readTMVar_C61n_cc
    = 9b95ffac
    ```
    
    Reviewers: simonmar, bgamari, erikd
    
    Reviewed By: simonmar, bgamari
    
    Subscribers: rwbarton, carter
    
    Differential Revision: https://phabricator.haskell.org/D5233


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

6e96aa2d503ddeeef1fa1f37b45d5c744522b64d
 rts/linker/Elf.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c
index 6de531a..b647d20 100644
--- a/rts/linker/Elf.c
+++ b/rts/linker/Elf.c
@@ -53,11 +53,13 @@
  * SILENTLY generate crashing code for data references.  This hack is
  * enabled by X86_64_ELF_NONPIC_HACK.
  *
- * One workaround is to use shared Haskell libraries.  This is
- * coming.  Another workaround is to keep the static libraries but
- * compile them with -fPIC, because that will generate PIC references
- * to data which can be relocated.  The PIC code is still too green to
- * do this systematically, though.
+ * One workaround is to use shared Haskell libraries. This is the case
+ * when dynamically-linked GHCi is used.
+ *
+ * Another workaround is to keep the static libraries but compile them
+ * with -fPIC -fexternal-dynamic-refs, because that will generate PIC
+ * references to data which can be relocated. This is the case when
+ * +RTS -xp is passed.
  *
  * See bug #781
  * See thread http://www.haskell.org/pipermail/cvs-ghc/2007-September/038458.html
@@ -74,7 +76,7 @@
  * Sym*_NeedsProto: the symbol is undefined and we add a dummy
  *                  default proto extern void sym(void);
  */
-#define X86_64_ELF_NONPIC_HACK 1
+#define X86_64_ELF_NONPIC_HACK (!RtsFlags.MiscFlags.linkerAlwaysPic)
 
 #if defined(sparc_HOST_ARCH)
 #  define ELF_TARGET_SPARC  /* Used inside <elf.h> */



More information about the ghc-commits mailing list