Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve portability #457

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ check_toolchain()
local emacs_version
local clang_version
local bpftool_version
local compiler=gcc

if ! command -v gcc >/dev/null 2>&1 && command -v clang >/dev/null 2>&1; then
compiler=clang
fi

: ${PKG_CONFIG:=pkg-config}
: ${CC=gcc}
: ${CC=$compiler}
: ${LD=ld}
: ${OBJCOPY=objcopy}
: ${CLANG=clang}
Expand All @@ -82,7 +87,7 @@ check_toolchain()

ARCH_NAME=$($CC -print-multiarch 2>/dev/null)

clang_version=$($CLANG --version | grep -Po '(?<=clang version )[[:digit:]]+')
clang_version=$($CLANG --version | sed -nE 's/.*clang version ([[:digit:]]+).*/\1/p')
if [ "$?" -ne "0" ]; then
echo "*** ERROR: Couldn't execute '$CLANG --version'"
exit 1
Expand Down Expand Up @@ -128,6 +133,13 @@ check_toolchain()
done
fi

case $(uname -m) in
aarch64) ARCH_EMULATION=aarch64linux ;;
armv7*) ARCH_EMULATION=armelf_linux_eabi ;;
i386) ARCH_EMULATION=elf_i386 ;;
*) ARCH_EMULATION=elf_x86_64 ;;
esac

echo "PKG_CONFIG:=${PKG_CONFIG}" >>$CONFIG
echo "CC:=${CC}" >>$CONFIG
echo "LD:=${LD}" >>$CONFIG
Expand All @@ -139,6 +151,7 @@ check_toolchain()
echo "ARCH_INCLUDES:=$ARCH_INCLUDES" >> $CONFIG
echo "READELF:=${READELF}" >> $CONFIG
echo "BPFTOOL:=${BPFTOOL}" >> $CONFIG
echo "ARCH_EMULATION:=${ARCH_EMULATION}" >> $CONFIG
[ -n "$BPFTOOL" ] && echo "HAVE_FEATURES+=BPFTOOL" >>"$CONFIG"
}

Expand Down
2 changes: 1 addition & 1 deletion lib/libxdp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ $(TEMPLATED_SOURCES): %.c: %.c.in Makefile
$(QUIET_M4)$(M4) $(DEFINES) $< > $@ || ( ret=$$?; rm -f $@; exit $$ret )

$(EMBEDDED_XDP_OBJS): %.embed.o: %.o
$(QUIET_GEN)$(LD) -r -b binary -o $@ -z noexecstack --format=binary $<
$(QUIET_GEN)$(LD) -r -b binary -o $@ -z noexecstack -m $(ARCH_EMULATION) --format=binary $<
$(Q)$(OBJCOPY) --rename-section .data=.rodata,alloc,load,readonly,data,contents $@

$(XDP_OBJS): %.o: %.c $(BPF_HEADERS) $(LIBMK)
Expand Down
1 change: 0 additions & 1 deletion lib/libxdp/libxdp.map
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ LIBXDP_1.0.0 {
xdp_multiprog__attach_mode;
xdp_multiprog__close;
xdp_multiprog__detach;
xdp_multiprog__dispatcher;
xdp_multiprog__get_from_ifindex;
xdp_multiprog__is_legacy;
xdp_multiprog__next_prog;
Expand Down
2 changes: 1 addition & 1 deletion lib/libxdp/libxdp.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
LIBXDP_VERSION := $(shell sed -ne "/LIBXDP_[0-9\.]\+ {/ {s/LIBXDP_\([0-9\.]\+\) {/\1/;p}" $(LIB_DIR)/libxdp/libxdp.map | tail -n 1)
LIBXDP_VERSION := $(shell sed -ne "/LIBXDP_[0-9\.]\+ {/ {s/LIBXDP_\([0-9\.]\+\) {/\1/;p;}" $(LIB_DIR)/libxdp/libxdp.map | tail -n 1)
LIBXDP_MAJOR_VERSION := $(shell echo $(LIBXDP_VERSION) | sed 's/\..*//')

4 changes: 2 additions & 2 deletions lib/libxdp/xdp-dispatcher.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static volatile const struct xdp_dispatcher_config conf = {};
*/
forloop(`i', `0', NUM_PROGS,
`__attribute__ ((noinline))
int format(`prog%d', i)(struct xdp_md *ctx) {
int format_prog`'i`'(struct xdp_md *ctx) {
volatile int ret = XDP_DISPATCHER_RETVAL;

if (!ctx)
Expand Down Expand Up @@ -58,7 +58,7 @@ forloop(`i', `0', NUM_PROGS,
`
if (num_progs_enabled < incr(i))
goto out;
ret = format(`prog%d', i)(ctx);
ret = format_prog`'i`'(ctx);
if (!((1U << ret) & conf.chain_call_actions[i]))
return ret;
')
Expand Down