summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoritz Angermann <moritz.angermann@gmail.com>2021-02-13 16:33:31 +0800
committerMoritz Angermann <moritz.angermann@gmail.com>2021-02-15 22:41:00 +0800
commit9d687f09629f2f84bef7d80c8378be29051ca85a (patch)
tree88ffd9e2dc53fd7bf50d2348e997875fdd1dd358
parenta000a793df08002bf9618ea8e52a32096715e7c0 (diff)
downloadhaskell-9d687f09629f2f84bef7d80c8378be29051ca85a.tar.gz
[aarch64] always PIC
this is effectively now required.
-rw-r--r--aclocal.m43
-rw-r--r--compiler/main/DynFlags.hs30
-rw-r--r--compiler/main/SysTools.hs2
-rw-r--r--docs/users_guide/runtime_control.rst6
-rw-r--r--rts/package.conf.in2
-rw-r--r--rts/rts.cabal.in2
6 files changed, 31 insertions, 14 deletions
diff --git a/aclocal.m4 b/aclocal.m4
index c39aff28c8..73791cd1b3 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -328,7 +328,8 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
[AC_LANG_PROGRAM([], [__asm__ (".subsections_via_symbols");])],
[AC_MSG_RESULT(yes)
if test x"$TargetArch" = xaarch64; then
- dnl subsections via symbols is busted on arm64
+ dnl subsections via symbols is busted on arm64 (aarch64-darwin)
+ dnl see #19379
TargetHasSubsectionsViaSymbols=NO
else
TargetHasSubsectionsViaSymbols=YES
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index 2ea0b3d5e9..8432c57cc0 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -4646,14 +4646,28 @@ validHoleFitsImpliedGFlags
default_PIC :: Platform -> [GeneralFlag]
default_PIC platform =
case (platformOS platform, platformArch platform) of
- (OSDarwin, ArchX86_64) -> [Opt_PIC]
- (OSOpenBSD, ArchX86_64) -> [Opt_PIC] -- Due to PIE support in
- -- OpenBSD since 5.3 release
- -- (1 May 2013) we need to
- -- always generate PIC. See
- -- #10597 for more
- -- information.
- _ -> []
+ -- Darwin always requires PIC. Especially on more recent macOS releases
+ -- there will be a 4GB __ZEROPAGE that prevents us from using 32bit addresses
+ -- while we could work around this on x86_64 (like WINE does), we won't be
+ -- able on aarch64, where this is enforced.
+ (OSDarwin, ArchX86_64) -> [Opt_PIC]
+ -- For AArch64, we need to always have PIC enabled. The relocation model
+ -- on AArch64 does not permit arbitrary relocations. Under ASLR, we can't
+ -- control much how far apart symbols are in memory for our in-memory static
+ -- linker; and thus need to ensure we get sufficiently capable relocations.
+ -- This requires PIC on AArch64, and ExternalDynamicRefs on Linux on top
+ -- of that. Subsequently we expect all code on aarch64/linux (and macOS) to
+ -- be built with -fPIC.
+ -- See #15275, #18892
+ (OSDarwin, ArchAArch64) -> [Opt_PIC]
+ (OSLinux, ArchAArch64) -> [Opt_PIC, Opt_ExternalDynamicRefs]
+ (OSOpenBSD, ArchX86_64) -> [Opt_PIC] -- Due to PIE support in
+ -- OpenBSD since 5.3 release
+ -- (1 May 2013) we need to
+ -- always generate PIC. See
+ -- #10597 for more
+ -- information.
+ _ -> []
-- We usually want to use RPath, except on macOS (OSDarwin). On recent macOS
diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs
index 4a301e0837..bed0251a47 100644
--- a/compiler/main/SysTools.hs
+++ b/compiler/main/SysTools.hs
@@ -370,7 +370,7 @@ linkDynLib dflags0 o_files dep_packages
++ [ Option "-undefined",
Option "dynamic_lookup",
Option "-single_module" ]
- ++ (if platformArch platform == ArchX86_64
+ ++ (if platformArch platform `elem` [ ArchX86_64, ArchAArch64 ]
then [ ]
else [ Option "-Wl,-read_only_relocs,suppress" ])
++ [ Option "-install_name", Option instName ]
diff --git a/docs/users_guide/runtime_control.rst b/docs/users_guide/runtime_control.rst
index 73e8824154..d341a763ce 100644
--- a/docs/users_guide/runtime_control.rst
+++ b/docs/users_guide/runtime_control.rst
@@ -313,8 +313,10 @@ Miscellaneous RTS options
an object, the linker will probably fail with an error message when the
problem is detected.
- On some platforms where PIC is always the case, e.g. x86_64 MacOS X, this
- flag is enabled by default.
+ On some platforms where PIC is always the case, e.g. macOS and OpenBSD on
+ x86_64, and macOS and Linux on aarch64 this flag is enabled by default.
+ One repercussion of this is that referenced system libraries also need to be
+ compiled with ``-fPIC`` if we need to load them in the runtime linker.
.. rts-flag:: -xm ⟨address⟩
diff --git a/rts/package.conf.in b/rts/package.conf.in
index e4cb159cb8..6e1d19d588 100644
--- a/rts/package.conf.in
+++ b/rts/package.conf.in
@@ -296,7 +296,7 @@ ld-options:
, "-Wl,-search_paths_first"
#endif
-#if defined(darwin_HOST_OS) && !defined(x86_64_HOST_ARCH)
+#if defined(darwin_HOST_OS) && !defined(x86_64_HOST_ARCH) && !defined(aarch64_HOST_ARCH)
, "-read_only_relocs", "warning"
#endif
diff --git a/rts/rts.cabal.in b/rts/rts.cabal.in
index cab390ed30..478e545589 100644
--- a/rts/rts.cabal.in
+++ b/rts/rts.cabal.in
@@ -368,7 +368,7 @@ library
if os(osx)
ld-options: "-Wl,-search_paths_first"
- if !arch(x86_64)
+ if !arch(x86_64) && !arch(aarch64)
ld-options: -read_only_relocs warning
cmm-sources: Apply.cmm