[Git][ghc/ghc][wip/marge_bot_batch_merge_job] 4 commits: hadrian: Add missing deriveConstants dependency on ghcplatform.h

Marge Bot gitlab at gitlab.haskell.org
Fri Jun 5 22:13:08 UTC 2020



 Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC


Commits:
c9ab4254 by Ben Gamari at 2020-06-05T09:32:35-04:00
hadrian: Add missing deriveConstants dependency on ghcplatform.h

deriveConstants wants to compile C sources which #include PosixSource.h,
which itself #includes ghcplatform.h. Make sure that Hadrian knows
about this dependency.

Fixes #18290.

- - - - -
96e6b5ff by Moritz Angermann at 2020-06-05T18:13:02-04:00
ghc-prim needs to depend on libc and libm

libm is just an empty shell on musl, and all the math functions are contained in
libc.

- - - - -
48af0602 by Moritz Angermann at 2020-06-05T18:13:02-04:00
Disable DLL loading if without system linker

Some platforms (musl, aarch64) do not have a working dynamic linker
implemented in the libc, even though we might see dlopen.  It will
ultimately just return that this is not supported.  Hence we'll add
a flag to the compiler to flat our disable loading dlls.  This is
needed as we will otherwise try to load the shared library even
if this will subsequently fail.  At that point we have given up
looking for static options though.

- - - - -
b1498ed6 by Moritz Angermann at 2020-06-05T18:13:03-04:00
Range is actually +/-2^32, not +/-2^31

See also: https://static.docs.arm.com/ihi0056/g/aaelf64.pdf

- - - - -


5 changed files:

- compiler/GHC/Runtime/Linker.hs
- compiler/ghc.cabal.in
- hadrian/src/Rules/Generate.hs
- libraries/ghc-prim/ghc-prim.cabal
- rts/linker/elf_reloc_aarch64.c


Changes:

=====================================
compiler/GHC/Runtime/Linker.hs
=====================================
@@ -1328,6 +1328,7 @@ linkPackage hsc_env pkg
             ("Loading package " ++ unitPackageIdString pkg ++ " ... ")
 
         -- See comments with partOfGHCi
+#if defined(CAN_LOAD_DLL)
         when (unitPackageName pkg `notElem` partOfGHCi) $ do
             loadFrameworks hsc_env platform pkg
             -- See Note [Crash early load_dyn and locateLib]
@@ -1336,7 +1337,7 @@ linkPackage hsc_env pkg
             -- For remaining `dlls` crash early only when there is surely
             -- no package's DLL around ... (not is_dyn)
             mapM_ (load_dyn hsc_env (not is_dyn) . mkSOName platform) dlls
-
+#endif
         -- After loading all the DLLs, we can load the static objects.
         -- Ordering isn't important here, because we do one final link
         -- step to resolve everything.
@@ -1471,10 +1472,15 @@ locateLib hsc_env is_hs lib_dirs gcc_dirs lib
     --   O(n). Loading an import library is also O(n) so in general we prefer
     --   shared libraries because they are simpler and faster.
     --
-  = findDll   user `orElse`
+  =
+#if defined(CAN_LOAD_DLL)
+    findDll   user `orElse`
+#endif
     tryImpLib user `orElse`
+#if defined(CAN_LOAD_DLL)
     findDll   gcc  `orElse`
     findSysDll     `orElse`
+#endif
     tryImpLib gcc  `orElse`
     findArchive    `orElse`
     tryGcc         `orElse`
@@ -1539,7 +1545,13 @@ locateLib hsc_env is_hs lib_dirs gcc_dirs lib
                          full     = dllpath $ search lib_so_name lib_dirs
                          gcc name = liftM (fmap Archive) $ search name lib_dirs
                          files    = import_libs ++ arch_files
-                     in apply $ short : full : map gcc files
+                         dlls     = [short, full]
+                         archives = map gcc files
+                     in apply $
+#if defined(CAN_LOAD_DLL)
+                          dlls ++
+#endif
+                          archives
      tryImpLib re = case os of
                        OSMinGW32 ->
                         let dirs' = if re == user then lib_dirs else gcc_dirs


