Skip to content

Commit

Permalink
Fix build on arm64
Browse files Browse the repository at this point in the history
Fix the arm64 build by adding arch specific header files to
CFLAGS and BPF_CFLAGS. Also, use `gcc -print-multiarch` to get
arch name instead of `uname -m` which is not the right way.

Signed-off-by: Sachin Tiptur <[email protected]>
  • Loading branch information
sachintiptur authored and tohojo committed Sep 21, 2023
1 parent eccba7e commit 6ce3063
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ check_toolchain()
: ${BPFTOOL=bpftool}
: ${READELF=readelf}
: ${ARCH_INCLUDES=}
: ${ARCH_NAME=}

CLANG=$(find_tool clang "$CLANG")
LLC=$(find_tool llc "$LLC")
Expand All @@ -79,6 +80,8 @@ check_toolchain()
fi;
done

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

clang_version=$($CLANG --version | grep -Po '(?<=clang version )[[:digit:]]+')
if [ "$?" -ne "0" ]; then
echo "*** ERROR: Couldn't execute '$CLANG --version'"
Expand Down Expand Up @@ -117,10 +120,10 @@ check_toolchain()
exit 1
fi

if [ -z "$ARCH_INCLUDES" ]; then
if [ -z "$ARCH_INCLUDES" ] && [ -n "$ARCH_NAME" ]; then
for dir in $(echo | $CC -Wp,-v -E - 2>&1 | grep '^ '); do
local idir
idir="${dir}/$(uname -m)-linux-gnu/"
idir="${dir}/${ARCH_NAME}/"
[ -d "$idir" ] && ARCH_INCLUDES="-I${idir} $ARCH_INCLUDES"
done
fi
Expand Down
4 changes: 2 additions & 2 deletions lib/defines.mk
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ endif

DEFINES += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64

CFLAGS += -std=gnu11 -Wextra -Werror $(DEFINES)
BPF_CFLAGS += $(DEFINES) $(filter -ffile-prefix-map=%,$(CFLAGS))
CFLAGS += -std=gnu11 -Wextra -Werror $(DEFINES) $(ARCH_INCLUDES)
BPF_CFLAGS += $(DEFINES) $(filter -ffile-prefix-map=%,$(CFLAGS)) $(ARCH_INCLUDES)

CONFIGMK := $(LIB_DIR)/../config.mk
LIBMK := Makefile $(CONFIGMK) $(LIB_DIR)/defines.mk $(LIB_DIR)/common.mk $(LIB_DIR)/../version.mk

0 comments on commit 6ce3063

Please sign in to comment.