Commit f7cb40bb authored by ony's avatar ony Committed by Ben Gamari
Browse files

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
parent d09ddfd0
......@@ -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])
......
......@@ -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"
......
......@@ -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))
......
......@@ -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
......
......@@ -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
#
......
......@@ -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>
......
......@@ -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>
......
......@@ -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@"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment