Skip to contentSkip to conversation

samples/bpf: change Makefile to cope with latest llvm

PATCH Superseded Yonghong Song 2 participants 6 messages Oct 3, 2020 – Oct 6, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 samples/bpf: change Makefile to cope with latest llvm

With latest llvm trunk, bpf programs under samples/bpf directory, if using CORE, may experience the following errors:

LLVM ERROR: Cannot select: intrinsic %llvm.preserve.struct.access.index PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace. Stack dump:

0.      Program arguments: llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o
1.      Running pass 'Function Pass Manager' on module '<stdin>'.
2.      Running pass 'BPF DAG->DAG Pattern Instruction Selection' on function '@bpf_prog1'
 #0 0x000000000183c26c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
    (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x183c26c)
...
 #7 0x00000000017c375e (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x17c375e)
 #8 0x00000000016a75c5 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*)
    (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16a75c5)
 #9 0x00000000016ab4f8 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*,
    unsigned int) (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16ab4f8)

...
Aborted (core dumped) | llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o

The reason is due to llvm change https://reviews.llvm.org/D87153
where the CORE relocation global generation is moved from the beginning of target dependent optimization (llc) to the beginning
of target independent optimization (opt).

Since samples/bpf programs did not use vmlinux.h and its clang compilation uses native architecture, we need to adjust arch triple at opt level to do CORE relocation global generation properly. Otherwise, the above error will appear.

This patch fixed the issue by introduce opt and llvm-dis to compilation chain, which will do proper CORE relocation global generation as well as O2 level optimization. Tested with llvm10, llvm11 and trunk/llvm12.

---
 samples/bpf/Makefile | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
samples/bpf/Makefile +5 -1
index 4f1ed0e3cf9f..79c5fdea63d2 100644
@@ -211,6 +211,8 @@ TPROGLDLIBS_xsk_fwd		+= -pthread
 #  make M=samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
 LLC ?= llc
 CLANG ?= clang
+OPT ?= opt
+LLVM_DIS ?= llvm-dis
 LLVM_OBJCOPY ?= llvm-objcopy
 BTF_PAHOLE ?= pahole
 
@@ -314,7 +316,9 @@ $(obj)/%.o: $(src)/%.c
 		-Wno-address-of-packed-member -Wno-tautological-compare \
 		-Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \
 		-I$(srctree)/samples/bpf/ -include asm_goto_workaround.h \
-		-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@
+		-O2 -emit-llvm -Xclang -disable-llvm-passes -c $< -o - | \
+		$(OPT) -O2 -mtriple=bpf-pc-linux | $(LLVM_DIS) | \
+		$(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@
 ifeq ($(DWARF2BTF),y)
 	$(BTF_PAHOLE) -J $@
 endif
Signature · 1 line
2.24.1
#1 lore raw

PATCH 2/2 samples/bpf: fix a compilation error with fallthrough marking

Compiling samples/bpf hits an error related to fallthrough marking.

    ...
    CC  samples/bpf/hbm.o
  samples/bpf/hbm.c: In function ‘main’:
  samples/bpf/hbm.c:486:4: error: ‘fallthrough’ undeclared (first use in this function)
      fallthrough;
      ^~~~~~~~~~~

The "fallthrough" is not defined under tools/include directory. Rather, it is "__fallthrough" is defined in linux/compiler.h. Including "linux/compiler.h" and using "__fallthrough" fixed the issue.

---
 samples/bpf/hbm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
samples/bpf/hbm.c +2 -1
index 4b22ace52f80..ff4c533dfac2 100644
@@ -40,6 +40,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <linux/unistd.h>
+#include <linux/compiler.h>
 
 #include <linux/bpf.h>
 #include <bpf/bpf.h>
@@ -483,7 +484,7 @@ int main(int argc, char **argv)
 					"Option -%c requires an argument.\n\n",
 					optopt);
 		case 'h':
-			fallthrough;
+			__fallthrough;
 		default:
 			Usage();
 			return 0;
Signature · 1 line
2.24.1
#2 lore raw
In reply to Yonghong Song
Quoted 55 lines · Yonghong Song

With latest llvm trunk, bpf programs under samples/bpf directory, if using CORE, may experience the following errors:

