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

[FMV] mangling of forward-declared multi-versioned callee differs between gcc and clang #81043

Closed
jroelofs opened this issue Feb 7, 2024 · 4 comments · Fixed by #81194
Closed
Assignees

Comments

@jroelofs
Copy link
Contributor

jroelofs commented Feb 7, 2024

https://clang.godbolt.org/z/zeeTxd3va

__attribute__((target_version("fp16")))
void foo(void);

__attribute__((target_version("fp16fml")))
void foo(void);

__attribute__((target_version("default")))
void foo(void);

void caller() {
    foo();
}

Note how clang calls it _Z3foov.ifunc, and gcc refers to it as _Z3foov. IMO gcc's behavior is the desirable one: it lets you forward-declare foo in a header without having to promise that the implementation is multi-versioned. This is useful for libraries that have to provide a stable ABI to be able to adopt FMV in the implementation of those interfaces, without having to write an excessive number of shims.

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Feb 7, 2024
@jroelofs
Copy link
Contributor Author

jroelofs commented Feb 7, 2024

@EugeneZelenko EugeneZelenko added clang:codegen and removed clang Clang issues not falling into any other category labels Feb 7, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 7, 2024

@llvm/issue-subscribers-clang-codegen

Author: Jon Roelofs (jroelofs)

https://clang.godbolt.org/z/zeeTxd3va
__attribute__((target_version("fp16")))
void foo(void);

__attribute__((target_version("fp16fml")))
void foo(void);

__attribute__((target_version("default")))
void foo(void);

void caller() {
    foo();
}

Note how clang calls it _Z3foov.ifunc, and gcc refers to it as _Z3foov. IMO gcc's behavior is the desirable one: it lets you forward-declare foo in a header without having to promise that the implementation is multi-versioned. This is useful for libraries that have to provide a stable ABI to be able to adopt FMV in the implementation of those interfaces, without having to write an excessive number of shims.

@jroelofs
Copy link
Contributor Author

jroelofs commented Feb 7, 2024

Note that gcc/clang match for target_clones: https://clang.godbolt.org/z/4cKoxcjGT

@jroelofs
Copy link
Contributor Author

jroelofs commented Feb 7, 2024

I think it's because of this:

// Holds the name of the resolver, in ifunc mode this is the ifunc (which has
// a separate resolver).
std::string ResolverName = MangledName;
if (getTarget().supportsIFunc()) {
if (!FD->isTargetClonesMultiVersion())
ResolverName += ".ifunc";
} else if (FD->isTargetMultiVersion()) {
ResolverName += ".resolver";
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants