Skip to content
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

Name mangling for standard vector calling convention #422

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kito-cheng
Copy link
Collaborator

Add extra name mangling rule for standard vector calling convention on C++ ABI, fortunately the Itanium C++ ABI already defined mangling rule for ABI tag, so we just need to define the ABI tag name.

Example for the mangling rule:

__attribute__((riscv_vector_cc)) void foo();
// _Z3fooB15riscv_vector_ccv with this mangling rule
// _Z3foov without this mangling rule

Add extra name mangling rule for standard vector calling convention on
C++ ABI, fortunately the Itanium C++ ABI already defined mangling rule
for ABI tag, so we just need to define the ABI tag name.

Example for the mangling rule:
```c
__attribute__((riscv_vector_cc)) void foo();
// _Z3fooB15riscv_vector_ccv with this mangling rule
// _Z3foov without this mangling rule
```
@kito-cheng kito-cheng requested review from asb, sorear, jrtc27 and lhtin February 2, 2024 13:44
@@ -433,6 +433,10 @@ NOTE: `setjmp`/`longjmp` follow the standard calling convention, which clobbers
all vector registers. Hence, the standard vector calling convention variant
won't disrupt the `jmp_buf` ABI.

NOTE: Functions that use the standard vector calling convention
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need to specially mangle the names of functions that use the vector calling convention. While arguably useful for function multi-versioning and the [[gnu::target_version]] attribute in particular, this is orthogonal to C++ overload resolution.

We do need to mangle function pointer types that use the vector calling convention, whether or not the function taking the parameter itself uses the vector calling convention, to allow overloading a function that takes arguments with different ABIs.

=== Name Mangling for Standard Calling Convention Variant

Function use standard calling convention variant have to append extra ABI tag to
the function name mangling, the rule are same as the "ABI tags" section in
Copy link
Collaborator

Choose a reason for hiding this comment

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

ABI tags (B) are used for the GNU abi_tag extension, which uses a string that is entirely under the control of a library author. It is probably wrong to use for architecture-specific features, and it does not fix my original example since it cannot be used on unnamed entities.

I was originally thinking of using a vendor-defined pointer qualifier as defined in 5.1.5.1 Qualified types, but the closest existing thing to what I'm asking for is the definition of Dx in 5.1.5.3 Function types. We may need upstream guidance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wait, I thought it work? https://gcc.godbolt.org/z/95shE9a13

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(let me read the Itanium C++ ABI more carefully again)

Copy link
Collaborator

@sorear sorear Feb 2, 2024

Choose a reason for hiding this comment

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

f and g in your example have the same calling convention, so there's no need for the compiler to generate two versions. If you add __attribute__((aarch64_sve_pcs)) to g, it breaks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, yeah, I got your main point: it should mangling function (pointer) type, not function name, I thought abi_tag works for function type but it only decorate/mangling function name.

@sorear
Copy link
Collaborator

sorear commented Feb 26, 2024

I filed itanium-cxx-abi/cxx-abi#178 to maybe get an expert opinion. Hope that isn't overstepping.

@kito-cheng
Copy link
Collaborator Author

I filed itanium-cxx-abi/cxx-abi#178 to maybe get an expert opinion. Hope that isn't overstepping.

Thanks for doing this, I think you are better person to create that since you have more context than me on this, will support you on that PR if needed :)

@sorear
Copy link
Collaborator

sorear commented Feb 26, 2024

swiftcall in clang appears to already have the behavior we need.

@kito-cheng kito-cheng marked this pull request as draft March 1, 2024 12:32
@kito-cheng
Copy link
Collaborator Author

Change to draft since this PR is not intend to merge so far, but we may keep this PR for keep tracking and/or discuss this issue.

@kito-cheng
Copy link
Collaborator Author

kito-cheng commented Mar 1, 2024

Oh, I should reply after read the PR, I didn't notice there is some discussion within the PR, anyway let me find some time to update and update this PR later.

(@sorear you can create another PR if you are interested since I may deal with other stuffs around the psABI repo first)

@kito-cheng
Copy link
Collaborator Author

Not really spec related, but kinda bookmark for myself:

clang implementation for Swift name mangling:
CXXNameMangler::[email protected]

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