Skip to contentSkip to conversation

tools/bpf: properly account for libbfd variations

PATCH Superseded Stanislav Fomichev 4 participants 9 messages Jan 15, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/bpf: properly account for libbfd variations

On some platforms, in order to link against libbfd, we need to link against liberty and even possibly libz. Account for that in the bpftool Makefile. We now have proper feature detection for each case, so handle each one separately.

See recent commit 14541b1e7e72 ("perf build: Don't unconditionally link the libbfd feature test to -liberty and -lz") where I fixed feature detection.

Fixes 29a9c10e4110 ("bpftool: make libbfd optional")
---
 tools/bpf/bpftool/Makefile | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
tools/bpf/bpftool/Makefile +13 -2
index 492f0f24e2d3..af9a25bf480d 100644
@@ -92,10 +92,21 @@ BFD_SRCS = jit_disasm.c
 
 SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
 
-ifeq ($(feature-libbfd),1)
+ifeq ($(feature-libbfd), 1)
+LIBS += -lbfd -ldl -lopcodes
+else
+  ifeq ($(feature-libbfd-liberty), 1)
+    LIBS += -lbfd -ldl -lopcodes -liberty
+  else
+    ifeq ($(feature-libbfd-liberty-z), 1)
+      LIBS += -lbfd -ldl -lopcodes -liberty -lz
+    endif
+  endif
+endif
+
+ifneq ($(filter -lbfd,$(EXTLIBS)),)
 CFLAGS += -DHAVE_LIBBFD_SUPPORT
 SRCS += $(BFD_SRCS)
-LIBS += -lbfd -lopcodes
 endif
 
 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
Signature · 1 line
2.20.1.97.g81188d93c3-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Stanislav Fomichev

On some platforms, in order to link against libbfd, we need to link against liberty and even possibly libz. Account for that in the bpftool Makefile. We now have proper feature detection for each case, so handle each one separately.

See recent commit 14541b1e7e72 ("perf build: Don't unconditionally link the libbfd feature test to -liberty and -lz") where I fixed feature detection.

Fixes 29a9c10e4110 ("bpftool: make libbfd optional")

Minor nits below, in any case:

Thanks for making bpftool build! :)

tools/bpf/bpftool/Makefile BFD_SRCS = jit_disasm.c · line 95

Quoted 10 lines
tools/bpf/bpftool/Makefile +1 -1
index 492f0f24e2d3..af9a25bf480d 100644
@@ -92,10 +92,21 @@ BFD_SRCS = jit_disasm.c
 
 SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
 
-ifeq ($(feature-libbfd),1)
+ifeq ($(feature-libbfd), 1)

nit: no space there is more common

$ git grep 'ifeq' | grep ',[^ ]' | wc -l
482
$ git grep 'ifeq' | grep ', ' | wc -l
136

tools/bpf/bpftool/Makefile BFD_SRCS = jit_disasm.c · line 96

Quoted 1 line
tools/bpf/bpftool/Makefile +1 -0
+LIBS += -lbfd -ldl -lopcodes

nit: should this be indented?

tools/bpf/bpftool/Makefile BFD_SRCS = jit_disasm.c · line 103

Quoted 7 lines
tools/bpf/bpftool/Makefile +7 -0
+else
+  ifeq ($(feature-libbfd-liberty), 1)
+    LIBS += -lbfd -ldl -lopcodes -liberty
+  else
+    ifeq ($(feature-libbfd-liberty-z), 1)
+      LIBS += -lbfd -ldl -lopcodes -liberty -lz
+    endif

Would this syntax:

ifeq ($(feature-libbfd),1)
LIBS += ..
else ifeq ($(feature-libbfd-liberty),1)
LIBS += ..
else ifeq ($(feature-libbfd-liberty-z),1)
LIBS += ..
endif

Not work?

https://www.gnu.org/software/make/manual/html_node/Conditional-Syntax.html

I don't think I've ever tried, but looks more concise..

