-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tc-testing: fix build of eBPF programs
rely on uAPI headers in the current kernel tree, rather than requiring the correct version installed on the test system. While at it, group all sections in a single binary and test the 'section' parameter. Reported-by: Lucas Bates <lucasb@mojatatu.com> Signed-off-by: Davide Caratti <dcaratti@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
- Loading branch information
Davide Caratti
authored and
David S. Miller
committed
Oct 5, 2018
1 parent
4a84810
commit cf5eafb
Showing
4 changed files
with
63 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
APIDIR := ../../../../include/uapi | ||
TEST_GEN_FILES = action.o | ||
|
||
top_srcdir = ../../../../.. | ||
include ../../lib.mk | ||
|
||
CLANG ?= clang | ||
LLC ?= llc | ||
PROBE := $(shell $(LLC) -march=bpf -mcpu=probe -filetype=null /dev/null 2>&1) | ||
|
||
ifeq ($(PROBE),) | ||
CPU ?= probe | ||
else | ||
CPU ?= generic | ||
endif | ||
|
||
CLANG_SYS_INCLUDES := $(shell $(CLANG) -v -E - </dev/null 2>&1 \ | ||
| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') | ||
|
||
CLANG_FLAGS = -I. -I$(APIDIR) \ | ||
$(CLANG_SYS_INCLUDES) \ | ||
-Wno-compare-distinct-pointer-types | ||
|
||
$(OUTPUT)/%.o: %.c | ||
$(CLANG) $(CLANG_FLAGS) \ | ||
-O2 -target bpf -emit-llvm -c $< -o - | \ | ||
$(LLC) -march=bpf -mcpu=$(CPU) $(LLC_FLAGS) -filetype=obj -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 | ||
* Copyright (c) 2018 Davide Caratti, Red Hat inc. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of version 2 of the GNU General Public | ||
* License as published by the Free Software Foundation. | ||
*/ | ||
|
||
#include <linux/bpf.h> | ||
#include <linux/pkt_cls.h> | ||
|
||
__attribute__((section("action-ok"),used)) int action_ok(struct __sk_buff *s) | ||
{ | ||
return TC_ACT_OK; | ||
} | ||
|
||
__attribute__((section("action-ko"),used)) int action_ko(struct __sk_buff *s) | ||
{ | ||
s->data = 0x0; | ||
return TC_ACT_OK; | ||
} | ||
|
||
char _license[] __attribute__((section("license"),used)) = "GPL"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters