Skip to content

Commit 3e83936

Browse files
0x7f454c46shuahkh
authored andcommitted
selftests: use LDLIBS for libraries instead of LDFLAGS
While building selftests, the following errors were observed: > tools/testing/selftests/timens' > gcc -Wall -Werror -pthread -lrt -ldl timens.c -o tools/testing/selftests/timens/timens > /usr/bin/ld: /tmp/ccGy5CST.o: in function `check_config_posix_timers': > timens.c:(.text+0x65a): undefined reference to `timer_create' > collect2: error: ld returned 1 exit status Quoting commit 870f193 ("selftests: net: use LDLIBS instead of LDFLAGS"): The default Makefile rule looks like: $(CC) $(CFLAGS) $(LDFLAGS) $@ $^ $(LDLIBS) When linking is done by gcc itself, no issue, but when it needs to be passed to proper ld, only LDLIBS follows and then ld cannot know what libs to link with. More detail: https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html LDFLAGS Extra flags to give to compilers when they are supposed to invoke the linker, ‘ld’, such as -L. Libraries (-lfoo) should be added to the LDLIBS variable instead. LDLIBS Library flags or names given to compilers when they are supposed to invoke the linker, ‘ld’. LOADLIBES is a deprecated (but still supported) alternative to LDLIBS. Non-library linker flags, such as -L, should go in the LDFLAGS variable. While at here, correct other selftests, not only timens ones. Reported-by: Shuah Khan <[email protected]> Signed-off-by: Dmitry Safonov <[email protected]> Tested-by: Shuah Khan <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent c363eb4 commit 3e83936

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

tools/testing/selftests/futex/functional/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22
INCLUDES := -I../include -I../../
33
CFLAGS := $(CFLAGS) -g -O2 -Wall -D_GNU_SOURCE -pthread $(INCLUDES)
4-
LDFLAGS := $(LDFLAGS) -pthread -lrt
4+
LDLIBS := -lpthread -lrt
55

66
HEADERS := \
77
../include/futextest.h \

tools/testing/selftests/net/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ KSFT_KHDR_INSTALL := 1
2727
include ../lib.mk
2828

2929
$(OUTPUT)/reuseport_bpf_numa: LDLIBS += -lnuma
30-
$(OUTPUT)/tcp_mmap: LDFLAGS += -lpthread
31-
$(OUTPUT)/tcp_inq: LDFLAGS += -lpthread
30+
$(OUTPUT)/tcp_mmap: LDLIBS += -lpthread
31+
$(OUTPUT)/tcp_inq: LDLIBS += -lpthread

tools/testing/selftests/rtc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22
CFLAGS += -O3 -Wl,-no-as-needed -Wall
3-
LDFLAGS += -lrt -lpthread -lm
3+
LDLIBS += -lrt -lpthread -lm
44

55
TEST_GEN_PROGS = rtctest
66

tools/testing/selftests/timens/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ TEST_GEN_PROGS := timens timerfd timer clock_nanosleep procfs exec
22
TEST_GEN_PROGS_EXTENDED := gettime_perf
33

44
CFLAGS := -Wall -Werror -pthread
5-
LDFLAGS := -lrt -ldl
5+
LDLIBS := -lrt -ldl
66

77
include ../lib.mk

0 commit comments

Comments
 (0)