Quoted 10 lines
tools/bpf/bpftool/Makefile +4 -1
+  endif
+endif
+
+ifneq ($(filter -lbfd,$(EXTLIBS)),)
 CFLAGS += -DHAVE_LIBBFD_SUPPORT
 SRCS += $(BFD_SRCS)
-LIBS += -lbfd -lopcodes
 endif
 
 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
#2 lore raw
Quoted 60 lines · Jakub Kicinski
Quoted 11 lines · Stanislav Fomichev

On some platforms, in order to link against libbfd, we need to link against liberty and even possibly libz. Account for that in the bpftool Makefile. We now have proper feature detection for each case, so handle each one separately.

See recent commit 14541b1e7e72 ("perf build: Don't unconditionally link the libbfd feature test to -liberty and -lz") where I fixed feature detection.

Fixes 29a9c10e4110 ("bpftool: make libbfd optional")

Minor nits below, in any case:

Thanks for making bpftool build! :)

tools/bpf/bpftool/Makefile BFD_SRCS = jit_disasm.c · line 95

Quoted 10 lines
tools/bpf/bpftool/Makefile +1 -1
index 492f0f24e2d3..af9a25bf480d 100644
@@ -92,10 +92,21 @@ BFD_SRCS = jit_disasm.c
 
 SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
 
-ifeq ($(feature-libbfd),1)
+ifeq ($(feature-libbfd), 1)

nit: no space there is more common

$ git grep 'ifeq' | grep ',[^ ]' | wc -l
482
$ git grep 'ifeq' | grep ', ' | wc -l
136

tools/bpf/bpftool/Makefile BFD_SRCS = jit_disasm.c · line 96

Quoted 1 line
tools/bpf/bpftool/Makefile +1 -0
+LIBS += -lbfd -ldl -lopcodes

nit: should this be indented?

tools/bpf/bpftool/Makefile BFD_SRCS = jit_disasm.c · line 103

Quoted 7 lines
tools/bpf/bpftool/Makefile +7 -0
+else
+  ifeq ($(feature-libbfd-liberty), 1)
+    LIBS += -lbfd -ldl -lopcodes -liberty
+  else
+    ifeq ($(feature-libbfd-liberty-z), 1)
+      LIBS += -lbfd -ldl -lopcodes -liberty -lz
+    endif

Would this syntax:

ifeq ($(feature-libbfd),1)
LIBS += ..
else ifeq ($(feature-libbfd-liberty),1)
LIBS += ..
else ifeq ($(feature-libbfd-liberty-z),1)
LIBS += ..
endif

Quoted 1 line

Not work?

I does seem to work :-) This is the first time I see it being written that way. (but your link indeed shows that this syntax is supported)

I'll post v2 shortly with all the nits addressed. Thanks for a quick review!

Quoted 16 lines

https://www.gnu.org/software/make/manual/html_node/Conditional-Syntax.html

I don't think I've ever tried, but looks more concise..

Quoted 10 lines
tools/bpf/bpftool/Makefile +4 -1
+  endif
+endif
+
+ifneq ($(filter -lbfd,$(EXTLIBS)),)
 CFLAGS += -DHAVE_LIBBFD_SUPPORT
 SRCS += $(BFD_SRCS)
-LIBS += -lbfd -lopcodes
 endif
 
 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
#3 lore raw

PATCH v2 1/1 tools/bpf: properly account for libbfd variations

In reply to Jakub Kicinski

On some platforms, in order to link against libbfd, we need to link against liberty and even possibly libz. Account for that in the bpftool Makefile. We now have proper feature detection for each case, so handle each one separately.

See recent commit 14541b1e7e72 ("perf build: Don't unconditionally link the libbfd feature test to -liberty and -lz") where I fixed feature detection.

