Re: [PATCH v3 3/3] selftests/nolibc: Add test for getcwd() and readlink()

From: Thomas Weißschuh

Date: Fri Jul 03 2026 - 13:38:17 EST


(+Cc clang/llvm folks, scroll down to test_getcwd())

Hi Daniel,

On 2026-07-02 17:51:01+0900, Daniel Palmer wrote:
> Add a test that uses both getcwd() and readlink() so that both
> are exercised.
>
> First the happy path is tested by fetching what should be the
> same string via getcwd() and readlink() and checking they match.
>
> Then a few different combinations of bad parameters are passed to
> getcwd() to make sure it returns NULL and sets errno in those
> cases.
>
> Signed-off-by: Daniel Palmer <daniel@xxxxxxxxx>

Applied, thanks.

> ---
> tools/testing/selftests/nolibc/nolibc-test.c | 53 ++++++++++++++++++++
> 1 file changed, 53 insertions(+)
>
> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> index c1c1ce43a047..ad3f6e0751be 100644
> --- a/tools/testing/selftests/nolibc/nolibc-test.c
> +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> @@ -854,6 +854,58 @@ static int test_dirent(void)
> return 0;
> }
>
> +static int test_getcwd(void)
> +{

I removed the static from this function.
When it is inlined the tests fail on SPARC on clang.
It seems the system call register is clobbered before the syscall is
invoked. It works fine on GCC.
The fix in [0] makes things a bit better, but not completely.

To reproduce:

* Check out the branch for-next in [1]
* Apply [0]
* cd tools/testing/selftests/nolibc
* ./run-tests.sh -m user -l sparc32
* Only run the problematic testcase: ./nolibc-test syscall:1

(The "sparc64" configuration is also broken,
it looks like the same issue)

This happens for me with clang 22.1.6.

(...)

[0] https://lore.kernel.org/lkml/20260703-nolibc-sparc-asm-v1-1-c7fe73e2e777@xxxxxxxxxxxxxx/
[1] https://git.kernel.org/pub/scm/linux/kernel/git/nolibc/linux-nolibc.git/


Thomas