[Git][ghc/ghc][wip/T22011] rts: Add generator for RtsSymbols from libgcc

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Wed Jul 5 18:22:29 UTC 2023



Ben Gamari pushed to branch wip/T22011 at Glasgow Haskell Compiler / GHC


Commits:
2c464418 by Ben Gamari at 2023-07-05T14:22:18-04:00
rts: Add generator for RtsSymbols from libgcc

- - - - -


2 changed files:

- hadrian/src/Rules/Generate.hs
- + rts/gen_libgcc_symbols.py


Changes:

=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -180,13 +180,21 @@ 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 -/- "rts/LibgccSymbols.h" %> genLibgccSymbols
+
+genLibgccSymbols :: FilePath -> Action ()
+genLibgccSymbols outFile = do
+    need [script]
+    runBuilder Python [script, outFile] [] []
+  where
+    script = "rts" -/- "gen_libgcc_symbols.py"
 
 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


=====================================
rts/gen_libgcc_symbols.py
=====================================
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+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')
+    args = parser.parse_args()
+    
+    syms = list_symbols(args.libgcc)
+    print('\n'.join(f'    SymE_NeedsProto({sym}),' for sym in sorted(syms)))
+
+if __name__ == '__main__':
+    main()



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2c464418607a9071cfcc903c9985c8982f3cef0d

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2c464418607a9071cfcc903c9985c8982f3cef0d
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/20230705/a1a8038c/attachment-0001.html>


More information about the ghc-commits mailing list