Message ID | 20230208205642.270567-5-iii@linux.ibm.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | BPF |
Headers | show |
Series | selftests/bpf: Add Memory Sanitizer support | expand |
On Wed, Feb 8, 2023 at 12:57 PM Ilya Leoshkevich <iii@linux.ibm.com> wrote: > > To get useful results from the Memory Sanitizer, all code running in a > process needs to be instrumented. When building tests with other > sanitizers, it's not strictly necessary, but is also helpful. > So make sure runqslower and libbpf are compiled with SAN_CFLAGS and > linked with SAN_LDFLAGS. > > Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> > --- > tools/testing/selftests/bpf/Makefile | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile > index 9b5786ac676e..c4b5c44cdee2 100644 > --- a/tools/testing/selftests/bpf/Makefile > +++ b/tools/testing/selftests/bpf/Makefile > @@ -215,7 +215,9 @@ $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL) $(RUNQSLOWER_OUTPUT) > OUTPUT=$(RUNQSLOWER_OUTPUT) VMLINUX_BTF=$(VMLINUX_BTF) \ > BPFTOOL_OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \ > BPFOBJ_OUTPUT=$(BUILD_DIR)/libbpf \ > - BPFOBJ=$(BPFOBJ) BPF_INCLUDE=$(INCLUDE_DIR) && \ > + BPFOBJ=$(BPFOBJ) BPF_INCLUDE=$(INCLUDE_DIR) \ > + EXTRA_CFLAGS='-g -O0 $(SAN_CFLAGS)' \ > + EXTRA_LDFLAGS='$(SAN_LDFLAGS)' && \ > cp $(RUNQSLOWER_OUTPUT)runqslower $@ > I wouldn't do it for runqslower, we just make sure that it compiles, we don't really run it at all. No need to complicate its build, IMO. > TEST_GEN_PROGS_EXTENDED += $(DEFAULT_BPFTOOL) > @@ -272,7 +274,8 @@ $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ > $(APIDIR)/linux/bpf.h \ > | $(BUILD_DIR)/libbpf > $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \ > - EXTRA_CFLAGS='-g -O0' \ > + EXTRA_CFLAGS='-g -O0 $(SAN_CFLAGS)' \ > + EXTRA_LDFLAGS='$(SAN_LDFLAGS)' \ > DESTDIR=$(SCRATCH_DIR) prefix= all install_headers > > ifneq ($(BPFOBJ),$(HOST_BPFOBJ)) > -- > 2.39.1 >
On Wed, 2023-02-08 at 17:03 -0800, Andrii Nakryiko wrote: > On Wed, Feb 8, 2023 at 12:57 PM Ilya Leoshkevich <iii@linux.ibm.com> > wrote: > > > > To get useful results from the Memory Sanitizer, all code running > > in a > > process needs to be instrumented. When building tests with other > > sanitizers, it's not strictly necessary, but is also helpful. > > So make sure runqslower and libbpf are compiled with SAN_CFLAGS and > > linked with SAN_LDFLAGS. > > > > Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> > > --- > > tools/testing/selftests/bpf/Makefile | 7 +++++-- > > 1 file changed, 5 insertions(+), 2 deletions(-) > > > > diff --git a/tools/testing/selftests/bpf/Makefile > > b/tools/testing/selftests/bpf/Makefile > > index 9b5786ac676e..c4b5c44cdee2 100644 > > --- a/tools/testing/selftests/bpf/Makefile > > +++ b/tools/testing/selftests/bpf/Makefile > > @@ -215,7 +215,9 @@ $(OUTPUT)/runqslower: $(BPFOBJ) | > > $(DEFAULT_BPFTOOL) $(RUNQSLOWER_OUTPUT) > > OUTPUT=$(RUNQSLOWER_OUTPUT) > > VMLINUX_BTF=$(VMLINUX_BTF) \ > > > > BPFTOOL_OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \ > > > > BPFOBJ_OUTPUT=$(BUILD_DIR)/libbpf \ > > - BPFOBJ=$(BPFOBJ) BPF_INCLUDE=$(INCLUDE_DIR) > > && \ > > + BPFOBJ=$(BPFOBJ) > > BPF_INCLUDE=$(INCLUDE_DIR) \ > > + EXTRA_CFLAGS='-g -O0 > > $(SAN_CFLAGS)' \ > > + EXTRA_LDFLAGS='$(SAN_LDFLAGS)' > > && \ > > cp $(RUNQSLOWER_OUTPUT)runqslower $@ > > > > I wouldn't do it for runqslower, we just make sure that it compiles, > we don't really run it at all. No need to complicate its build, IMO. runqslower is linked with target libbpf, which is instrumented. This produces undefined symbol errors, since MSan runtime is expected to be a part of an executable. [...]
On Thu, Feb 9, 2023 at 1:55 AM Ilya Leoshkevich <iii@linux.ibm.com> wrote: > > On Wed, 2023-02-08 at 17:03 -0800, Andrii Nakryiko wrote: > > On Wed, Feb 8, 2023 at 12:57 PM Ilya Leoshkevich <iii@linux.ibm.com> > > wrote: > > > > > > To get useful results from the Memory Sanitizer, all code running > > > in a > > > process needs to be instrumented. When building tests with other > > > sanitizers, it's not strictly necessary, but is also helpful. > > > So make sure runqslower and libbpf are compiled with SAN_CFLAGS and > > > linked with SAN_LDFLAGS. > > > > > > Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> > > > --- > > > tools/testing/selftests/bpf/Makefile | 7 +++++-- > > > 1 file changed, 5 insertions(+), 2 deletions(-) > > > > > > diff --git a/tools/testing/selftests/bpf/Makefile > > > b/tools/testing/selftests/bpf/Makefile > > > index 9b5786ac676e..c4b5c44cdee2 100644 > > > --- a/tools/testing/selftests/bpf/Makefile > > > +++ b/tools/testing/selftests/bpf/Makefile > > > @@ -215,7 +215,9 @@ $(OUTPUT)/runqslower: $(BPFOBJ) | > > > $(DEFAULT_BPFTOOL) $(RUNQSLOWER_OUTPUT) > > > OUTPUT=$(RUNQSLOWER_OUTPUT) > > > VMLINUX_BTF=$(VMLINUX_BTF) \ > > > > > > BPFTOOL_OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \ > > > > > > BPFOBJ_OUTPUT=$(BUILD_DIR)/libbpf \ > > > - BPFOBJ=$(BPFOBJ) BPF_INCLUDE=$(INCLUDE_DIR) > > > && \ > > > + BPFOBJ=$(BPFOBJ) > > > BPF_INCLUDE=$(INCLUDE_DIR) \ > > > + EXTRA_CFLAGS='-g -O0 > > > $(SAN_CFLAGS)' \ > > > + EXTRA_LDFLAGS='$(SAN_LDFLAGS)' > > > && \ > > > cp $(RUNQSLOWER_OUTPUT)runqslower $@ > > > > > > > I wouldn't do it for runqslower, we just make sure that it compiles, > > we don't really run it at all. No need to complicate its build, IMO. > > runqslower is linked with target libbpf, which is instrumented. > This produces undefined symbol errors, since MSan runtime is expected > to be a part of an executable. ah, ok then, never mind > > [...]
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index 9b5786ac676e..c4b5c44cdee2 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -215,7 +215,9 @@ $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL) $(RUNQSLOWER_OUTPUT) OUTPUT=$(RUNQSLOWER_OUTPUT) VMLINUX_BTF=$(VMLINUX_BTF) \ BPFTOOL_OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \ BPFOBJ_OUTPUT=$(BUILD_DIR)/libbpf \ - BPFOBJ=$(BPFOBJ) BPF_INCLUDE=$(INCLUDE_DIR) && \ + BPFOBJ=$(BPFOBJ) BPF_INCLUDE=$(INCLUDE_DIR) \ + EXTRA_CFLAGS='-g -O0 $(SAN_CFLAGS)' \ + EXTRA_LDFLAGS='$(SAN_LDFLAGS)' && \ cp $(RUNQSLOWER_OUTPUT)runqslower $@ TEST_GEN_PROGS_EXTENDED += $(DEFAULT_BPFTOOL) @@ -272,7 +274,8 @@ $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ $(APIDIR)/linux/bpf.h \ | $(BUILD_DIR)/libbpf $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \ - EXTRA_CFLAGS='-g -O0' \ + EXTRA_CFLAGS='-g -O0 $(SAN_CFLAGS)' \ + EXTRA_LDFLAGS='$(SAN_LDFLAGS)' \ DESTDIR=$(SCRATCH_DIR) prefix= all install_headers ifneq ($(BPFOBJ),$(HOST_BPFOBJ))
To get useful results from the Memory Sanitizer, all code running in a process needs to be instrumented. When building tests with other sanitizers, it's not strictly necessary, but is also helpful. So make sure runqslower and libbpf are compiled with SAN_CFLAGS and linked with SAN_LDFLAGS. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> --- tools/testing/selftests/bpf/Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)