=====================================
compiler/ghc.cabal.in
=====================================
@@ -55,6 +55,11 @@ Flag integer-gmp
     Manual: True
     Default: False
 
+Flag dynamic-system-linker
+    Description: The system can load dynamic code. This is not the case for musl.
+    Default: True
+    Manual: False
+
 Library
     Default-Language: Haskell2010
     Exposed: False
@@ -108,6 +113,10 @@ Library
         CPP-Options: -DINTEGER_SIMPLE
         build-depends: integer-simple >= 0.1.1.1
 
+    -- if no dynamic system linker is available, don't try DLLs.
+    if flag(dynamic-system-linker)
+        CPP-Options: -DCAN_LOAD_DLL
+
     Other-Extensions:
         BangPatterns
         CPP


=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -185,6 +185,9 @@ generateRules = do
         -- TODO: simplify, get rid of fake rts context
         for_ (fst <$> deriveConstantsPairs) $ \constantsFile ->
             prefix -/- constantsFile %> \file -> do
+                -- N.B. deriveConstants needs to compile programs which #include
+                -- PosixSource.h, which #include's ghcplatform.h. Fixes #18290.
+                need [prefix -/- "ghcplatform.h"]
                 withTempDir $ \dir -> build $
                     target (rtsContext stage) DeriveConstants [] [file, dir]
   where


=====================================
libraries/ghc-prim/ghc-prim.cabal
=====================================
@@ -68,6 +68,11 @@ Library
         --         on Windows. Required because of mingw32.
         extra-libraries: user32, mingw32, mingwex
 
+    if os(linux)
+        -- we need libm, but for musl and other's we might need libc, as libm
+        -- is just an empty shell.
+        extra-libraries: c, m
+
     c-sources:
         cbits/atomic.c
         cbits/bswap.c


=====================================
rts/linker/elf_reloc_aarch64.c
=====================================
@@ -93,12 +93,14 @@ encodeAddendAarch64(Section * section, Elf_Rel * rel, int64_t addend) {
             // ...              hi            ] [     Rd     ]
             //
             // imm64 = SignExtend(hi:lo:0x000,64)
-            assert(isInt64(32, addend));
+            // Range is 21 bits + the 12 page relative bits
+            // known to be 0. -2^32 <= X < 2^32
+            assert(isInt64(21+12, addend));
             assert((addend & 0xfff) == 0); /* page relative */
 
             *(inst_t *)P = (*(inst_t *)P & 0x9f00001f)
-                           | (inst_t) (((uint64_t) addend << 17) & 0x60000000)
-                           | (inst_t) (((uint64_t) addend >> 9) & 0x00ffffe0);
+                        | (inst_t) (((uint64_t) addend << 17) & 0x60000000)
+                        | (inst_t) (((uint64_t) addend >> 9) & 0x00ffffe0);
             break;
         }
         /* - control flow relocations */
@@ -111,8 +113,8 @@ encodeAddendAarch64(Section * section, Elf_Rel * rel, int64_t addend) {
             break;
         }
         case COMPAT_R_AARCH64_ADR_GOT_PAGE: {
-
-            assert(isInt64(32, addend)); /* X in range */
+            /* range is -2^32 <= X < 2^32 */
+            assert(isInt64(21+12, addend)); /* X in range */
             assert((addend & 0xfff) == 0); /* page relative */
 
             *(inst_t *)P = (*(inst_t *)P & 0x9f00001f)



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/05dc1ca946dc4f9b59c7c5e34b2fd9b8d921cde7...b1498ed6a7be554e4ae1b37d19e68dba0fe3d4a5

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/05dc1ca946dc4f9b59c7c5e34b2fd9b8d921cde7...b1498ed6a7be554e4ae1b37d19e68dba0fe3d4a5
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200605/76dab2f8/attachment-0001.html>


More information about the ghc-commits mailing list