v2 (addressed Jakub's nits):
* better syntax for 'else ifeq'
* no space between ifeq args

Fixes 29a9c10e4110 ("bpftool: make libbfd optional")
---
 tools/bpf/bpftool/Makefile | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/bpf/bpftool/Makefile +8 -1
index 492f0f24e2d3..fbf7e62a5b86 100644
@@ -93,9 +93,16 @@ BFD_SRCS = jit_disasm.c
 SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
 
 ifeq ($(feature-libbfd),1)
+  LIBS += -lbfd -ldl -lopcodes
+else ifeq ($(feature-libbfd-liberty),1)
+  LIBS += -lbfd -ldl -lopcodes -liberty
+else ifeq ($(feature-libbfd-liberty-z),1)
+  LIBS += -lbfd -ldl -lopcodes -liberty -lz
+endif
+
+ifneq ($(filter -lbfd,$(EXTLIBS)),)
 CFLAGS += -DHAVE_LIBBFD_SUPPORT
 SRCS += $(BFD_SRCS)
-LIBS += -lbfd -lopcodes
 endif
 
 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
Signature · 1 line
2.20.1.97.g81188d93c3-goog
#4 lore raw
Quoted 25 lines · Stanislav Fomichev

On some platforms, in order to link against libbfd, we need to link against liberty and even possibly libz. Account for that in the bpftool Makefile. We now have proper feature detection for each case, so handle each one separately.

See recent commit 14541b1e7e72 ("perf build: Don't unconditionally link the libbfd feature test to -liberty and -lz") where I fixed feature detection.

v2 (addressed Jakub's nits):
* better syntax for 'else ifeq'
* no space between ifeq args

Fixes 29a9c10e4110 ("bpftool: make libbfd optional")
---
 tools/bpf/bpftool/Makefile | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/bpf/bpftool/Makefile +0 -0
index 492f0f24e2d3..fbf7e62a5b86 100644
@@ -93,9 +93,16 @@ BFD_SRCS = jit_disasm.c
 SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))

tools/bpf/bpftool/Makefile BFD_SRCS = jit_disasm.c · line 103

Quoted 10 lines
tools/bpf/bpftool/Makefile +8 -0
 
 ifeq ($(feature-libbfd),1)
+  LIBS += -lbfd -ldl -lopcodes
+else ifeq ($(feature-libbfd-liberty),1)
+  LIBS += -lbfd -ldl -lopcodes -liberty
+else ifeq ($(feature-libbfd-liberty-z),1)
+  LIBS += -lbfd -ldl -lopcodes -liberty -lz
+endif
+
+ifneq ($(filter -lbfd,$(EXTLIBS)),)

Ah, I just noticed now that you use EXTLIBS here, not LIBS, is that on purpose?

Quoted 6 lines
tools/bpf/bpftool/Makefile +0 -1
 CFLAGS += -DHAVE_LIBBFD_SUPPORT
 SRCS += $(BFD_SRCS)
-LIBS += -lbfd -lopcodes
 endif
 
 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
#5 lore raw
Quoted 27 lines · Jakub Kicinski
Quoted 26 lines · Stanislav Fomichev

On some platforms, in order to link against libbfd, we need to link against liberty and even possibly libz. Account for that in the bpftool Makefile. We now have proper feature detection for each case, so handle each one separately.

See recent commit 14541b1e7e72 ("perf build: Don't unconditionally link the libbfd feature test to -liberty and -lz") where I fixed feature detection.

