Skip to content

Extract mangled names from .swiftinterface rather than using nm #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 10, 2024

Conversation

DougGregor
Copy link
Member

The Swift compiler recently added a frontend option (in swiftlang/swift#76600) -abi-comments-in-module-interface that emits ABI-related comments into the generated Swift interface file. Parse the resulting // MANGLED NAME: comments to extract mangled name information for public symbols instead of relying on hardcoded nm invocations on the shared library.

Note that this pull request means that jextract-swift will require an as-yet-unreleased Swift compiler that comes from the main branch. At present, there is no downloadable toolchain containing the compiler fix, so I'm starting by opening this as a draft. Once downloadable toolchains are available for all platforms, we can update the documentation to point jextract-swift users there and merge this pull request.

Remove all of the supporting code for querying nm, which turns out to be a lot :).

The Swift compiler is growing an option to emit mangled names along with
various operations. Build example .swiftinterfaces with that option and
rely on parsing the mangled name from there instead of 'nm'.
@DougGregor DougGregor requested a review from ktoso October 1, 2024 04:43
Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks! Great to get rid of the vendored-in subprocess (and nm hack 😉)

Waiting for a toolchain then... 🕐

@ktoso ktoso mentioned this pull request Oct 2, 2024
1 task
@ktoso
Copy link
Collaborator

ktoso commented Oct 2, 2024

Sorry for the conflicts, but should be easy to resolve -- it's the to-be-removed subprocess mostly 🙇

@DougGregor
Copy link
Member Author

DougGregor commented Oct 2, 2024

Sorry for the conflicts, but should be easy to resolve -- it's the to-be-removed subprocess mostly 🙇

No worries! The conflicts are all easy to resolve when it's time.

@ktoso ktoso force-pushed the swiftinterface-mangled-names branch from 3514b58 to 482e703 Compare October 10, 2024 08:07
@ktoso ktoso marked this pull request as ready for review October 10, 2024 08:51
@ktoso
Copy link
Collaborator

ktoso commented Oct 10, 2024

Look at who's passing on Linux:


MySwiftClassTest > test_MySwiftClass_voidMethod() STANDARD_OUT
    [java][MySwiftClass.java:131] Downcall: <init>(12, 42)
    [java][MySwiftClass.java:528] Downcall: voidMethod(MemorySegment{ address: 0x7f337c92b620, byteSize: 0 })

MySwiftClassTest > test_MySwiftClass_makeIntMethod() STANDARD_OUT
    [java][MySwiftClass.java:131] Downcall: <init>(12, 42)
    [java][MySwiftClass.java:736] Downcall: makeIntMethod(MemorySegment{ address: 0x7f337c92c030, byteSize: 0 })

and all of its friends 😄

@ktoso ktoso merged commit 38fdd9e into swiftlang:main Oct 10, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants