[Git][ghc/ghc][wip/T22011] rts: Add generator for RtsSymbols from libgcc
Ben Gamari (@bgamari)
gitlab at gitlab.haskell.org
Thu Jul 6 19:04:09 UTC 2023
Ben Gamari pushed to branch wip/T22011 at Glasgow Haskell Compiler / GHC
Commits:
7c0486d9 by Ben Gamari at 2023-07-06T15:04:00-04:00
rts: Add generator for RtsSymbols from libgcc
- - - - -
4 changed files:
- hadrian/src/Rules/Generate.hs
- hadrian/src/Rules/Register.hs
- rts/RtsSymbols.c
- + rts/gen_libgcc_symbols.py
Changes:
=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -59,21 +59,26 @@ rtsDependencies = do
jsTarget <- expr isJsTarget
useSystemFfi <- expr (flag UseSystemFfi)
- let -- headers common to native and JS RTS
+ let in_include file = rtsPath -/- "include" -/- file
+
+ -- headers common to native and JS RTS
common_headers =
+ map in_include
[ "ghcautoconf.h", "ghcplatform.h"
, "DerivedConstants.h"
]
-- headers specific to the native RTS
native_headers =
+ map in_include
[ "rts" -/- "EventTypes.h"
, "rts" -/- "EventLogConstants.h"
]
- ++ (if useSystemFfi then [] else libffiHeaderFiles)
+ ++ (if useSystemFfi then [] else map in_include libffiHeaderFiles)
+ ++ [ in_include $ rtsPath -/- "LibgccSymbols.h" ]
headers
| jsTarget = common_headers
| otherwise = common_headers ++ native_headers
- pure $ ((rtsPath -/- "include") -/-) <$> headers
+ pure headers
genapplyDependencies :: Expr [FilePath]
genapplyDependencies = do
@@ -166,7 +171,7 @@ generatePackageCode context@(Context stage pkg _ _) = do
[accessOpsSource, "addr-access-ops", file]
[] []
root -/- primopsTxt stage %> \file -> do
- need $ [primopsSource, ba_ops_txt, addr_ops_txt]
+ need [primopsSource, ba_ops_txt, addr_ops_txt]
-- ba_ops_txt and addr_ops_txt get #include-d
build $ target context HsCpp [primopsSource] [file]
@@ -180,13 +185,29 @@ generatePackageCode context@(Context stage pkg _ _) = do
root -/- "**" -/- dir -/- "include/DerivedConstants.h" %> genPlatformConstantsHeader context
root -/- "**" -/- dir -/- "include/rts/EventLogConstants.h" %> genEventTypes "--event-types-defines"
root -/- "**" -/- dir -/- "include/rts/EventTypes.h" %> genEventTypes "--event-types-array"
+ root -/- "**" -/- dir -/- "LibgccSymbols.h" %> genLibgccSymbols context
+
+genLibgccSymbols :: Context -> FilePath -> Action ()
+genLibgccSymbols (Context stage _ _ _) outFile = do
+ libgcc <- getLibgccPath
+ need [script]
+ runBuilder Python [script, libgcc, "-o", outFile] [] []
+ where
+ script = "rts" -/- "gen_libgcc_symbols.py"
+ getLibgccPath :: Action FilePath
+ getLibgccPath = do
+ let builder = Cc CompileC stage
+ needBuilders [builder]
+ path <- builderPath builder
+ StdoutTrim libgcc <- quietly $ cmd [path] ["-print-libgcc-file-name"]
+ return libgcc
genEventTypes :: String -> FilePath -> Action ()
genEventTypes flag file = do
- need ["rts" -/- "gen_event_types.py"]
- runBuilder Python
- ["rts" -/- "gen_event_types.py", flag, file]
- [] []
+ need [script]
+ runBuilder Python [script, flag, file] [] []
+ where
+ script = "rts" -/- "gen_event_types.py"
genPrimopCode :: Context -> FilePath -> Action ()
genPrimopCode context@(Context stage _pkg _ _) file = do
=====================================
hadrian/src/Rules/Register.hs
=====================================
@@ -212,6 +212,7 @@ buildConfInplace rs context at Context {..} _conf = do
, path -/- "include/ghcplatform.h"
, path -/- "include/rts/EventLogConstants.h"
, path -/- "include/rts/EventTypes.h"
+ , path -/- "LibgccSymbols.h"
]
-- we need to generate this file for GMP
=====================================
rts/RtsSymbols.c
=====================================
@@ -983,6 +983,10 @@ extern char **environ;
#define RTS_FINI_ARRAY_SYMBOLS
#endif
+// Symbols defined by libgcc/compiler-rt. This file is generated by
+// gen_libgcc_symbols.py.
+#include "LibgccSymbols.h"
+
/* entirely bogus claims about types of these symbols */
#define SymI_NeedsProto(vvv) extern void vvv(void);
#define SymI_NeedsDataProto(vvv) extern StgWord vvv[];
@@ -1014,6 +1018,7 @@ RTS_LIBC_SYMBOLS
RTS_LIBGCC_SYMBOLS
RTS_FINI_ARRAY_SYMBOLS
RTS_LIBFFI_SYMBOLS
+RTS_LIBGCC_SYMBOLS
#undef SymI_NeedsProto
#undef SymI_NeedsDataProto
@@ -1055,9 +1060,7 @@ RtsSymbolVal rtsSyms[] = {
RTS_LIBGCC_SYMBOLS
RTS_FINI_ARRAY_SYMBOLS
RTS_LIBFFI_SYMBOLS
-#if defined(linux_HOST_OS) && defined(aarch64_HOST_ARCH)
-#include "AArch64Symbols.h"
-#endif
+ RTS_LIBGCC_SYMBOLS
SymI_HasDataProto(nonmoving_write_barrier_enabled)
#if defined(darwin_HOST_OS) && defined(i386_HOST_ARCH)
// dyld stub code contains references to this,
=====================================
rts/gen_libgcc_symbols.py
=====================================
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+
+import sys
+import subprocess
+import argparse
+from typing import Set
+from pathlib import Path
+
+def list_symbols(lib: Path) -> Set[str]:
+ out = subprocess.check_output([
+ 'nm', '--format=posix', '--extern-only', '--defined-only', lib
+ ], encoding='ASCII')
+ syms = set()
+ for l in out.split('\n'):
+ parts = l.split(' ')
+ if len(parts) == 4:
+ syms.add(parts[0])
+
+ return syms
+
+def main() -> None:
+ parser = argparse.ArgumentParser()
+ parser.add_argument('libgcc', type=Path, help='path to libgcc')
+ parser.add_argument('-o', '--output', default=sys.stdout, type=argparse.FileType('w'), help='output file name')
+ args = parser.parse_args()
+
+ syms = list_symbols(args.libgcc)
+ print('#define RTS_LIBGCC_SYMBOLS \\', file=args.output)
+ print('\n'.join(f' SymE_NeedsProto({sym}) \\' for sym in sorted(syms)),
+ file=args.output)
+
+if __name__ == '__main__':
+ main()
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/7c0486d9a996bd56287d0f51c4a918e43fda2c0a
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/7c0486d9a996bd56287d0f51c4a918e43fda2c0a
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/20230706/a09e3651/attachment-0001.html>
More information about the ghc-commits
mailing list