v2 (addressed Jakub's nits):
* better syntax for 'else ifeq'
* no space between ifeq args

Fixes 29a9c10e4110 ("bpftool: make libbfd optional")
---
 tools/bpf/bpftool/Makefile | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/bpf/bpftool/Makefile +0 -0
index 492f0f24e2d3..fbf7e62a5b86 100644
@@ -93,9 +93,16 @@ BFD_SRCS = jit_disasm.c
 SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
 
Quoted 12 lines

tools/bpf/bpftool/Makefile BFD_SRCS = jit_disasm.c · line 103

Quoted 9 lines
tools/bpf/bpftool/Makefile +8 -0
 ifeq ($(feature-libbfd),1)
+  LIBS += -lbfd -ldl -lopcodes
+else ifeq ($(feature-libbfd-liberty),1)
+  LIBS += -lbfd -ldl -lopcodes -liberty
+else ifeq ($(feature-libbfd-liberty-z),1)
+  LIBS += -lbfd -ldl -lopcodes -liberty -lz
+endif
+
+ifneq ($(filter -lbfd,$(EXTLIBS)),)

Ah, I just noticed now that you use EXTLIBS here, not LIBS, is that on purpose?

Nice catch! Should be LIBS, probably copy-pasted it from somewhere :-(

Quoted 8 lines
Quoted 7 lines
tools/bpf/bpftool/Makefile +0 -1
 CFLAGS += -DHAVE_LIBBFD_SUPPORT
 SRCS += $(BFD_SRCS)
-LIBS += -lbfd -lopcodes
 endif
 
 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
#6 lore raw

PATCH v3 1/1 tools/bpf: properly account for libbfd variations

In reply to Jakub Kicinski

On some platforms, in order to link against libbfd, we need to link against liberty and even possibly libz. Account for that in the bpftool Makefile. We now have proper feature detection for each case, so handle each one separately.

See recent commit 14541b1e7e72 ("perf build: Don't unconditionally link the libbfd feature test to -liberty and -lz") where I fixed feature detection.

v2 (addressed Jakub's nits):
* better syntax for 'else ifeq'
* no space between ifeq args
v3:
* use LIBS, not EXTLIBS for -DHAVE_LIBBFD_SUPPORT

Fixes 29a9c10e4110 ("bpftool: make libbfd optional")
---
 tools/bpf/bpftool/Makefile | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/bpf/bpftool/Makefile +8 -1
index 492f0f24e2d3..4ad1f0894d53 100644
@@ -93,9 +93,16 @@ BFD_SRCS = jit_disasm.c
 SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
 
 ifeq ($(feature-libbfd),1)
+  LIBS += -lbfd -ldl -lopcodes
+else ifeq ($(feature-libbfd-liberty),1)
+  LIBS += -lbfd -ldl -lopcodes -liberty
+else ifeq ($(feature-libbfd-liberty-z),1)
+  LIBS += -lbfd -ldl -lopcodes -liberty -lz
+endif
+
+ifneq ($(filter -lbfd,$(LIBS)),)
 CFLAGS += -DHAVE_LIBBFD_SUPPORT
 SRCS += $(BFD_SRCS)
-LIBS += -lbfd -lopcodes
 endif
 
 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
Signature · 1 line
2.20.1.97.g81188d93c3-goog
Acked-by on v3 1/1
#7 lore raw
Quoted 9 lines · Stanislav Fomichev

On some platforms, in order to link against libbfd, we need to link against liberty and even possibly libz. Account for that in the bpftool Makefile. We now have proper feature detection for each case, so handle each one separately.

See recent commit 14541b1e7e72 ("perf build: Don't unconditionally link the libbfd feature test to -liberty and -lz") where I fixed feature detection.

Quoted 8 lines

v2 (addressed Jakub's nits):
* better syntax for 'else ifeq'
* no space between ifeq args
v3:
* use LIBS, not EXTLIBS for -DHAVE_LIBBFD_SUPPORT

Fixes 29a9c10e4110 ("bpftool: make libbfd optional")

Thanks!!

maintainer Applied
#8 lore raw
In reply to Stanislav Fomichev
Quoted 9 lines · Stanislav Fomichev

On some platforms, in order to link against libbfd, we need to link against liberty and even possibly libz. Account for that in the bpftool Makefile. We now have proper feature detection for each case, so handle each one separately.

See recent commit 14541b1e7e72 ("perf build: Don't unconditionally link the libbfd feature test to -liberty and -lz") where I fixed feature detection.

Quoted 8 lines

v2 (addressed Jakub's nits):
* better syntax for 'else ifeq'
* no space between ifeq args
v3:
* use LIBS, not EXTLIBS for -DHAVE_LIBBFD_SUPPORT

Fixes 29a9c10e4110 ("bpftool: make libbfd optional")

Applied, thanks!