David Eichmann pushed to branch wip/davide/windows-dlls_sysm-test_master at Glasgow Haskell Compiler / GHC Commits: ba364142 by David Eichmann at 2026-10-22T16:58:49+01:00 RtsSymbols stores redirect labels Redirect labels are used by the rts-check-symbols test - - - - - 8 changed files: - rts/RtsSymbols.c - rts/include/rts/RtsSymbols.h - testsuite/tests/ghci/linking/T25155_iserv_main.c - testsuite/tests/rts/symbols/Main.hs - testsuite/tests/rts/symbols/all.T - testsuite/tests/rts/symbols/dumpDeclaredSymbols.c - testsuite/tests/rts/symbols/rts-check-symbols.ignore - testsuite/tests/rts/symbols/rts-check-symbols.stdout Changes: ===================================== rts/RtsSymbols.c ===================================== @@ -1220,13 +1220,13 @@ RTS_SYMBOLS_PRIM /* See Note [Naming Scheme for Symbol Macros] */ #define SymI_HasProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \ - (void*)(&(vvv)), STRENGTH_NORMAL, SYM_TYPE_CODE }, + (void*)(&(vvv)), STRENGTH_NORMAL, SYM_TYPE_CODE, NULL }, #define SymI_HasDataProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \ - (void*)(&(vvv)), STRENGTH_NORMAL, SYM_TYPE_DATA }, + (void*)(&(vvv)), STRENGTH_NORMAL, SYM_TYPE_DATA, NULL }, #define SymE_HasProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \ - (void*)(&(vvv)), STRENGTH_NORMAL, SYM_TYPE_CODE }, + (void*)(&(vvv)), STRENGTH_NORMAL, SYM_TYPE_CODE, NULL }, #define SymE_HasDataProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \ - (void*)(&(vvv)), STRENGTH_NORMAL, SYM_TYPE_DATA }, + (void*)(&(vvv)), STRENGTH_NORMAL, SYM_TYPE_DATA, NULL }, #define SymI_NeedsProto(vvv) SymI_HasProto(vvv) #define SymI_NeedsDataProto(vvv) SymI_HasDataProto(vvv) @@ -1237,7 +1237,7 @@ RTS_SYMBOLS_PRIM // another symbol. See newCAF/newRetainedCAF/newGCdCAF for an example. #define SymI_HasProto_redirect(vvv,xxx,strength,ty) \ { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \ - (void*)(&(xxx)), strength, ty }, + (void*)(&(xxx)), strength, ty, MAYBE_LEADING_UNDERSCORE_STR(#xxx) }, static RtsSymbolVal * rtsSyms = NULL; @@ -1264,7 +1264,7 @@ RtsSymbolVal const * getRtsSymbols(void) { RTS_ARM_OUTLINE_ATOMIC_SYMBOLS RTS_SYMBOLS_PRIM SymI_HasDataProto(nonmoving_write_barrier_enabled) - { 0, 0, STRENGTH_NORMAL, SYM_TYPE_CODE } /* sentinel */ + { 0, 0, STRENGTH_NORMAL, SYM_TYPE_CODE, NULL } /* sentinel */ }; uint32_t n = 1; @@ -1362,7 +1362,7 @@ RtsSymbolVal const * getRtsSymbols(void) { // CODE_SYM(getauxval) // CODE_SYM(posix_spawn_file_actions_init) // ... -// { 0, 0, STRENGTH_NORMAL, SYM_TYPE_CODE } /* sentinel */ +// { 0, 0, STRENGTH_NORMAL, SYM_TYPE_CODE, NULL } /* sentinel */ // }; // // RtsSymbolVal* rtsExtraSyms() { @@ -1375,7 +1375,7 @@ RtsSymbolVal const * getRtsSymbols(void) { // static RtsSymbolVal default_extra_syms[] = { - { 0, 0, STRENGTH_NORMAL, SYM_TYPE_CODE } /* sentinel */ + { 0, 0, STRENGTH_NORMAL, SYM_TYPE_CODE, NULL } /* sentinel */ }; /* Default empty extra RTS symbols. See Note[Extra RTS symbols] */ ===================================== rts/include/rts/RtsSymbols.h ===================================== @@ -8,6 +8,7 @@ #pragma once +#include <stdbool.h> typedef void SymbolAddr; typedef char SymbolName; @@ -36,6 +37,9 @@ typedef struct _RtsSymbolVal { SymbolAddr* addr; SymStrength strength; SymType type; + // If this is a redirection, then this is the lable of the + // target symbol. Otherwise NULL. + const SymbolName* lbl_redirect_target; } RtsSymbolVal; RtsSymbolVal const * getRtsSymbols(void); ===================================== testsuite/tests/ghci/linking/T25155_iserv_main.c ===================================== @@ -23,7 +23,7 @@ int main (int argc, char *argv[]) // can use the FFI call to foobar in a TH splice. #define SymI_HasProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \ - (void*)(&(vvv)), STRENGTH_NORMAL, SYM_TYPE_CODE }, + (void*)(&(vvv)), STRENGTH_NORMAL, SYM_TYPE_CODE, NULL }, void foobar(int x) { ===================================== testsuite/tests/rts/symbols/Main.hs ===================================== @@ -19,18 +19,26 @@ main = do -- want to avoid copying that logic again in the test. So we just ignore some -- symbols so that CI can pass and in the future we aim to fix RtsSymbols.c and -- reduce the size of ignoredSymbols. - ignoreSymbols <- S.fromList + ignoreSymbols' <- S.fromList . filter (not . null) . lines <$> readFile ignoreSymbolsFile + let symbolFilter :: String -> CodeOrData -> Bool + symbolFilter name cd = + -- Not in ingore list + not (S.member name ignoreSymbols') + -- Doesn't look like a entry code symbol + -- (These can appear in unregisterd builds wihere tables next to code is disabled) + && not ("_entry" `isSuffixOf` name && cd == Code) + declaredSymbolsStr <- readFile declaredSymbolsFile observedSymbolsStr <- readFile observedSymbolsFile - let declaredSymbols = readCodeOrData <$> linePairs declaredSymbolsStr - let observedSymbols = parseReadelf observedSymbolsStr + let declaredSymbols = M.filterWithKey symbolFilter $ readCodeOrData <$> linePairs declaredSymbolsStr + let observedSymbols = M.filterWithKey symbolFilter $ parseReadelf observedSymbolsStr - let diffStr = diff ignoreSymbols declaredSymbols observedSymbols + let diffStr = diff declaredSymbols observedSymbols -- writeFile "<ghc root>/testsuite/tests/rts/symbols/rts-check-symbols.stdout" putStrLn diffStr @@ -44,8 +52,8 @@ data CodeOrData = Code | Data -- Compare observedSymbols (symbols observed in the DSO) to declaredSymbols -- (symbols declared in RtsSymbols.c) -diff :: S.Set String -> M.Map String CodeOrData -> M.Map String CodeOrData -> String -diff ignoreSymbols declaredSymbolsAll observedSymbolsAll = unlines $ +diff :: M.Map String CodeOrData -> M.Map String CodeOrData -> String +diff declaredSymbols observedSymbols = unlines $ [ "Symbols declared in RtsSymbols.c but not observed in the DSO:" ] ++ [ "Declared> " ++ k ++ " " ++ show v | (k, v) <- M.toList diffInDeclaredSymbols ] ++ [ "" ] @@ -56,10 +64,6 @@ diff ignoreSymbols declaredSymbolsAll observedSymbolsAll = unlines $ ++ [ "WrongType> " ++ k ++ " (declared, observed): (" ++ show declared ++ ", " ++ show observed ++ ")" | (k, (declared, observed)) <- M.toList diffOnType ] where - -- Ignore some symbols - declaredSymbols = declaredSymbolsAll `M.withoutKeys` ignoreSymbols - observedSymbols = observedSymbolsAll `M.withoutKeys` ignoreSymbols - -- Undeclared observed symbols diffInObservedSymbols :: M.Map String CodeOrData diffInObservedSymbols = observedSymbols M.\\ declaredSymbols ===================================== testsuite/tests/rts/symbols/all.T ===================================== @@ -1,5 +1,5 @@ test('rts-check-symbols', [ - unless(have_dynamic() and have_readelf() and have_ldd(), skip), + unless(opsys('linux') and have_dynamic() and have_readelf() and have_ldd(), skip), windows_skip, extra_files([ 'dumpDeclaredSymbols.c', ===================================== testsuite/tests/rts/symbols/dumpDeclaredSymbols.c ===================================== @@ -19,8 +19,16 @@ void dumpDeclaredSymbols(void) { type = "data"; } + const char * lbl = NULL; + if (sym->lbl_redirect_target) { + // In the case of redirects, the true symbol name is lbl_redirect_target + lbl = sym->lbl_redirect_target; + } else { + lbl = sym->lbl; + } + if (type) { - printf("%s %s\n", sym->lbl, type); + printf("%s %s\n", lbl, type); } } } ===================================== testsuite/tests/rts/symbols/rts-check-symbols.ignore ===================================== @@ -1,3 +1,16 @@ +__ashldi3 +__ashrdi3 +__divdi3 +__fixunsdfdi +__lshrdi3 +__moddi3 +__muldi3 +__udivdi3 +__udivti3 +__umoddi3 +__umodti3 +_fini +_init complex_ccall_adjustor_template decodeAddendAarch64 encodeAddendAarch64 @@ -30,11 +43,13 @@ isLoadStore isVectorOp makeStub makeStubAarch64 -needStubForRelAarch64 +mblock_address_space +mblock_map needStubForRelaAarch64 +needStubForRelAarch64 numberOfStubsForSection relocateObjectCode relocateObjectCodeAarch64 simple_ccall_adjustor_template StgReturn -stubSizeAarch64 +stubSizeAarch64 \ No newline at end of file ===================================== testsuite/tests/rts/symbols/rts-check-symbols.stdout ===================================== @@ -1,6 +1,4 @@ Symbols declared in RtsSymbols.c but not observed in the DSO: -Declared> __udivti3 Code -Declared> __umodti3 Code Declared> atomic_dec Code Declared> dirty_TVAR Code Declared> ffi_call Code @@ -172,7 +170,6 @@ Observed> lookupIPEId Code Observed> m32_free_page_pool Data Observed> m32_free_page_pool_size Data Observed> makeGot Code -Observed> mblock_address_space Data Observed> mblocks_allocated Data Observed> modules Data Observed> mpc_misses Data View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ba364142b29b702c3b89d131f1f41955... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ba364142b29b702c3b89d131f1f41955... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help