LLVM ERROR: Cannot select: intrinsic %llvm.preserve.struct.access.index PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace. Stack dump:

0.      Program arguments: llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o
1.      Running pass 'Function Pass Manager' on module '<stdin>'.
2.      Running pass 'BPF DAG->DAG Pattern Instruction Selection' on function '@bpf_prog1'
 #0 0x000000000183c26c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
    (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x183c26c)
...
 #7 0x00000000017c375e (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x17c375e)
 #8 0x00000000016a75c5 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*)
    (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16a75c5)
 #9 0x00000000016ab4f8 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*,
    unsigned int) (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16ab4f8)

...
Aborted (core dumped) | llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o

The reason is due to llvm change https://reviews.llvm.org/D87153
where the CORE relocation global generation is moved from the beginning of target dependent optimization (llc) to the beginning
of target independent optimization (opt).

Since samples/bpf programs did not use vmlinux.h and its clang compilation uses native architecture, we need to adjust arch triple at opt level to do CORE relocation global generation properly. Otherwise, the above error will appear.

This patch fixed the issue by introduce opt and llvm-dis to compilation chain, which will do proper CORE relocation global generation as well as O2 level optimization. Tested with llvm10, llvm11 and trunk/llvm12.

---
 samples/bpf/Makefile | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
samples/bpf/Makefile +2 -0
index 4f1ed0e3cf9f..79c5fdea63d2 100644
@@ -211,6 +211,8 @@ TPROGLDLIBS_xsk_fwd         += -pthread
 #  make M=samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
 LLC ?= llc
 CLANG ?= clang
+OPT ?= opt
+LLVM_DIS ?= llvm-dis
 LLVM_OBJCOPY ?= llvm-objcopy
 BTF_PAHOLE ?= pahole
 

samples/bpf/Makefile $(obj)/%.o: $(src)/%.c · line 321

Quoted 7 lines
samples/bpf/Makefile +3 -1
@@ -314,7 +316,9 @@ $(obj)/%.o: $(src)/%.c
                -Wno-address-of-packed-member -Wno-tautological-compare \
                -Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \
                -I$(srctree)/samples/bpf/ -include asm_goto_workaround.h \
-               -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@
+               -O2 -emit-llvm -Xclang -disable-llvm-passes -c $< -o - | \
+               $(OPT) -O2 -mtriple=bpf-pc-linux | $(LLVM_DIS) | \
+               $(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@

I keep forgetting exact details of why we do this native clang + llc pipeline instead of just doing clang -target bpf? Is it still relevant and necessary, or we can just simplify it now?

Quoted 6 lines
samples/bpf/Makefile +0 -1
 ifeq ($(DWARF2BTF),y)
        $(BTF_PAHOLE) -J $@
 endif
--

2.24.1

#3 lore raw
Quoted 55 lines · Andrii Nakryiko
Quoted 54 lines · Yonghong Song

With latest llvm trunk, bpf programs under samples/bpf directory, if using CORE, may experience the following errors:

LLVM ERROR: Cannot select: intrinsic %llvm.preserve.struct.access.index
PLEASE submit a bug report to https://urldefense.proofpoint.com/v2/url?u=https-3A__bugs.llvm.org_&d=DwIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=_D9tvuWQ6EbYqcMBdVB0qqRMVdV6Etws5ITtx8Pa1ZM&s=BwTAvhipPl-Az_WaiJDbqU8yl__NvG8W4HmCqWqHdqg&e= and include the crash backtrace. Stack dump:

0.      Program arguments: llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o
1.      Running pass 'Function Pass Manager' on module '<stdin>'.
2.      Running pass 'BPF DAG->DAG Pattern Instruction Selection' on function '@bpf_prog1'
  #0 0x000000000183c26c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
     (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x183c26c)
...
  #7 0x00000000017c375e (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x17c375e)
  #8 0x00000000016a75c5 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*)
     (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16a75c5)
  #9 0x00000000016ab4f8 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*,
     unsigned int) (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16ab4f8)

...
Aborted (core dumped) | llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o

