Commit 0472f0f6 authored by John Ericson's avatar John Ericson Committed by Marge Bot

Remove most uses of TARGET platform macros

These prevent multi-target builds. They were gotten rid of in 3 ways:

1. In the compiler itself, replacing `#if` with runtime `if`. In these
cases, we care about the target platform still, but the target platform
is dynamic so we must delay the elimination to run time.

2. In the compiler itself, replacing `TARGET` with `HOST`. There was
just one bit of this, in some code splitting strings representing lists
of paths. These paths are used by GHC itself, and not by the compiled
binary. (They are compiler lookup paths, rather than RPATHS or something
that does matter to the compiled binary, and thus would legitamentally
be target-sensative.) As such, the path-splitting method only depends on
where GHC runs and not where code it produces runs. This should have
been `HOST` all along.

3. Changing the RTS. The RTS doesn't care about the target platform,
full stop.

4. `includes/stg/HaskellMachRegs.h` This file is also included in the
genapply executable. This is tricky because the RTS's host platform
really is that utility's target platform. so that utility really really
isn't multi-target either. But at least it isn't an installed part of
GHC, but just a one-off tool when building the RTS. Lying with the
`HOST` to a one-off program (genapply) that isn't installed doesn't seem so bad.
It's certainly better than the other way around of lying to the RTS
though not to genapply. The RTS is more important, and it is installed,
*and* this header is installed as part of the RTS.
parent fb43bddc
......@@ -12,7 +12,7 @@ you will screw up the layout where they are used in case expressions!
/* Useful in the headers that we share with the RTS */
#define COMPILING_GHC 1
/* Pull in all the platform defines for this build (foo_TARGET_ARCH etc.) */
/* Pull in all the platform defines for this build (foo_HOST_ARCH etc.) */
#include "ghc_boot_platform.h"
/* Pull in the autoconf defines (HAVE_FOO), but don't include
......
......@@ -1962,11 +1962,13 @@ doCpp dflags raw input_fn output_fn = do
let cpp_prog args | raw = SysTools.runCpp dflags args
| otherwise = SysTools.runCc Nothing dflags (SysTools.Option "-E" : args)
let targetArch = stringEncodeArch $ platformArch $ targetPlatform dflags
targetOS = stringEncodeOS $ platformOS $ targetPlatform dflags
let target_defs =
[ "-D" ++ HOST_OS ++ "_BUILD_OS",
"-D" ++ HOST_ARCH ++ "_BUILD_ARCH",
"-D" ++ TARGET_OS ++ "_HOST_OS",
"-D" ++ TARGET_ARCH ++ "_HOST_ARCH" ]
"-D" ++ targetOS ++ "_HOST_OS",
"-D" ++ targetArch ++ "_HOST_ARCH" ]
-- remember, in code we *compile*, the HOST is the same our TARGET,
-- and BUILD is the same as our HOST.
......
......@@ -1503,9 +1503,11 @@ versionedAppDir dflags = do
-- constructing platform-version-dependent files that need to co-exist.
--
versionedFilePath :: DynFlags -> FilePath
versionedFilePath dflags = TARGET_ARCH
++ '-':TARGET_OS
++ '-':projectVersion dflags
versionedFilePath dflags = intercalate "-"
[ stringEncodeArch $ platformArch $ targetPlatform dflags
, stringEncodeOS $ platformOS $ targetPlatform dflags
, projectVersion dflags
]
-- NB: This functionality is reimplemented in Cabal, so if you
-- change it, be sure to update Cabal.
......@@ -5503,7 +5505,7 @@ addIncludePath p =
addFrameworkPath p =
upd (\s -> s{frameworkPaths = frameworkPaths s ++ splitPathList p})
#if !defined(mingw32_TARGET_OS)
#if !defined(mingw32_HOST_OS)
split_marker :: Char
split_marker = ':' -- not configurable (ToDo)
#endif
......@@ -5515,7 +5517,7 @@ splitPathList s = filter notNull (splitUp s)
-- cause confusion when they are translated into -I options
-- for passing to gcc.
where
#if !defined(mingw32_TARGET_OS)
#if !defined(mingw32_HOST_OS)
splitUp xs = split split_marker xs
#else
-- Windows: 'hybrid' support for DOS-style paths in directory lists.
......
......@@ -493,11 +493,8 @@ generateVersionHs :: Expr String
generateVersionHs = do
trackGenerateHs
projectVersion <- getSetting ProjectVersion
targetOs <- getSetting TargetOs
targetArch <- getSetting TargetArch
return $ unlines
[ "module Version where"
, "version, targetOS, targetARCH :: String"
, "version :: String"
, "version = " ++ show projectVersion
, "targetOS = " ++ show targetOs
, "targetARCH = " ++ show targetArch ]
]
......@@ -27,7 +27,7 @@
hackery can go away sometime.
------------------------------------------------------------------------- */
#if defined(x86_64_TARGET_ARCH)
#if defined(x86_64_HOST_ARCH)
#define OFFSET_FIELD(n) StgHalfInt n; StgHalfWord __pad_##n
#else
#define OFFSET_FIELD(n) StgInt n
......@@ -153,7 +153,7 @@ typedef union {
} StgClosureInfo;
#if defined(x86_64_TARGET_ARCH) && defined(TABLES_NEXT_TO_CODE)
#if defined(x86_64_HOST_ARCH) && defined(TABLES_NEXT_TO_CODE)
// On x86_64 we can fit a pointer offset in half a word, so put the SRT offset
// in the info->srt field directly.
//
......@@ -338,7 +338,7 @@ typedef struct StgConInfoTable_ {
* info must be a Stg[Ret|Thunk]InfoTable* (an info table that has a SRT)
*/
#if defined(TABLES_NEXT_TO_CODE)
#if defined(x86_64_TARGET_ARCH)
#if defined(x86_64_HOST_ARCH)
#define GET_SRT(info) \
((StgClosure*) (((StgWord) ((info)+1)) + (info)->i.srt))
#else
......@@ -365,7 +365,7 @@ typedef struct StgConInfoTable_ {
* info must be a StgFunInfoTable*
*/
#if defined(TABLES_NEXT_TO_CODE)
#if defined(x86_64_TARGET_ARCH)
#if defined(x86_64_HOST_ARCH)
#define GET_FUN_SRT(info) \
((StgClosure*) (((StgWord) ((info)+1)) + (info)->i.srt))
#else
......
......@@ -32,32 +32,32 @@
#define MACHREGS_NO_REGS 0
#if defined(i386_TARGET_ARCH)
#if defined(i386_HOST_ARCH)
#define MACHREGS_i386 1
#endif
#if defined(x86_64_TARGET_ARCH)
#if defined(x86_64_HOST_ARCH)
#define MACHREGS_x86_64 1
#endif
#if defined(powerpc_TARGET_ARCH) || defined(powerpc64_TARGET_ARCH) \
|| defined(powerpc64le_TARGET_ARCH) || defined(rs6000_TARGET_ARCH)
#if defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH) \
|| defined(powerpc64le_HOST_ARCH) || defined(rs6000_HOST_ARCH)
#define MACHREGS_powerpc 1
#endif
#if defined(sparc_TARGET_ARCH)
#if defined(sparc_HOST_ARCH)
#define MACHREGS_sparc 1
#endif
#if defined(arm_TARGET_ARCH)
#if defined(arm_HOST_ARCH)
#define MACHREGS_arm 1
#endif
#if defined(aarch64_TARGET_ARCH)
#if defined(aarch64_HOST_ARCH)
#define MACHREGS_aarch64 1
#endif
#if defined(darwin_TARGET_OS)
#if defined(darwin_HOST_OS)
#define MACHREGS_darwin 1
#endif
......
......@@ -2440,7 +2440,7 @@ stg_traceEventzh ( W_ msg )
// We should go through the macro HASKELLEVENT_USER_MSG_ENABLED from
// RtsProbes.h, but that header file includes unistd.h, which doesn't
// work in Cmm
#if !defined(solaris2_TARGET_OS)
#if !defined(solaris2_HOST_OS)
(enabled) = ccall __dtrace_isenabled$HaskellEvent$user__msg$v1();
#else
// Solaris' DTrace can't handle the
......@@ -2482,7 +2482,7 @@ stg_traceMarkerzh ( W_ msg )
W_ enabled;
#if !defined(solaris2_TARGET_OS)
#if !defined(solaris2_HOST_OS)
(enabled) = ccall __dtrace_isenabled$HaskellEvent$user__marker$v1();
#else
enabled = 1;
......
......@@ -12,8 +12,12 @@
-- for details
module Main(main) where
-- We improperly include *HOST* macros for our target...
#include "../../includes/ghcconfig.h"
-- .. so that this header defines the right stuff.
#include "../../includes/stg/HaskellMachRegs.h"
#include "../../includes/rts/Constants.h"
-- Needed for TAG_BITS
......
......@@ -17,10 +17,8 @@ utils/ghc-pkg/dist/build/Version.hs \
utils/ghc-pkg/dist-install/build/Version.hs: mk/project.mk | $$(dir $$@)/.
$(call removeFiles,$@)
echo "module Version where" >> $@
echo "version, targetOS, targetARCH :: String" >> $@
echo "version :: String" >> $@
echo "version = \"$(ProjectVersion)\"" >> $@
echo "targetOS = \"$(TargetOS_CPP)\"" >> $@
echo "targetARCH = \"$(TargetArch_CPP)\"" >> $@
utils/ghc-pkg_PACKAGE = ghc-pkg
......
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