[commit: ghc] ghc-7.10: Handle platforms with renamed "readelf" (f7cb40b)

git at git.haskell.org git at git.haskell.org
Mon Oct 26 17:00:30 UTC 2015


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

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

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

commit f7cb40bbca319677e508b768ec8fe92deee9dc90
Author: Mykola Orliuk <virkony at gmail.com>
Date:   Mon Oct 26 16:12:21 2015 +0100

    Handle platforms with renamed "readelf"
    
    - Add `-pgmreadelf` option
    - Auto configure path and name of "readelf"
    - Add settings `readelf command`
    - During build of GHC name of tool can be changed with
      `./configure --with-readelf=myreadelf`
    
    Test Plan:
    ```
    make -C testsuite/tests/driver/recomp011
    ```
    
    Reviewers: austin, bgamari
    
    Subscribers: erikd, thomie
    
    Differential Revision: https://phabricator.haskell.org/D1335
    
    GHC Trac Issues: #10974


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

f7cb40bbca319677e508b768ec8fe92deee9dc90
 aclocal.m4                  | 19 +++++++++++++++++++
 compiler/main/DynFlags.hs   |  7 ++++++-
 compiler/main/SysTools.hs   |  6 ++++--
 configure.ac                |  5 +++++
 distrib/configure.ac.in     |  5 +++++
 docs/users_guide/flags.xml  |  7 +++++++
 docs/users_guide/phases.xml | 11 +++++++++++
 settings.in                 |  1 +
 8 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/aclocal.m4 b/aclocal.m4
