File tree Expand file tree Collapse file tree
tools/testing/selftests/nolibc Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -171,17 +171,17 @@ sysroot/$(ARCH)/include:
171171 $(Q ) mv sysroot/sysroot sysroot/$(ARCH )
172172
173173ifneq ($(NOLIBC_SYSROOT ) ,0)
174- nolibc-test : nolibc-test.c sysroot/$(ARCH ) /include
174+ nolibc-test : nolibc-test.c nolibc-test-linkage.c sysroot/$(ARCH ) /include
175175 $(QUIET_CC )$(CC ) $(CFLAGS ) $(LDFLAGS ) -o $@ \
176- -nostdlib -nostdinc -static -Isysroot/$(ARCH ) /include $< -lgcc
176+ -nostdlib -nostdinc -static -Isysroot/$(ARCH ) /include nolibc-test.c nolibc-test-linkage.c -lgcc
177177else
178- nolibc-test : nolibc-test.c
178+ nolibc-test : nolibc-test.c nolibc-test-linkage.c
179179 $(QUIET_CC )$(CC ) $(CFLAGS ) $(LDFLAGS ) -o $@ \
180- -nostdlib -static -include ../../../include/nolibc/nolibc.h $< -lgcc
180+ -nostdlib -static -include ../../../include/nolibc/nolibc.h nolibc-test.c nolibc-test-linkage.c -lgcc
181181endif
182182
183- libc-test : nolibc-test.c
184- $(QUIET_CC )$(HOSTCC ) -o $@ $<
183+ libc-test : nolibc-test.c nolibc-test-linkage.c
184+ $(QUIET_CC )$(HOSTCC ) -o $@ nolibc-test.c nolibc-test-linkage.c
185185
186186# local libc-test
187187run-libc-test : libc-test
Original file line number Diff line number Diff line change 1+ /* SPDX-License-Identifier: GPL-2.0 */
2+
3+ #include "nolibc-test-linkage.h"
4+
5+ #ifndef NOLIBC
6+ #include <errno.h>
7+ #endif
8+
9+ void * linkage_test_errno_addr (void )
10+ {
11+ return & errno ;
12+ }
13+
14+ int linkage_test_constructor_test_value ;
15+
16+ __attribute__((constructor ))
17+ static void constructor1 (void )
18+ {
19+ linkage_test_constructor_test_value = 2 ;
20+ }
21+
22+ __attribute__((constructor ))
23+ static void constructor2 (void )
24+ {
25+ linkage_test_constructor_test_value *= 3 ;
26+ }
Original file line number Diff line number Diff line change 1+ /* SPDX-License-Identifier: GPL-2.0 */
2+
3+ #ifndef _NOLIBC_TEST_LINKAGE_H
4+ #define _NOLIBC_TEST_LINKAGE_H
5+
6+ void * linkage_test_errno_addr (void );
7+ extern int linkage_test_constructor_test_value ;
8+
9+ #endif /* _NOLIBC_TEST_LINKAGE_H */
Original file line number Diff line number Diff line change 4141#endif
4242#endif
4343
44+ #include "nolibc-test-linkage.h"
45+
4446/* for the type of int_fast16_t and int_fast32_t, musl differs from glibc and nolibc */
4547#define SINT_MAX_OF_TYPE (type ) (((type)1 << (sizeof(type) * 8 - 2)) - (type)1 + ((type)1 << (sizeof(type) * 8 - 2)))
4648#define SINT_MIN_OF_TYPE (type ) (-SINT_MAX_OF_TYPE(type) - 1)
@@ -647,6 +649,8 @@ int run_startup(int min, int max)
647649 CASE_TEST (auxv_addr ); EXPECT_PTRGT (test_auxv != (void * )-1 , test_auxv , brk ); break ;
648650 CASE_TEST (auxv_AT_UID ); EXPECT_EQ (1 , getauxval (AT_UID ), getuid ()); break ;
649651 CASE_TEST (constructor ); EXPECT_EQ (1 , constructor_test_value , 2 ); break ;
652+ CASE_TEST (linkage_errno ); EXPECT_PTREQ (1 , linkage_test_errno_addr (), & errno ); break ;
653+ CASE_TEST (linkage_constr ); EXPECT_EQ (1 , linkage_test_constructor_test_value , 6 ); break ;
650654 case __LINE__ :
651655 return ret ; /* must be last */
652656 /* note: do not set any defaults so as to permit holes above */
You can’t perform that action at this time.
0 commit comments