The reason is due to llvm change https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D87153&d=DwIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=_D9tvuWQ6EbYqcMBdVB0qqRMVdV6Etws5ITtx8Pa1ZM&s=fo_LvXqHJx_m0m0pJJiDdOUcOzVXm2_iYoxPhpqpzng&e=
where the CORE relocation global generation is moved from the beginning
of target dependent optimization (llc) to the beginning
of target independent optimization (opt).

Since samples/bpf programs did not use vmlinux.h and its clang compilation uses native architecture, we need to adjust arch triple at opt level to do CORE relocation global generation properly. Otherwise, the above error will appear.

This patch fixed the issue by introduce opt and llvm-dis to compilation chain, which will do proper CORE relocation global generation as well as O2 level optimization. Tested with llvm10, llvm11 and trunk/llvm12.

---
  samples/bpf/Makefile | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
samples/bpf/Makefile +2 -0
index 4f1ed0e3cf9f..79c5fdea63d2 100644
@@ -211,6 +211,8 @@ TPROGLDLIBS_xsk_fwd         += -pthread
  #  make M=samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
  LLC ?= llc
  CLANG ?= clang
+OPT ?= opt
+LLVM_DIS ?= llvm-dis
  LLVM_OBJCOPY ?= llvm-objcopy
  BTF_PAHOLE ?= pahole
 
Quoted 11 lines

samples/bpf/Makefile $(obj)/%.o: $(src)/%.c · line 321

Quoted 8 lines
samples/bpf/Makefile +3 -1
@@ -314,7 +316,9 @@ $(obj)/%.o: $(src)/%.c
                 -Wno-address-of-packed-member -Wno-tautological-compare \
                 -Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \
                 -I$(srctree)/samples/bpf/ -include asm_goto_workaround.h \
-               -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@
+               -O2 -emit-llvm -Xclang -disable-llvm-passes -c $< -o - | \
+               $(OPT) -O2 -mtriple=bpf-pc-linux | $(LLVM_DIS) | \
+               $(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@

I keep forgetting exact details of why we do this native clang + llc pipeline instead of just doing clang -target bpf? Is it still

samples/bpf programs did not use vmlinux.h. they directly use kernel-devel headers, hence they need to first compile with native arch for clang but later change target arch to bpf to generate final byte code. They cannot just do 'clang -target bpf' without vmlinux.h.

But changing to use vmlinux.h is a much bigger project and I merely want to make it just work so people won't make/compile samples/bpf and get compilation errors.

Quoted 8 lines

relevant and necessary, or we can just simplify it now?

Quoted 6 lines
samples/bpf/Makefile +0 -1
  ifeq ($(DWARF2BTF),y)
         $(BTF_PAHOLE) -J $@
  endif
--

2.24.1

#4 lore raw
Quoted 59 lines · Yonghong Song
Quoted 55 lines · Andrii Nakryiko
Quoted 54 lines · Yonghong Song

With latest llvm trunk, bpf programs under samples/bpf directory, if using CORE, may experience the following errors:

LLVM ERROR: Cannot select: intrinsic %llvm.preserve.struct.access.index
PLEASE submit a bug report to https://urldefense.proofpoint.com/v2/url?u=https-3A__bugs.llvm.org_&d=DwIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=_D9tvuWQ6EbYqcMBdVB0qqRMVdV6Etws5ITtx8Pa1ZM&s=BwTAvhipPl-Az_WaiJDbqU8yl__NvG8W4HmCqWqHdqg&e= and include the crash backtrace. Stack dump:

0.      Program arguments: llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o
1.      Running pass 'Function Pass Manager' on module '<stdin>'.
2.      Running pass 'BPF DAG->DAG Pattern Instruction Selection' on function '@bpf_prog1'
  #0 0x000000000183c26c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
     (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x183c26c)
...
  #7 0x00000000017c375e (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x17c375e)
  #8 0x00000000016a75c5 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*)
     (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16a75c5)
  #9 0x00000000016ab4f8 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*,
     unsigned int) (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16ab4f8)

...
Aborted (core dumped) | llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o

