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

Internal linkage in Picolib breaks libcxx module tests #76980

Closed
mordante opened this issue Jan 4, 2024 · 9 comments
Closed

Internal linkage in Picolib breaks libcxx module tests #76980

mordante opened this issue Jan 4, 2024 · 9 comments
Assignees
Labels
clang:modules C++20 modules and Clang Header Modules libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@mordante
Copy link
Member

mordante commented Jan 4, 2024

At least since C11 "Any declaration of a library function shall have external linkage." This is important for C++20 modules. Named declarations with internal linkage can't be exported, which prevents using these declarations in the C++23 std and std.compat module.

Several declarations in Picolib have internal linkage, for example static __inline int isblank(int c). See https://buildkite.com/llvm-project/libcxx-ci/builds/32428#018c9247-50ba-4728-b13d-fb064eba3707 for more issues. This prevents using this library in the C++ modules

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 4, 2024

@llvm/issue-subscribers-clang-modules

Author: Mark de Wever (mordante)

At least since [C11](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf#%5B%7B%22num%22%3A429%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C-27%2C816%2Cnull%5D) "Any declaration of a library function shall have external linkage." This is important for C++20 modules. Named declarations with internal linkage can't be exported, which prevents using these declarations in the C++23 `std` and `std.compat` module.

Several declarations in Picolib have internal linkage, for example static __inline int isblank(int c). See https://buildkite.com/llvm-project/libcxx-ci/builds/32428#018c9247-50ba-4728-b13d-fb064eba3707 for more issues. This prevents using this library in the C++ modules

@DavidSpickett
Copy link
Collaborator

To reproduce, check out the branch https://github.com/llvm/llvm-project/tree/users/mordante/adds_module_testing and remove the PicoLib xfail:

diff --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py
index 1939d553d72d..9a676f98d104 100644
--- a/libcxx/utils/libcxx/test/features.py
+++ b/libcxx/utils/libcxx/test/features.py
@@ -324,7 +324,7 @@ DEFAULT_FEATURES = [
         # This is not allowed per C11 7.1.2 Standard headers/6
         #  Any declaration of a library function shall have external linkage.
         when=lambda cfg: "__ANDROID__" in compilerMacros(cfg)
-        or "__PICOLIBC__" in compilerMacros(cfg)
+#        or "__PICOLIBC__" in compilerMacros(cfg)
         or platform.system().lower().startswith("aix")
         # Avoid building on platforms that don't support modules properly.
         or not hasCompileFlag(cfg, "-Wno-reserved-module-identifier"),

Then make sure you have clang 16.x or higher, and qemu-system-arm 8.1.3 or greater.

~/modules-llvm-project$ ./libcxx/utils/ci/run-buildbot armv7m-picolibc
********************
Failed Tests (5):
  armv7m-picolibc-libc++.cfg.in :: libcxx/selftest/modules/std-and-std.compat-module.sh.cpp
  armv7m-picolibc-libc++.cfg.in :: libcxx/selftest/modules/std-module.sh.cpp
  armv7m-picolibc-libc++.cfg.in :: libcxx/selftest/modules/std.compat-module.sh.cpp
  armv7m-picolibc-libc++.cfg.in :: std/modules/std.compat.pass.cpp
  armv7m-picolibc-libc++.cfg.in :: std/modules/std.pass.cpp

The builder downloads the picolib release each time, might have to hack in a local path for that as you make changes. The version in use now is 1.8.5.

@DavidSpickett
Copy link
Collaborator

I've brought this to the attention of the team at Arm handling this area.

@DavidSpickett DavidSpickett changed the title Internal linkage in Picolib Internal linkage in Picolib breaks libcxx module tests Jan 5, 2024
@DavidSpickett DavidSpickett added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 5, 2024
@mordante
Copy link
Member Author

mordante commented Jan 5, 2024

I've brought this to the attention of the team at Arm handling this area.

Thanks! Note that this issue is not just needed for libc++, it's required for conformance with the C standard too.

domin144 added a commit to domin144/picolibc that referenced this issue Jan 11, 2024
External linkage is required by C11. Not conforming to this results in
issues in implementation of C++ modules. [1]

llvm/llvm-project#76980
domin144 added a commit to domin144/picolibc that referenced this issue Jan 11, 2024
External linkage is required by C11. Not conforming to this results in
issues in implementation of C++ modules. [1]

llvm/llvm-project#76980
@domin144
Copy link
Contributor

I am trying to sort out the isblank issue in upstream.

There are other errors related to std::get_deleter. I think these are caused by disabled RTTI in one of the picolibc variants.

@keith-packard
Copy link

keith-packard commented Jan 11, 2024

Where available, picolibc uses the gnu_inline attribute to make this work while still providing inline acceleration of these operations.

Example:

file-1.c:

#include <stdlib.h>
#include <stdio.h>

extern int foo(int y);

extern __inline int __attribute((gnu_inline, always_inline)) foo(int y)
{
	return y + 1;
}

int main(int argc, char **argv)
{
	printf("%d\n", foo(atoi(argv[1])));
	return 0;
}

file-2.c:

extern int foo(int y);

extern __inline int __attribute((gnu_inline, always_inline)) foo(int y)
{
	return y + 1;
}

int
foo(int y)
{
	return y + 2;
}

Note that the inline and extern versions generate different results (which is "wrong", but useful for testing).

$ cc file-1.c file-2.c
$ nm a.out | grep foo
0000000000001191 T foo
$ ./a.out 10
11
$

As you can see, foo is a real function, but when invoked, the application uses the inline version.

@mordante
Copy link
Member Author

I am trying to sort out the isblank issue in upstream.

Great to hear.

There are other errors related to std::get_deleter. I think these are caused by disabled RTTI in one of the picolibc variants.

I noticed that too, I just added a fix here f8bf61f

@keith-packard is this the current situation or the proposed change? In the example static __inline int isblank(int c) uses
static not extern __inline int __attribute((gnu_inline, always_inline)) isblank(int c).

@keith-packard
Copy link

@keith-packard is this the current situation or the proposed change? In the example static __inline int isblank(int c) uses static not extern __inline int __attribute((gnu_inline, always_inline)) isblank(int c).

isblank is an exception, and this represents a bug. I'm working on fixing this, but there's a bigger mess in the fenv support that needs clearing out as well. The current status of picolibc/picolibc#668 shows the proposed fix for isblank stack on top of a general cleanup of the use of gnu_inline. I'll merge that in and then continue the fenv cleanup on top.

domin144 added a commit to domin144/llvm-project that referenced this issue Jan 12, 2024
The updated picolibc version has "isblank" function with external
linkage. This is required for C++ modules support.[1]

[1] llvm#76980
ldionne pushed a commit that referenced this issue Jan 12, 2024
The updated picolibc version has "isblank" function with external
linkage. This is required for C++ modules support.

This should solve all the problems reported in #76980, but
we'll wait to validate this with the modules build without
closing that issue.
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this issue Jan 28, 2024
The updated picolibc version has "isblank" function with external
linkage. This is required for C++ modules support.

This should solve all the problems reported in llvm#76980, but
we'll wait to validate this with the modules build without
closing that issue.
@mordante
Copy link
Member Author

With the picolib updates this issue is resolved and modules are now tested with Picolib in the CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

6 participants