Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions riscv-cc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.

variant follow an additional name mangling rule for {Cpp}.
For more details, see <<Name Mangling for Standard Calling Convention Variant>>.

=== ILP32E Calling Convention

IMPORTANT: RV32E is not a ratified base ISA and so we cannot guarantee the
Expand Down
28 changes: 28 additions & 0 deletions riscv-elf.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,34 @@ See the "Type encodings" section in _Itanium {Cpp} ABI_
for more detail on how to mangle types. Note that `__bf16` is mangled in the
same way as `std::bfloat16_t`.

=== 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.

_Itanium {Cpp} ABI_.

.ABI Tag name for calling convention variants
[cols="5,2"]
[width=80%]
|===
| Name | ABI tag name

| Standard vector calling convention variant | riscv_vector_cc
|===


For example:
[,c]
----
__attribute__((riscv_vector_cc)) void foo();
----

is mangled as
[,c]
----
_Z3fooB15riscv_vector_ccv
----

=== Name Mangling for Vector Data Types, Vector Mask Types and Vector Tuple Types.

The vector data types and vector mask types, as defined in the section
Expand Down