index d19a66e..6ca3986 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -472,6 +472,7 @@ AC_DEFUN([FP_SETTINGS],
         SettingsDllWrapCommand="/bin/false"
         SettingsWindresCommand="/bin/false"
         SettingsLibtoolCommand="libtool"
+        SettingsReadElfCommand="$ReadElfCmd"
         SettingsTouchCommand='touch'
     fi
     if test -z "$LlcCmd"
@@ -501,6 +502,7 @@ AC_DEFUN([FP_SETTINGS],
     AC_SUBST(SettingsDllWrapCommand)
     AC_SUBST(SettingsWindresCommand)
     AC_SUBST(SettingsLibtoolCommand)
+    AC_SUBST(SettingsReadElfCommand)
     AC_SUBST(SettingsTouchCommand)
     AC_SUBST(SettingsLlcCommand)
     AC_SUBST(SettingsOptCommand)
@@ -2203,6 +2205,23 @@ AC_DEFUN([FIND_GCC],[
     AC_SUBST($1)
 ])
 
+# FIND_READELF()
+# --------------------------------
+# Finds which `readelf` to use. This is used in both in the top level
+# `configure.ac` and in `distrib/configure.ac.in`
+#
+# $1 = the variable to set
+#
+AC_DEFUN([FIND_READELF],[
+    if test "$HostOS" != "mingw32"; then
+        FP_ARG_WITH_PATH_GNU_PROG([READELF], [readelf], [readelf])
+        if test -z "$READELF"; then
+            AC_MSG_ERROR([cannot identify readelf tool])
+        fi
+        $1="$READELF"
+    fi
+])
+
 AC_DEFUN([MAYBE_OVERRIDE_STAGE0],[
   if test ! -z "$With_$1" -a "$CrossCompiling" != "YES"; then
       AC_MSG_NOTICE([Not cross-compiling, so --with-$1 also sets $2])
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index 78370cf..42ac14e 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -71,7 +71,7 @@ module DynFlags (
         versionedAppDir,
         extraGccViaCFlags, systemPackageConfig,
         pgm_L, pgm_P, pgm_F, pgm_c, pgm_s, pgm_a, pgm_l, pgm_dll, pgm_T,
-        pgm_sysman, pgm_windres, pgm_libtool, pgm_lo, pgm_lc,
+        pgm_sysman, pgm_windres, pgm_libtool, pgm_readelf, pgm_lo, pgm_lc,
         opt_L, opt_P, opt_F, opt_c, opt_a, opt_l,
         opt_windres, opt_lo, opt_lc,
 
@@ -935,6 +935,7 @@ data Settings = Settings {
   sPgm_sysman            :: String,
   sPgm_windres           :: String,
   sPgm_libtool           :: String,
+  sPgm_readelf           :: String,
   sPgm_lo                :: (String,[Option]), -- LLVM: opt llvm optimiser
   sPgm_lc                :: (String,[Option]), -- LLVM: llc static compiler
   -- options for particular phases
@@ -995,6 +996,8 @@ pgm_windres           :: DynFlags -> String
 pgm_windres dflags = sPgm_windres (settings dflags)
 pgm_libtool           :: DynFlags -> String
 pgm_libtool dflags = sPgm_libtool (settings dflags)
+pgm_readelf           :: DynFlags -> String
+pgm_readelf dflags = sPgm_readelf (settings dflags)
 pgm_lo                :: DynFlags -> (String,[Option])
 pgm_lo dflags = sPgm_lo (settings dflags)
 pgm_lc                :: DynFlags -> (String,[Option])
@@ -2308,6 +2311,8 @@ dynamic_flags = [
       (hasArg (\f -> alterSettings (\s -> s { sPgm_windres = f})))
   , defFlag "pgmlibtool"
       (hasArg (\f -> alterSettings (\s -> s { sPgm_libtool = f})))
+  , defFlag "pgmreadelf"
+      (hasArg (\f -> alterSettings (\s -> s { sPgm_readelf = f})))
 
     -- need to appear before -optl/-opta to be parsed as LLVM flags.
   , defFlag "optlo"
diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs
index b3a540b..8c3ab1a 100644
--- a/compiler/main/SysTools.hs
+++ b/compiler/main/SysTools.hs
@@ -275,6 +275,7 @@ initSysTools mbMinusB
 
        windres_path <- getSetting "windres command"
        libtool_path <- getSetting "libtool command"
+       readelf_path <- getSetting "readelf command"
 
        tmpdir <- getTemporaryDirectory
 
@@ -346,6 +347,7 @@ initSysTools mbMinusB
                     sPgm_sysman  = top_dir ++ "/ghc/rts/parallel/SysMan",
                     sPgm_windres = windres_path,
                     sPgm_libtool = libtool_path,
+                    sPgm_readelf = readelf_path,
                     sPgm_lo  = (lo_prog,[]),
                     sPgm_lc  = (lc_prog,[]),
                     -- Hans: this isn't right in general, but you can
@@ -1048,9 +1050,9 @@ copyWithHeader dflags purpose maybe_header from to = do
 -- | read the contents of the named section in an ELF object as a
 -- String.
 readElfSection :: DynFlags -> String -> FilePath -> IO (Maybe String)
-readElfSection _dflags section exe = do
+readElfSection dflags section exe = do
   let
-     prog = "readelf"
+     prog = pgm_readelf dflags
      args = [Option "-p", Option section, FileOption "" exe]
   --
   r <- readProcessEnvWithExitCode prog (filter notNull (map showOpt args))
diff --git a/configure.ac b/configure.ac
index b41a810..5b94d07 100644
--- a/configure.ac
+++ b/configure.ac
@@ -532,6 +532,11 @@ FP_ARG_WITH_PATH_GNU_PROG([RANLIB], [ranlib], [ranlib])
 RanlibCmd="$RANLIB"
 RANLIB="$RanlibCmd"
 
+dnl ** Which readelf to use?
+dnl --------------------------------------------------------------
+FIND_READELF([ReadElfCmd])
+AC_SUBST([ReadElfCmd])
+
 
 # Note: we may not have objdump on OS X, and we only need it on Windows (for DLL checks)
 case $HostOS_CPP in
diff --git a/distrib/configure.ac.in b/distrib/configure.ac.in
index 0fcd869..f1abd91 100644
--- a/distrib/configure.ac.in
+++ b/distrib/configure.ac.in
@@ -139,6 +139,11 @@ dnl ** how to invoke `ar' and `ranlib'
 FP_PROG_AR_SUPPORTS_ATFILE
 FP_PROG_AR_NEEDS_RANLIB
 
+dnl ** Which readelf to use?
+dnl --------------------------------------------------------------
+FIND_READELF([ReadElfCmd])
+AC_SUBST([ReadElfCmd])
+
 FP_SETTINGS
 
 #
diff --git a/docs/users_guide/flags.xml b/docs/users_guide/flags.xml
index f019854..b4a76ff 100644
--- a/docs/users_guide/flags.xml
+++ b/docs/users_guide/flags.xml
@@ -2780,6 +2780,13 @@
             <entry>dynamic</entry>
             <entry>-</entry>
           </row>
+          <row>
+            <entry><option>-pgmreadelf</option> <replaceable>cmd</replaceable></entry>
+            <entry>Use <replaceable>cmd</replaceable> as the command for readelf
+              (part of Unix binutils)</entry>
+            <entry>dynamic</entry>
+            <entry>-</entry>
+          </row>
         </tbody>
       </tgroup>
     </informaltable>
diff --git a/docs/users_guide/phases.xml b/docs/users_guide/phases.xml
index 8994ffe..3b7403b 100644
--- a/docs/users_guide/phases.xml
+++ b/docs/users_guide/phases.xml
@@ -148,6 +148,17 @@
           (when using <option>-staticlib</option> only).</para>
         </listitem>
       </varlistentry>
+
+      <varlistentry>
+        <term>
+          <option>-pgmreadelf</option> <replaceable>cmd</replaceable>
+          <indexterm><primary><option>-pgmreadelf</option></primary></indexterm>
+        </term>
+        <listitem>
+          <para>Use <replaceable>cmd</replaceable> as the readelf command
+          (part of Unix binutils).</para>
+        </listitem>
+      </varlistentry>
     </variablelist>
   </sect2>
 
diff --git a/settings.in b/settings.in
index e8cdad3..5f54fd9 100644
--- a/settings.in
+++ b/settings.in
@@ -17,6 +17,7 @@
  ("dllwrap command", "@SettingsDllWrapCommand@"),
  ("windres command", "@SettingsWindresCommand@"),
  ("libtool command", "@SettingsLibtoolCommand@"),
+ ("readelf command", "@SettingsReadElfCommand@"),
  ("perl command", "@SettingsPerlCommand@"),
  ("cross compiling", "@CrossCompiling@"),
  ("target os", "@HaskellTargetOs@"),



More information about the ghc-commits mailing list