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

Link with -lm to fix build on arm/mips/risc/ppc #292

Merged
merged 1 commit into from
Feb 14, 2023

Conversation

bluca
Copy link
Contributor

@bluca bluca commented Feb 12, 2023

xdp_sample uses floor()/ceil() so every executable that imports that module needs to link with -lm. E.g. on armhf:

gcc -Wall -O2 -g -std=gnu11 -Wextra -Werror -DBPF_DIR_MNT=\"/sys/fs/bpf\" -DBPF_OBJECT_PATH=\"/usr/local/lib/bpf\" -DMAX_DISPATCHER_ACTIONS=10 -DTOOLS_VERSION=\""1.3.0"\" -DLIBBPF_VERSION=\"1.1.0\" -DRUNDIR=\"/run\" -DHAVE_LIBBPF_PERF_BUFFER__CONSUME -DHAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID -DHAVE_LIBBPF_BTF__TYPE_CNT -DHAVE_LIBBPF_BPF_OBJECT__NEXT_MAP -DHAVE_LIBBPF_BPF_OBJECT__NEXT_PROGRAM -DHAVE_LIBBPF_BPF_PROGRAM__INSN_CNT -DHAVE_LIBBPF_BPF_MAP_CREATE -DHAVE_LIBBPF_PERF_BUFFER__NEW_RAW -DHAVE_LIBBPF_BPF_XDP_ATTACH -DHAVE_LIBBPF_BPF_MAP__SET_AUTOCREATE -DHAVE_LIBBPF_BPF_PROG_TEST_RUN_OPTS -DHAVE_SECURE_GETENV -DLIBBPF_DYNAMIC -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I../../headers -I../util   -L../libxdp -o test-tool ../util/params.o ../util/logging.o ../util/util.o ../util/stats.o ../util/xpcapng.o ../util/xdp_sample.o \
 test-tool.c  -l:libxdp.a  -lbpf
/usr/bin/ld: ../util/xdp_sample.o: in function `sample_round':
/home/bluca/xdp-tools-1.3.0/lib/util/xdp_sample.c:542: undefined reference to `trunc'
/usr/bin/ld: /home/bluca/xdp-tools-1.3.0/lib/util/xdp_sample.c:544: undefined reference to `ceil'
/usr/bin/ld: /home/bluca/xdp-tools-1.3.0/lib/util/xdp_sample.c:542: undefined reference to `floor'

Signed-off-by: Luca Boccassi bluca@debian.org

@tohojo
Copy link
Member

tohojo commented Feb 12, 2023

Thanks for the fix! Why is it needed for xdp-loader, xdpdump and xdp-filter, though?

@bluca
Copy link
Contributor Author

bluca commented Feb 12, 2023

It's included in those executables too by the makefile, so those builds fail too

@tohojo
Copy link
Member

tohojo commented Feb 12, 2023

So even though no functions from xdp_sample.o is included in the executable, just adding it to the linking step is enough to trigger an error?

In that case I think it's better to just add LDLIBS += -lm in common.mk instead of having to add it to every executable...

@bluca
Copy link
Contributor Author

bluca commented Feb 12, 2023

ok, updated

@tohojo
Copy link
Member

tohojo commented Feb 12, 2023

Could you please remove the now-redundant USER_LIBS from xdp-bench and xdp-monitor as well?

xdp_sample uses floor()/ceil() so every executable that imports that
module needs to link with -lm. E.g. on armhf:

gcc -Wall -O2 -g -std=gnu11 -Wextra -Werror -DBPF_DIR_MNT=\"/sys/fs/bpf\" -DBPF_OBJECT_PATH=\"/usr/local/lib/bpf\" -DMAX_DISPATCHER_ACTIONS=10 -DTOOLS_VERSION=\""1.3.0"\" -DLIBBPF_VERSION=\"1.1.0\" -DRUNDIR=\"/run\" -DHAVE_LIBBPF_PERF_BUFFER__CONSUME -DHAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID -DHAVE_LIBBPF_BTF__TYPE_CNT -DHAVE_LIBBPF_BPF_OBJECT__NEXT_MAP -DHAVE_LIBBPF_BPF_OBJECT__NEXT_PROGRAM -DHAVE_LIBBPF_BPF_PROGRAM__INSN_CNT -DHAVE_LIBBPF_BPF_MAP_CREATE -DHAVE_LIBBPF_PERF_BUFFER__NEW_RAW -DHAVE_LIBBPF_BPF_XDP_ATTACH -DHAVE_LIBBPF_BPF_MAP__SET_AUTOCREATE -DHAVE_LIBBPF_BPF_PROG_TEST_RUN_OPTS -DHAVE_SECURE_GETENV -DLIBBPF_DYNAMIC -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I../../headers -I../util   -L../libxdp -o test-tool ../util/params.o ../util/logging.o ../util/util.o ../util/stats.o ../util/xpcapng.o ../util/xdp_sample.o \
 test-tool.c  -l:libxdp.a  -lbpf
/usr/bin/ld: ../util/xdp_sample.o: in function `sample_round':
/home/bluca/xdp-tools-1.3.0/lib/util/xdp_sample.c:542: undefined reference to `trunc'
/usr/bin/ld: /home/bluca/xdp-tools-1.3.0/lib/util/xdp_sample.c:544: undefined reference to `ceil'
/usr/bin/ld: /home/bluca/xdp-tools-1.3.0/lib/util/xdp_sample.c:542: undefined reference to `floor'

Signed-off-by: Luca Boccassi <bluca@debian.org>
@bluca
Copy link
Contributor Author

bluca commented Feb 12, 2023

done

@tohojo tohojo merged commit 3b4d645 into xdp-project:master Feb 14, 2023
@bluca bluca deleted the libm branch February 14, 2023 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants