-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Release overlay GCC build fails with "aliased to external symbol" #60481
Comments
@llvm/issue-subscribers-libc |
Just been looking at this myself, this only happens for overlay mode. It's the overlaying mechanism that leads to this error I think. Reading the gcc docs: "It is an error if `__f' is not defined in the same translation unit." clang does not document it so I don't know if clang allows this on purpose or not. I also found https://stackoverflow.com/questions/7649979/gcc-alias-to-function-outside-of-translation-unit-aka-is-this-even-the-right-t asking about this with another project. No obvious solution from C, but some ideas with linker scripts and such. I should note that the libc project only officially supports clang at this time. The gcc buildbots they have build the full mode so they won't have hit this. |
Interestingly, this seems to happen only for release mode builds with |
Ah, looks like |
I also started to get the same error for
It builds fine in Debug mode. |
Suggested re-title: "Standard library re-aliasing issues in overlay mode builds only in the release configuration" |
Looks like gcc will error for aliases created with the alias attributes, but not asm aliases. |
Simpler reproducer:
|
When building overlay mode with GCC in release mode, glibc's stdlib.h contains an extern inline declaration of bsearch. This breaks our use of the gnu::alias function attribute in LLVM_LIBC_FUNCTION with GCC because GCC checks that the aliasee is defined in the same TU (clang does not). We're looking at also potentially updating our definition of LLVM_LIBC_FUNCTION from libc/src/__support/common.h. Upon testing, I was able to get -Wnonnull-compare diagnostics from GCC in our definition of bsearch because glibc declares bsearch with the fugly nonnull function attribute. There's more we can do here though to improve our implementation of bsearch. 7.24.5.1 says: Pointer arguments on such a call shall still have valid values, as described in 7.1.4. We could also use either function attributes or parameter attributes to denote these should not be null (for users/callers) and perhaps still check for non-null explicitly under some yet to be discussed hardening configurations in the future. Fixes: llvm#60481 Link: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-nonnull-function-attribute
So clang can diagnose this, but seemingly only at I have a fix for the immediate issue of bsearch, but it won't close out this issue because we hit similar but slightly trickier to fix cases for 3 other functions (wctob, vprintf, and atof). |
When building overlay mode with GCC in release mode, glibc's stdlib.h contains an extern inline declaration of bsearch. This breaks our use of the gnu::alias function attribute in LLVM_LIBC_FUNCTION with GCC because GCC checks that the aliasee is defined in the same TU (clang does not). We're looking at also potentially updating our definition of LLVM_LIBC_FUNCTION from libc/src/__support/common.h. Upon testing, I was able to get -Wnonnull-compare diagnostics from GCC in our definition of bsearch because glibc declares bsearch with the fugly nonnull function attribute. There's more we can do here though to improve our implementation of bsearch. 7.24.5.1 says: Pointer arguments on such a call shall still have valid values, as described in 7.1.4. We could also use either function attributes or parameter attributes to denote these should not be null (for users/callers) and perhaps still check for non-null explicitly under some yet to be discussed hardening configurations in the future. Link: #60481 Link: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-nonnull-function-attribute
Turns out the problems are from extra A solution for this issue is:
|
Also protect against extern inline function definitions added when building with gcc: #60481.
I've ran into this same problem recently with a couple different files:
|
CMake invocation: (C/C++ compilers set to GCC/G++)
The text was updated successfully, but these errors were encountered: