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
"ifunc must point to a defined function" error for static IFUNC resolver functions in C++ mode #54549
Comments
@llvm/issue-subscribers-clang-frontend |
I was able to repro this with:
|
@erichkeane Please note that your reduced example doesn't build with gcc either, as the parameter of the This is why I added |
Ah! Interesting, thank you for the clarification! I note that the 'IR' when you do For anyone who sees this later,
BUT the final IR for
Note that when checking, the 'resolver' is just a function declaration, and not yet the |
I was able to find that the alias for I suspect there is a bit of work that needs to happen to make sure we update for this particular case, but I'm not sure I'm out of time for the day, so if I or others come across this, perhaps this can save some time. Else, if I have time to, I'll take a look again on Monday. |
The patch to fix this was getting complicated, so I ended up having a question on the mailing list: https://discourse.llvm.org/t/why-are-extern-c-static-functions-emitted-with-c-mangling/61268 Depending on the answer to that, I can have my implementation unblocked. |
Review here: https://reviews.llvm.org/D122608 |
@llvm/issue-subscribers-clang-codegen |
We expect that `extern "C"` static functions to be usable in things like inline assembly, as well as ifuncs: See the bug report here: #54549 However, we were diagnosing this as 'not defined', because the ifunc's attempt to look up its resolver would generate a declared IR function. Additionally, as background, the way we allow these static extern "C" functions to work in inline assembly is by making an alias with the C mangling in MOST situations to the version we emit with internal-linkage/mangling. The problem here was multi-fold: First- We generated the alias after the ifunc was checked, so the function by that name didn't exist yet. Second, the ifunc's generation caused a symbol to exist under the name of the alias already (the declared function above), which suppressed the alias generation. This patch fixes all of this by moving the checking of ifuncs/CFE aliases until AFTER we have generated the extern-C alias. Then, it does a 'fixup' around the GlobalIFunc to make sure we correct the reference. Differential Revision: https://reviews.llvm.org/D122608
Fixed! 9ba8c40 |
We expect that `extern "C"` static functions to be usable in things like inline assembly, as well as ifuncs: See the bug report here: llvm/llvm-project#54549 However, we were diagnosing this as 'not defined', because the ifunc's attempt to look up its resolver would generate a declared IR function. Additionally, as background, the way we allow these static extern "C" functions to work in inline assembly is by making an alias with the C mangling in MOST situations to the version we emit with internal-linkage/mangling. The problem here was multi-fold: First- We generated the alias after the ifunc was checked, so the function by that name didn't exist yet. Second, the ifunc's generation caused a symbol to exist under the name of the alias already (the declared function above), which suppressed the alias generation. This patch fixes all of this by moving the checking of ifuncs/CFE aliases until AFTER we have generated the extern-C alias. Then, it does a 'fixup' around the GlobalIFunc to make sure we correct the reference. Differential Revision: https://reviews.llvm.org/D122608
The following code compiles correctly (using both Clang 13.0.1 and trunk) in C mode, but returns an "ifunc must point to a defined function" error when compiled with
clang++
.Removing the
static
storage class specifier makes it compile in C++ mode too.The documentation explicitly states that IFUNC resolver functions may be
static
, so I think this is a bug.The text was updated successfully, but these errors were encountered: