Skip to contentSkip to conversation

libbpf: stop using feature-detection Makefiles

PATCH Applied Andrii Nakryiko 4 participants 4 messages Feb 3, 2021 – Feb 4, 2021

Subsystems (4)
lore
Share & tools
lore

Andrii Nakryiko

author maintainer
#0 lore raw

PATCH 1/1 libbpf: stop using feature-detection Makefiles

Libbpf's Makefile relies on Linux tools infrastructure's feature detection framework, but libbpf's needs are very modest: it detects the presence of libelf and libz, both of which are mandatory. So it doesn't benefit much from the framework, but pays significant costs in terms of maintainability and debugging experience, when something goes wrong. The other feature detector, testing for the presernce of minimal BPF API in system headers is long obsolete as well, providing no value.

So stop using feature detection and just assume the presence of libelf and libz during build time. Worst case, user will get a clear and actionable linker error, e.g.:

/usr/bin/ld: cannot find -lelf

On the other hand, we completely bypass recurring issues various users reported over time with false negatives of feature detection (libelf or libz not being detected, while they are actually present in the system).

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Randy Dunlap <[email protected]>
---
 tools/lib/bpf/.gitignore |  1 -
 tools/lib/bpf/Makefile   | 47 ++++------------------------------------
 2 files changed, 4 insertions(+), 44 deletions(-)
tools/lib/bpf/.gitignore +0 -1
index 8a81b3679d2b..5d4cfac671d5 100644
@@ -1,7 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 libbpf_version.h
 libbpf.pc
-FEATURE-DUMP.libbpf
 libbpf.so.*
 TAGS
 tags
tools/lib/bpf/Makefile +4 -43

80 lines not on this page · raw message

Signature · 1 line
2.24.1
Acked-by on v1 1/1
#1 lore raw
Quoted 18 lines · Andrii Nakryiko

Libbpf's Makefile relies on Linux tools infrastructure's feature detection framework, but libbpf's needs are very modest: it detects the presence of libelf and libz, both of which are mandatory. So it doesn't benefit much from the framework, but pays significant costs in terms of maintainability and debugging experience, when something goes wrong. The other feature detector, testing for the presernce of minimal BPF API in system headers is long obsolete as well, providing no value.

So stop using feature detection and just assume the presence of libelf and libz during build time. Worst case, user will get a clear and actionable linker error, e.g.:

/usr/bin/ld: cannot find -lelf

On the other hand, we completely bypass recurring issues various users reported over time with false negatives of feature detection (libelf or libz not being detected, while they are actually present in the system).

Quoted 7 lines
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Randy Dunlap <[email protected]>
---
 tools/lib/bpf/.gitignore |  1 -
 tools/lib/bpf/Makefile   | 47 ++++------------------------------------
 2 files changed, 4 insertions(+), 44 deletions(-)

I've also hit these annoying cases at least once or twice.

Acked-by on v1 1/1
#2 lore raw
In reply to Andrii Nakryiko
Quoted 18 lines · Andrii Nakryiko

Libbpf's Makefile relies on Linux tools infrastructure's feature detection framework, but libbpf's needs are very modest: it detects the presence of libelf and libz, both of which are mandatory. So it doesn't benefit much from the framework, but pays significant costs in terms of maintainability and debugging experience, when something goes wrong. The other feature detector, testing for the presernce of minimal BPF API in system headers is long obsolete as well, providing no value.

So stop using feature detection and just assume the presence of libelf and libz during build time. Worst case, user will get a clear and actionable linker error, e.g.:

/usr/bin/ld: cannot find -lelf

On the other hand, we completely bypass recurring issues various users reported over time with false negatives of feature detection (libelf or libz not being detected, while they are actually present in the system).

Quoted 7 lines
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Randy Dunlap <[email protected]>
---
 tools/lib/bpf/.gitignore |  1 -
 tools/lib/bpf/Makefile   | 47 ++++------------------------------------
 2 files changed, 4 insertions(+), 44 deletions(-)

Hi Andrii,

This does indeed fix the build problems that I was seeing, so I can add:

but in the long term I think that features/libs/etc. that are used should be checked for instead of being used blindly... IMO.

Thanks.

Signature · 1 line
~Randy
#3 lore raw
In reply to Andrii Nakryiko
This patch was applied to bpf/bpf-next.git (refs/heads/master):

Hello:

This patch was applied to bpf/bpf-next.git (refs/heads/master):

Quoted 9 lines · On Wed, 3 Feb 2021 12:34:45 -0800 you wrote:

Libbpf's Makefile relies on Linux tools infrastructure's feature detection framework, but libbpf's needs are very modest: it detects the presence of libelf and libz, both of which are mandatory. So it doesn't benefit much from the framework, but pays significant costs in terms of maintainability and debugging experience, when something goes wrong. The other feature detector, testing for the presernce of minimal BPF API in system headers is long obsolete as well, providing no value.

[...]

Here is the summary with links:
- [bpf-next] libbpf: stop using feature-detection Makefiles

    https://git.kernel.org/bpf/bpf-next/c/5f10c1aac8b2

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html