The reason is due to llvm change https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D87153&d=DwIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=_D9tvuWQ6EbYqcMBdVB0qqRMVdV6Etws5ITtx8Pa1ZM&s=fo_LvXqHJx_m0m0pJJiDdOUcOzVXm2_iYoxPhpqpzng&e=
where the CORE relocation global generation is moved from the beginning
of target dependent optimization (llc) to the beginning
of target independent optimization (opt).

Since samples/bpf programs did not use vmlinux.h and its clang compilation uses native architecture, we need to adjust arch triple at opt level to do CORE relocation global generation properly. Otherwise, the above error will appear.

This patch fixed the issue by introduce opt and llvm-dis to compilation chain, which will do proper CORE relocation global generation as well as O2 level optimization. Tested with llvm10, llvm11 and trunk/llvm12.

---
  samples/bpf/Makefile | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
samples/bpf/Makefile +2 -0
index 4f1ed0e3cf9f..79c5fdea63d2 100644
@@ -211,6 +211,8 @@ TPROGLDLIBS_xsk_fwd         += -pthread
  #  make M=samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
  LLC ?= llc
  CLANG ?= clang
+OPT ?= opt
+LLVM_DIS ?= llvm-dis
  LLVM_OBJCOPY ?= llvm-objcopy
  BTF_PAHOLE ?= pahole
 
Quoted 8 lines
Quoted 8 lines

samples/bpf/Makefile $(obj)/%.o: $(src)/%.c · line 321

Quoted 8 lines
samples/bpf/Makefile +3 -1
@@ -314,7 +316,9 @@ $(obj)/%.o: $(src)/%.c
                 -Wno-address-of-packed-member -Wno-tautological-compare \
                 -Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \
                 -I$(srctree)/samples/bpf/ -include asm_goto_workaround.h \
-               -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@
+               -O2 -emit-llvm -Xclang -disable-llvm-passes -c $< -o - | \
+               $(OPT) -O2 -mtriple=bpf-pc-linux | $(LLVM_DIS) | \
+               $(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@

This is an extremely unusual set of steps, and might be worthwhile to leave a comment explaining what's going on, so that I or someone else doesn't ask the same question few months later :)

At any rate, this fixes the issue, so:

Quoted 8 lines
Quoted 3 lines

I keep forgetting exact details of why we do this native clang + llc pipeline instead of just doing clang -target bpf? Is it still

samples/bpf programs did not use vmlinux.h. they directly use kernel-devel headers, hence they need to first compile with native arch for clang but later change target arch to bpf to generate final byte code. They cannot just do 'clang -target bpf' without vmlinux.h.

Ok, right, thanks for explanation. I wonder if this "native" clang + llc pass will also help with vmlinux.h on 32-bit architectures (though with my recent patches that shouldn't be necessary, so this is more of a curiosity, rather than the need).

Quoted 4 lines

But changing to use vmlinux.h is a much bigger project and I merely want to make it just work so people won't make/compile samples/bpf and get compilation errors.

Right, of course.

Quoted 9 lines
Quoted 9 lines

relevant and necessary, or we can just simplify it now?

Quoted 6 lines
samples/bpf/Makefile +0 -1
  ifeq ($(DWARF2BTF),y)
         $(BTF_PAHOLE) -J $@
  endif
--

2.24.1

#5 lore raw
Quoted 60 lines · Andrii Nakryiko
Quoted 59 lines · Yonghong Song
Quoted 55 lines · Andrii Nakryiko
Quoted 54 lines · Yonghong Song

With latest llvm trunk, bpf programs under samples/bpf directory, if using CORE, may experience the following errors:

LLVM ERROR: Cannot select: intrinsic %llvm.preserve.struct.access.index
PLEASE submit a bug report to https://urldefense.proofpoint.com/v2/url?u=https-3A__bugs.llvm.org_&d=DwIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=_D9tvuWQ6EbYqcMBdVB0qqRMVdV6Etws5ITtx8Pa1ZM&s=BwTAvhipPl-Az_WaiJDbqU8yl__NvG8W4HmCqWqHdqg&e= and include the crash backtrace. Stack dump:

0.      Program arguments: llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o
1.      Running pass 'Function Pass Manager' on module '<stdin>'.
2.      Running pass 'BPF DAG->DAG Pattern Instruction Selection' on function '@bpf_prog1'
   #0 0x000000000183c26c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
      (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x183c26c)
...
   #7 0x00000000017c375e (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x17c375e)
   #8 0x00000000016a75c5 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*)
      (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16a75c5)
   #9 0x00000000016ab4f8 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*,
      unsigned int) (/data/users/yhs/work/llvm-project/llvm/build.cur/install/bin/llc+0x16ab4f8)

