Skip to content

Commit

Permalink
selftests: use LDLIBS for libraries instead of LDFLAGS
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
0x7f454c46 authored and shuahkh committed Feb 13, 2020
1 parent c363eb4 commit 3e83936
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tools/testing/selftests/futex/functional/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
INCLUDES := -I../include -I../../
CFLAGS := $(CFLAGS) -g -O2 -Wall -D_GNU_SOURCE -pthread $(INCLUDES)
LDFLAGS := $(LDFLAGS) -pthread -lrt
LDLIBS := -lpthread -lrt

HEADERS := \
../include/futextest.h \
Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/net/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ KSFT_KHDR_INSTALL := 1
include ../lib.mk

$(OUTPUT)/reuseport_bpf_numa: LDLIBS += -lnuma
$(OUTPUT)/tcp_mmap: LDFLAGS += -lpthread
$(OUTPUT)/tcp_inq: LDFLAGS += -lpthread
$(OUTPUT)/tcp_mmap: LDLIBS += -lpthread
$(OUTPUT)/tcp_inq: LDLIBS += -lpthread
2 changes: 1 addition & 1 deletion tools/testing/selftests/rtc/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
CFLAGS += -O3 -Wl,-no-as-needed -Wall
LDFLAGS += -lrt -lpthread -lm
LDLIBS += -lrt -lpthread -lm

TEST_GEN_PROGS = rtctest

Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/timens/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ TEST_GEN_PROGS := timens timerfd timer clock_nanosleep procfs exec
TEST_GEN_PROGS_EXTENDED := gettime_perf

CFLAGS := -Wall -Werror -pthread
LDFLAGS := -lrt -ldl
LDLIBS := -lrt -ldl

include ../lib.mk

0 comments on commit 3e83936

Please sign in to comment.