Fix TCC symbol lookup failure on macOS in c_loader #640
Fix TCC symbol lookup failure on macOS in c_loader #640ROKUMATE wants to merge 1 commit intometacall:developfrom
Conversation
|
Have you tested this? It is just wrong... |
|
Hey, thanks for the review. Could you point out specifically what's wrong? |
|
Here's our reasoning and test: https://gist.github.com/ROKUMATE/8191109dbbbe5816a91ad771369ed399 The gist shows that without the _ stripping, system TCC (macOS ABI) stores _compiled_print but the lookup always uses the plain Clang-reported name compiled_print → not found → symbol skipped. That's the root cause |
|
@ROKUMATE here is the full review of your PR: 6496e03 As there is no way to know at compile time if TCC is going to produce "_" or not, I checked their repo for seeing if there is any version where they introduced the flag to test against it but I found nothing. Due to that I did a simple check at runtime for detecting if the symbols are underscored using the same method of the list. I wasn't neither sure if the tcc_get_symbol would be quivalent, that's why. This should work in any case and always properly. Your case could introduce something like having a symbol with _ in the real name and getting deleted although tcc uses no symbol, preventing the C Loader to find it later on. |
|
The runtime check is much safer. I'll study your commit to understand the pattern for future contributions. |
Summary
Fixes #442 — the C loader test (
metacall_test) fails on macOS because TCC-compiled symbols cannot be discovered, with the error:Root Cause
On macOS, TCC may store symbols with a leading
_prefix per the platform ABI (e.g.compiled_print→_compiled_print). Clang's AST parser always reports plain names. When the symbols map is populated with_-prefixed names, the plain-name lookup inc_loader_impl_discover_signaturefails.The existing
#if __APPLE__workaround inc_loader_impl_discover_signaturetried to compensate by prepending_at lookup time — this worked for the system TCC, but fails with the MetaCall forked TCC (which does NOT add the underscore prefix). Since CI uses the forked TCC (by design), the test failed.Fix
Rather than patching the lookup side (which is TCC-variant-dependent), normalize symbol names at insertion time in
c_loader_impl_discover_symbols:_from the symbol name before inserting into the mapifcondition is false, no change in behaviour_is stripped, map holds plain nameThen remove the now-redundant
#if __APPLE__prefix-prepend inc_loader_impl_discover_signatureso lookups always use the plain Clang-reported name.Files Changed
source/loaders/c_loader/source/c_loader_impl.cppc_loader_impl_discover_symbols()— strip leading_on macOS at insertion timec_loader_impl_discover_signature()— remove#if __APPLE__block, usefunc_namedirectlyTesting
Build verified clean. The fix makes behaviour consistent across both TCC variants.