...
Aborted (core dumped) | llc -march=bpf -filetype=obj -o samples/bpf/test_probe_write_user_kern.o

The reason is due to llvm change https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D87153&d=DwIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=_D9tvuWQ6EbYqcMBdVB0qqRMVdV6Etws5ITtx8Pa1ZM&s=fo_LvXqHJx_m0m0pJJiDdOUcOzVXm2_iYoxPhpqpzng&e=
where the CORE relocation global generation is moved from the beginning
of target dependent optimization (llc) to the beginning
of target independent optimization (opt).

Since samples/bpf programs did not use vmlinux.h and its clang compilation uses native architecture, we need to adjust arch triple at opt level to do CORE relocation global generation properly. Otherwise, the above error will appear.

This patch fixed the issue by introduce opt and llvm-dis to compilation chain, which will do proper CORE relocation global generation as well as O2 level optimization. Tested with llvm10, llvm11 and trunk/llvm12.

---
   samples/bpf/Makefile | 6 +++++-
   1 file changed, 5 insertions(+), 1 deletion(-)
samples/bpf/Makefile +2 -0
index 4f1ed0e3cf9f..79c5fdea63d2 100644
@@ -211,6 +211,8 @@ TPROGLDLIBS_xsk_fwd         += -pthread
   #  make M=samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
   LLC ?= llc
   CLANG ?= clang
+OPT ?= opt
+LLVM_DIS ?= llvm-dis
   LLVM_OBJCOPY ?= llvm-objcopy
   BTF_PAHOLE ?= pahole
 
Quoted 12 lines
Quoted 8 lines
Quoted 8 lines

samples/bpf/Makefile $(obj)/%.o: $(src)/%.c · line 321

Quoted 8 lines
samples/bpf/Makefile +3 -1
@@ -314,7 +316,9 @@ $(obj)/%.o: $(src)/%.c
                  -Wno-address-of-packed-member -Wno-tautological-compare \
                  -Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \
                  -I$(srctree)/samples/bpf/ -include asm_goto_workaround.h \
-               -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@
+               -O2 -emit-llvm -Xclang -disable-llvm-passes -c $< -o - | \
+               $(OPT) -O2 -mtriple=bpf-pc-linux | $(LLVM_DIS) | \
+               $(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@

This is an extremely unusual set of steps, and might be worthwhile to leave a comment explaining what's going on, so that I or someone else doesn't ask the same question few months later :)

Sure. Will add some comments and send v2.

Quoted 14 lines

At any rate, this fixes the issue, so:

Quoted 8 lines
Quoted 3 lines

I keep forgetting exact details of why we do this native clang + llc pipeline instead of just doing clang -target bpf? Is it still

samples/bpf programs did not use vmlinux.h. they directly use kernel-devel headers, hence they need to first compile with native arch for clang but later change target arch to bpf to generate final byte code. They cannot just do 'clang -target bpf' without vmlinux.h.

Quoted 4 lines

Ok, right, thanks for explanation. I wonder if this "native" clang + llc pass will also help with vmlinux.h on 32-bit architectures (though with my recent patches that shouldn't be necessary, so this is more of a curiosity, rather than the need).

Yes, I think this should help 32-bit as all the 32-bit long/ptr size is captured in IR. I probably tried before with 32bit x86 uprobe, but I forgot details...

Quoted 17 lines
Quoted 5 lines

But changing to use vmlinux.h is a much bigger project and I merely want to make it just work so people won't make/compile samples/bpf and get compilation errors.

Right, of course.

Quoted 9 lines
Quoted 9 lines

relevant and necessary, or we can just simplify it now?

Quoted 6 lines
samples/bpf/Makefile +0 -1
   ifeq ($(DWARF2BTF),y)
          $(BTF_PAHOLE) -J $@
   endif
--

2.24.1