Skip to contentSkip to conversation

selftests/bpf: Drop the need for LLVM's llc

PATCH Superseded Andrew Delgadillo 3 participants 9 messages Dec 9, 2020 – Dec 11, 2020

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

PATCH 1/1 selftests/bpf: Drop the need for LLVM's llc

LLC is meant for compiler development and debugging. Consequently, it exposes many low level options about its backend. To avoid future bugs introduced by using the raw LLC tool, use clang directly so that all appropriate options are passed to the back end.

Additionally, the native clang build rule was not being use in the selftests Makefile, so remove it.

---
 tools/testing/selftests/bpf/Makefile | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
tools/testing/selftests/bpf/Makefile +4 -16
index 944ae17a39ed..74870d365b62 100644
@@ -19,7 +19,6 @@ ifneq ($(wildcard $(GENHDR)),)
 endif
 
 CLANG		?= clang
-LLC		?= llc
 LLVM_OBJCOPY	?= llvm-objcopy
 BPF_GCC		?= $(shell command -v bpf-gcc;)
 SAN_CFLAGS	?=
@@ -256,24 +255,13 @@ $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h
 # $3 - CFLAGS
 # $4 - LDFLAGS
 define CLANG_BPF_BUILD_RULE
-	$(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm			\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -mattr=dwarfris -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
+	$(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
+	$(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -Xclang -target-feature -Xclang +dwarfris -mcpu=v3 $4
 endef
 # Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
 define CLANG_NOALU32_BPF_BUILD_RULE
-	$(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm			\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -march=bpf -mcpu=v2 $4 -filetype=obj -o $2
-endef
-# Similar to CLANG_BPF_BUILD_RULE, but using native Clang and bpf LLC
-define CLANG_NATIVE_BPF_BUILD_RULE
 	$(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -emit-llvm					\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
+	$(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v2 $4
 endef
 # Build BPF object using GCC
 define GCC_BPF_BUILD_RULE
@@ -402,7 +390,7 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko	\
 		       $(wildcard progs/btf_dump_test_case_*.c)
 TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
-TRUNNER_BPF_LDFLAGS := -mattr=+alu32
+TRUNNER_BPF_LDFLAGS := -Xclang -target-feature -Xclang +alu32
 $(eval $(call DEFINE_TEST_RUNNER,test_progs))
 
 # Define test_progs-no_alu32 test runner.
Signature · 1 line
2.29.2.576.ga3fc446d84-goog
#1 lore raw
Quoted 4 lines · Andrew Delgadillo

LLC is meant for compiler development and debugging. Consequently, it exposes many low level options about its backend. To avoid future bugs introduced by using the raw LLC tool, use clang directly so that all appropriate options are passed to the back end.

Agree that this indeed make build system simpler.

Quoted 3 lines

Additionally, the native clang build rule was not being use in the selftests Makefile, so remove it.

This is true too. Otherwise, native clang build will require both clang and llc runs.

The patch looks good and I have a few comments and hopefully you can accommodate.

Quoted 19 lines
---
  tools/testing/selftests/bpf/Makefile | 20 ++++----------------
  1 file changed, 4 insertions(+), 16 deletions(-)
tools/testing/selftests/bpf/Makefile +0 -1
index 944ae17a39ed..74870d365b62 100644
@@ -19,7 +19,6 @@ ifneq ($(wildcard $(GENHDR)),)
  endif
 
  CLANG		?= clang
-LLC		?= llc
  LLVM_OBJCOPY	?= llvm-objcopy
  BPF_GCC		?= $(shell command -v bpf-gcc;)
  SAN_CFLAGS	?=

tools/testing/selftests/bpf/Makefile $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h · line 259

Quoted 9 lines
tools/testing/selftests/bpf/Makefile +2 -4
@@ -256,24 +255,13 @@ $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h
  # $3 - CFLAGS
  # $4 - LDFLAGS
  define CLANG_BPF_BUILD_RULE
-	$(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm			\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -mattr=dwarfris -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
+	$(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
+	$(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -Xclang -target-feature -Xclang +dwarfris -mcpu=v3 $4

Yes, we still use +dwarfris here.
The original llvm patch which introduded +dwarfris is:

https://github.com/llvm/llvm-project/commit/03e1c8b8f9cc7b898217b7789d3887a903443c93
it is to workaround an elfutils/libdw issue as it does not support bpf backend so pahole cannot display debuginfo structures properly. Subsequently, the elfutils/libdw bpf support is added at

https://sourceware.org/git/?p=elfutils.git;a=commitdiff;h=c1990d36cfe37a30bcc49422c37a6767fd190559

Any recent pahole should already build with the above fix. I tested with pahole 1.16 it works fine for binaries built without +dwarfris. Also BTF now can be used to dump structures.

So could you also accommodate the change to remove +dwarfris option?

Quoted 19 lines
tools/testing/selftests/bpf/Makefile +1 -10
  endef
  # Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
  define CLANG_NOALU32_BPF_BUILD_RULE
-	$(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm			\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -march=bpf -mcpu=v2 $4 -filetype=obj -o $2
-endef
-# Similar to CLANG_BPF_BUILD_RULE, but using native Clang and bpf LLC
-define CLANG_NATIVE_BPF_BUILD_RULE
  	$(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -emit-llvm					\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
+	$(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v2 $4
  endef
  # Build BPF object using GCC
  define GCC_BPF_BUILD_RULE

tools/testing/selftests/bpf/Makefile TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko \ · line 393

Quoted 5 lines
tools/testing/selftests/bpf/Makefile +1 -1
@@ -402,7 +390,7 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko	\
  		       $(wildcard progs/btf_dump_test_case_*.c)
  TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
  TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
-TRUNNER_BPF_LDFLAGS := -mattr=+alu32
+TRUNNER_BPF_LDFLAGS := -Xclang -target-feature -Xclang +alu32

The +alu32 is only used for non-alu32 case where -mcpu=v3 actually implies alu32. So let us remove TRUNNER_BPF_LDFLAGS flag from Makefile too.

Quoted 4 lines
tools/testing/selftests/bpf/Makefile +0 -0
  $(eval $(call DEFINE_TEST_RUNNER,test_progs))
 
  # Define test_progs-no_alu32 test runner.
#2 lore raw
Quoted 86 lines · Yonghong Song
Quoted 4 lines · Andrew Delgadillo

LLC is meant for compiler development and debugging. Consequently, it exposes many low level options about its backend. To avoid future bugs introduced by using the raw LLC tool, use clang directly so that all appropriate options are passed to the back end.

Agree that this indeed make build system simpler.

Quoted 3 lines

Additionally, the native clang build rule was not being use in the selftests Makefile, so remove it.

This is true too. Otherwise, native clang build will require both clang and llc runs.

The patch looks good and I have a few comments and hopefully you can accommodate.

Quoted 19 lines
---
  tools/testing/selftests/bpf/Makefile | 20 ++++----------------
  1 file changed, 4 insertions(+), 16 deletions(-)
tools/testing/selftests/bpf/Makefile +0 -1
index 944ae17a39ed..74870d365b62 100644
@@ -19,7 +19,6 @@ ifneq ($(wildcard $(GENHDR)),)
  endif
 
  CLANG               ?= clang
-LLC          ?= llc
  LLVM_OBJCOPY        ?= llvm-objcopy
  BPF_GCC             ?= $(shell command -v bpf-gcc;)
  SAN_CFLAGS  ?=

tools/testing/selftests/bpf/Makefile $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h · line 259

Quoted 9 lines
tools/testing/selftests/bpf/Makefile +2 -4
@@ -256,24 +255,13 @@ $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h
  # $3 - CFLAGS
  # $4 - LDFLAGS
  define CLANG_BPF_BUILD_RULE
-     $(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
-     $(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm                     \
-             -c $1 -o - || echo "BPF obj compilation failed") |      \
-     $(LLC) -mattr=dwarfris -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
+     $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
+     $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -Xclang -target-feature -Xclang +dwarfris -mcpu=v3 $4

Yes, we still use +dwarfris here.
The original llvm patch which introduded +dwarfris is:

https://github.com/llvm/llvm-project/commit/03e1c8b8f9cc7b898217b7789d3887a903443c93
it is to workaround an elfutils/libdw issue as it does not support bpf backend so pahole cannot display debuginfo structures properly. Subsequently, the elfutils/libdw bpf support is added at

https://sourceware.org/git/?p=elfutils.git;a=commitdiff;h=c1990d36cfe37a30bcc49422c37a6767fd190559

Any recent pahole should already build with the above fix. I tested with pahole 1.16 it works fine for binaries built without +dwarfris. Also BTF now can be used to dump structures.

So could you also accommodate the change to remove +dwarfris option?

Quoted 19 lines
tools/testing/selftests/bpf/Makefile +1 -10
  endef
  # Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
  define CLANG_NOALU32_BPF_BUILD_RULE
-     $(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
-     $(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm                     \
-             -c $1 -o - || echo "BPF obj compilation failed") |      \
-     $(LLC) -march=bpf -mcpu=v2 $4 -filetype=obj -o $2
-endef
-# Similar to CLANG_BPF_BUILD_RULE, but using native Clang and bpf LLC
-define CLANG_NATIVE_BPF_BUILD_RULE
      $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
-     $(Q)($(CLANG) $3 -O2 -emit-llvm                                 \
-             -c $1 -o - || echo "BPF obj compilation failed") |      \
-     $(LLC) -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
+     $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v2 $4
  endef
  # Build BPF object using GCC
  define GCC_BPF_BUILD_RULE
@@ -402,7 +390,7 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko    \
Quoted 13 lines

tools/testing/selftests/bpf/Makefile TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko \ · line 393

Quoted 5 lines
tools/testing/selftests/bpf/Makefile +1 -1
                     $(wildcard progs/btf_dump_test_case_*.c)
  TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
  TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
-TRUNNER_BPF_LDFLAGS := -mattr=+alu32
+TRUNNER_BPF_LDFLAGS := -Xclang -target-feature -Xclang +alu32

The +alu32 is only used for non-alu32 case where -mcpu=v3 actually implies alu32. So let us remove TRUNNER_BPF_LDFLAGS flag from Makefile too.

Quoted 4 lines
tools/testing/selftests/bpf/Makefile +0 -0
  $(eval $(call DEFINE_TEST_RUNNER,test_progs))
 
  # Define test_progs-no_alu32 test runner.

Thank you for reviewing. I will make those changes and send a v2 of the patch.

#3 lore raw

PATCH v2 1/1 selftests/bpf: Drop the need for LLVM's llc

In reply to Andrew Delgadillo

LLC is meant for compiler development and debugging. Consequently, it exposes many low level options about its backend. To avoid future bugs introduced by using the raw LLC tool, use clang directly so that all appropriate options are passed to the back end.

Additionally, simplify the Makefile by removing the CLANG_NATIVE_BPF_BUILD_RULE as it is not being use, stop passing dwarfris attr since elfutils/libdw now supports the bpf backend (which should work with any recent pahole), and stop passing alu32 since -mcpu=v3 implies alu32.

---
Changes since v1:
* do not pass +dwarfris
* do not pass +alu32 when using -mcpu=v3

---
 tools/testing/selftests/bpf/Makefile | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)
tools/testing/selftests/bpf/Makefile +3 -16
index 944ae17a39ed..a96f63dfd8dc 100644
@@ -19,7 +19,6 @@ ifneq ($(wildcard $(GENHDR)),)
 endif
 
 CLANG		?= clang
-LLC		?= llc
 LLVM_OBJCOPY	?= llvm-objcopy
 BPF_GCC		?= $(shell command -v bpf-gcc;)
 SAN_CFLAGS	?=
@@ -256,24 +255,13 @@ $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h
 # $3 - CFLAGS
 # $4 - LDFLAGS
 define CLANG_BPF_BUILD_RULE
-	$(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm			\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -mattr=dwarfris -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
+	$(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
+	$(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v3 $4
 endef
 # Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
 define CLANG_NOALU32_BPF_BUILD_RULE
-	$(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm			\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -march=bpf -mcpu=v2 $4 -filetype=obj -o $2
-endef
-# Similar to CLANG_BPF_BUILD_RULE, but using native Clang and bpf LLC
-define CLANG_NATIVE_BPF_BUILD_RULE
 	$(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -emit-llvm					\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
+	$(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v2 $4
 endef
 # Build BPF object using GCC
 define GCC_BPF_BUILD_RULE
@@ -402,7 +390,6 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko	\
 		       $(wildcard progs/btf_dump_test_case_*.c)
 TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
-TRUNNER_BPF_LDFLAGS := -mattr=+alu32
 $(eval $(call DEFINE_TEST_RUNNER,test_progs))
 
 # Define test_progs-no_alu32 test runner.
Signature · 1 line
2.29.2.576.ga3fc446d84-goog
#4 lore raw

PATCH v2 1/1 selftests/bpf: Drop the need for LLVM's llc

LLC is meant for compiler development and debugging. Consequently, it exposes many low level options about its backend. To avoid future bugs introduced by using the raw LLC tool, use clang directly so that all appropriate options are passed to the back end.

Additionally, simplify the Makefile by removing the CLANG_NATIVE_BPF_BUILD_RULE as it is not being use, stop passing dwarfris attr since elfutils/libdw now supports the bpf backend (which should work with any recent pahole), and stop passing alu32 since -mcpu=v3 implies alu32.

---
Changes since v1:
* do not pass +dwarfris
* do not pass +alu32 when using -mcpu=v3

---
 tools/testing/selftests/bpf/Makefile | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)
tools/testing/selftests/bpf/Makefile +3 -16
index 944ae17a39ed..a96f63dfd8dc 100644
@@ -19,7 +19,6 @@ ifneq ($(wildcard $(GENHDR)),)
 endif
 
 CLANG		?= clang
-LLC		?= llc
 LLVM_OBJCOPY	?= llvm-objcopy
 BPF_GCC		?= $(shell command -v bpf-gcc;)
 SAN_CFLAGS	?=
@@ -256,24 +255,13 @@ $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h
 # $3 - CFLAGS
 # $4 - LDFLAGS
 define CLANG_BPF_BUILD_RULE
-	$(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm			\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -mattr=dwarfris -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
+	$(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
+	$(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v3 $4
 endef
 # Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
 define CLANG_NOALU32_BPF_BUILD_RULE
-	$(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm			\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -march=bpf -mcpu=v2 $4 -filetype=obj -o $2
-endef
-# Similar to CLANG_BPF_BUILD_RULE, but using native Clang and bpf LLC
-define CLANG_NATIVE_BPF_BUILD_RULE
 	$(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -emit-llvm					\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
+	$(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v2 $4
 endef
 # Build BPF object using GCC
 define GCC_BPF_BUILD_RULE
@@ -402,7 +390,6 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko	\
 		       $(wildcard progs/btf_dump_test_case_*.c)
 TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
-TRUNNER_BPF_LDFLAGS := -mattr=+alu32
 $(eval $(call DEFINE_TEST_RUNNER,test_progs))
 
 # Define test_progs-no_alu32 test runner.
Signature · 1 line
2.29.2.576.ga3fc446d84-goog
#5 lore raw
Quoted 33 lines · Andrew Delgadillo

LLC is meant for compiler development and debugging. Consequently, it exposes many low level options about its backend. To avoid future bugs introduced by using the raw LLC tool, use clang directly so that all appropriate options are passed to the back end.

Additionally, simplify the Makefile by removing the CLANG_NATIVE_BPF_BUILD_RULE as it is not being use, stop passing dwarfris attr since elfutils/libdw now supports the bpf backend (which should work with any recent pahole), and stop passing alu32 since -mcpu=v3 implies alu32.

---
Changes since v1:
* do not pass +dwarfris
* do not pass +alu32 when using -mcpu=v3

---
  tools/testing/selftests/bpf/Makefile | 19 +++----------------
  1 file changed, 3 insertions(+), 16 deletions(-)
tools/testing/selftests/bpf/Makefile +0 -1
index 944ae17a39ed..a96f63dfd8dc 100644
@@ -19,7 +19,6 @@ ifneq ($(wildcard $(GENHDR)),)
  endif
 
  CLANG		?= clang
-LLC		?= llc
  LLVM_OBJCOPY	?= llvm-objcopy
  BPF_GCC		?= $(shell command -v bpf-gcc;)
  SAN_CFLAGS	?=

tools/testing/selftests/bpf/Makefile $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h · line 256

Quoted 2 lines
tools/testing/selftests/bpf/Makefile +0 -0
@@ -256,24 +255,13 @@ $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h
  # $3 - CFLAGS
  # $4 - LDFLAGS

You can remove TRUNNER_BPF_LDFLAGS completely, so we won't have $4 here.

tools/testing/selftests/bpf/Makefile $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h · line 259

Quoted 7 lines
tools/testing/selftests/bpf/Makefile +2 -4
  define CLANG_BPF_BUILD_RULE
-	$(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm			\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -mattr=dwarfris -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
+	$(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
+	$(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v3 $4

and $4 here.

Quoted 5 lines
tools/testing/selftests/bpf/Makefile +0 -2
  endef
  # Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
  define CLANG_NOALU32_BPF_BUILD_RULE
-	$(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm			\

tools/testing/selftests/bpf/Makefile $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h · line 264

Quoted 10 lines
tools/testing/selftests/bpf/Makefile +1 -8
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -march=bpf -mcpu=v2 $4 -filetype=obj -o $2
-endef
-# Similar to CLANG_BPF_BUILD_RULE, but using native Clang and bpf LLC
-define CLANG_NATIVE_BPF_BUILD_RULE
  	$(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -emit-llvm					\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
+	$(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v2 $4

and $4 here.

Quoted 12 lines
tools/testing/selftests/bpf/Makefile +0 -1
  endef
  # Build BPF object using GCC
  define GCC_BPF_BUILD_RULE
@@ -402,7 +390,6 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko	\
  		       $(wildcard progs/btf_dump_test_case_*.c)
  TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
  TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
-TRUNNER_BPF_LDFLAGS := -mattr=+alu32
  $(eval $(call DEFINE_TEST_RUNNER,test_progs))
 
  # Define test_progs-no_alu32 test runner.
#6 lore raw

PATCH v3 1/1 selftests/bpf: Drop the need for LLVM's llc

LLC is meant for compiler development and debugging. Consequently, it exposes many low level options about its backend. To avoid future bugs introduced by using the raw LLC tool, use clang directly so that all appropriate options are passed to the back end.

Additionally, simplify the Makefile by removing the CLANG_NATIVE_BPF_BUILD_RULE as it is not being use, stop passing dwarfris attr since elfutils/libdw now supports the bpf backend (which should work with any recent pahole), and stop passing alu32 since -mcpu=v3 implies alu32.

---
Changes since v2:
* Remove TRUNNER_BPF_LDFLAGS since they are not used Changes since v1:
* do not pass +dwarfris
* do not pass +alu32 when using -mcpu=v3

---
 tools/testing/selftests/bpf/Makefile | 28 +++++-----------------------
 1 file changed, 5 insertions(+), 23 deletions(-)
tools/testing/selftests/bpf/Makefile +5 -23
index 944ae17a39ed..70122f414bcd 100644
@@ -19,7 +19,6 @@ ifneq ($(wildcard $(GENHDR)),)
 endif
 
 CLANG		?= clang
-LLC		?= llc
 LLVM_OBJCOPY	?= llvm-objcopy
 BPF_GCC		?= $(shell command -v bpf-gcc;)
 SAN_CFLAGS	?=
@@ -254,31 +253,19 @@ $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h
 # $1 - input .c file
 # $2 - output .o file
 # $3 - CFLAGS
-# $4 - LDFLAGS
 define CLANG_BPF_BUILD_RULE
-	$(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm			\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -mattr=dwarfris -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
+	$(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
+	$(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v3
 endef
 # Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
 define CLANG_NOALU32_BPF_BUILD_RULE
-	$(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm			\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -march=bpf -mcpu=v2 $4 -filetype=obj -o $2
-endef
-# Similar to CLANG_BPF_BUILD_RULE, but using native Clang and bpf LLC
-define CLANG_NATIVE_BPF_BUILD_RULE
 	$(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
-	$(Q)($(CLANG) $3 -O2 -emit-llvm					\
-		-c $1 -o - || echo "BPF obj compilation failed") | 	\
-	$(LLC) -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
+	$(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v2
 endef
 # Build BPF object using GCC
 define GCC_BPF_BUILD_RULE
 	$(call msg,GCC-BPF,$(TRUNNER_BINARY),$2)
-	$(Q)$(BPF_GCC) $3 $4 -O2 -c $1 -o $2
+	$(Q)$(BPF_GCC) $3 -O2 -c $1 -o $2
 endef
 
 SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c
@@ -333,8 +320,7 @@ $(TRUNNER_BPF_OBJS): $(TRUNNER_OUTPUT)/%.o:				\
 		     $$(INCLUDE_DIR)/vmlinux.h				\
 		     $(wildcard $(BPFDIR)/bpf_*.h) | $(TRUNNER_OUTPUT)
 	$$(call $(TRUNNER_BPF_BUILD_RULE),$$<,$$@,			\
-					  $(TRUNNER_BPF_CFLAGS),	\
-					  $(TRUNNER_BPF_LDFLAGS))
+					  $(TRUNNER_BPF_CFLAGS))
 
 $(TRUNNER_BPF_SKELS): $(TRUNNER_OUTPUT)/%.skel.h:			\
 		      $(TRUNNER_OUTPUT)/%.o				\
@@ -402,19 +388,16 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko	\
 		       $(wildcard progs/btf_dump_test_case_*.c)
 TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
-TRUNNER_BPF_LDFLAGS := -mattr=+alu32
 $(eval $(call DEFINE_TEST_RUNNER,test_progs))
 
 # Define test_progs-no_alu32 test runner.
 TRUNNER_BPF_BUILD_RULE := CLANG_NOALU32_BPF_BUILD_RULE
-TRUNNER_BPF_LDFLAGS :=
 $(eval $(call DEFINE_TEST_RUNNER,test_progs,no_alu32))
 
 # Define test_progs BPF-GCC-flavored test runner.
 ifneq ($(BPF_GCC),)
 TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE
 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc)
-TRUNNER_BPF_LDFLAGS :=
 $(eval $(call DEFINE_TEST_RUNNER,test_progs,bpf_gcc))
 endif
 
@@ -425,7 +408,6 @@ TRUNNER_EXTRA_SOURCES := test_maps.c
 TRUNNER_EXTRA_FILES :=
 TRUNNER_BPF_BUILD_RULE := $$(error no BPF objects should be built)
 TRUNNER_BPF_CFLAGS :=
-TRUNNER_BPF_LDFLAGS :=
 $(eval $(call DEFINE_TEST_RUNNER,test_maps))
 
 # Define test_verifier test runner.
Signature · 1 line
2.29.2.576.ga3fc446d84-goog
Acked-by on v3 1/1
#7 lore raw
Quoted 5 lines · Andrew Delgadillo

LLC is meant for compiler development and debugging. Consequently, it exposes many low level options about its backend. To avoid future bugs introduced by using the raw LLC tool, use clang directly so that all appropriate options are passed to the back end.

Quoted 7 lines

Additionally, simplify the Makefile by removing the CLANG_NATIVE_BPF_BUILD_RULE as it is not being use, stop passing dwarfris attr since elfutils/libdw now supports the bpf backend (which should work with any recent pahole), and stop passing alu32 since -mcpu=v3 implies alu32.

#8 lore raw
In reply to Andrew Delgadillo
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 5 lines · On Fri, 11 Dec 2020 00:43:44 +0000 you wrote:

LLC is meant for compiler development and debugging. Consequently, it exposes many low level options about its backend. To avoid future bugs introduced by using the raw LLC tool, use clang directly so that all appropriate options are passed to the back end.

Quoted 7 lines

Additionally, simplify the Makefile by removing the CLANG_NATIVE_BPF_BUILD_RULE as it is not being use, stop passing dwarfris attr since elfutils/libdw now supports the bpf backend (which should work with any recent pahole), and stop passing alu32 since -mcpu=v3 implies alu32.

[...]

Here is the summary with links:
- [bpf-next,v3] selftests/bpf: Drop the need for LLVM's llc

    https://git.kernel.org/bpf/bpf-next/c/89ad7420b25c

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