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

Cannot BUILD with NDK R17B (Latest) #4

Open
eakteam opened this issue Jul 18, 2018 · 2 comments
Open

Cannot BUILD with NDK R17B (Latest) #4

eakteam opened this issue Jul 18, 2018 · 2 comments

Comments

@eakteam
Copy link

eakteam commented Jul 18, 2018

Update tcpdump_ver=4.9.2 and libpcap_ver=1.8.1

First issue :

Refusing to clobber existing install directory: toolchain.

make-standalone-toolchain.sh used to install a new toolchain into an existing
directory. This is not desirable, as it will not clean up any stale files. If
you wish to remove the install directory before creation, pass --force.
 _______
|       |
| ERROR |
|_______|

After passing --force to :

bash ${ndk_dir}/build/tools/make-standalone-toolchain.sh --force --toolchain=${toolchain} --platform=android-${android_api} --install-dir=toolchain

it create toolchain successfully , but cannot compile :

#
# Older programs import this if they want to show the
# libpcap version number, rather than calling
# pcap_lib_version(), so we need to export it.
#
./gen_version_c.sh ./VERSION version.c
arm-linux-androideabi-gcc -fvisibility=hidden -fpic -fPIE -pie -I.  -DBUILDING_PCAP -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -fPIE -pie    -c version.c
arm-linux-androideabi-ar rc libpcap.a pcap-linux.o pcap-usb-linux.o pcap-netfilter-linux.o fad-gifc.o pcap.o inet.o fad-helpers.o gencode.o optimize.o nametoaddr.o etherent.o savefile.o sf-pcap.o sf-pcap-ng.o pcap-common.o bpf_image.o bpf_dump.o  scanner.o grammar.o bpf_filter.o version.o
arm-linux-androideabi-ranlib libpcap.a
VER=`cat ./VERSION`; \
        MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' ./VERSION`; \
        arm-linux-androideabi-gcc -shared -Wl,-soname,libpcap.so.$MAJOR_VER  \
            -o libpcap.so.$VER pcap-linux.o pcap-usb-linux.o pcap-netfilter-linux.o fad-gifc.o pcap.o inet.o fad-helpers.o gencode.o optimize.o nametoaddr.o etherent.o savefile.o sf-pcap.o sf-pcap-ng.o pcap-common.o bpf_image.o bpf_dump.o  scanner.o grammar.o bpf_filter.o version.o
/home/eakteam/tcpdumpbuild/toolchain/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: nametoaddr.o: requires unsupported dynamic reloc R_ARM_REL32; recompile with -fPIC
collect2: error: ld returned 1 exit status
make: *** [libpcap.so] Error 1
 _______
|       |
| ERROR |
|_______|

Tried to pass -fPIC to CFLAGS : export CFLAGS="-fPIC -fPIE -pie"
Tried with older tcpdump and libpcap too and it still failed with latest NDK

@eakteam
Copy link
Author

eakteam commented Jul 18, 2018

WORKING EXAMPLE FOR armeabi-v7a :

#!/bin/bash

# --------------------------------------
#
#     Title: build-tcpdump
#    Author: Loic Poulain, [email protected]
#
#   Purpose: download & build tcpdump for arm android platform
#
# You have to define your android NDK directory before calling this script
# example:
# $ export NDK=/home/Workspace/android-ndk-r10e
# $ sh build-tcpdump
#
# --------------------------------------

# default, edit versions
tcpdump_ver=4.9.2
libpcap_ver=1.8.1
android_api_def=16
toolchain=arm-linux-androideabi-4.9
ndk_dir_def=/home/eakteam/ndk-r17b

#-------------------------------------------------------#

tcpdump_dir=tcpdump-${tcpdump_ver}
libpcap_dir=libpcap-${libpcap_ver}


if [ ${NDK} ]
then
	ndk_dir=${NDK}
else
	ndk_dir=${ndk_dir_def}
fi

ndk_dir=`readlink -f ${ndk_dir}`

if [ ${ANDROID_API} ]
then
	android_api=${ANDROID_API}
else
	android_api=${android_api_def}
fi

echo "_______________________"
echo ""
echo "NDK - ${ndk_dir}"
echo "Android API: ${android_api}"
echo "_______________________"


exit_error()
{
	echo " _______"
	echo "|       |"
	echo "| ERROR |"
	echo "|_______|"
	exit 1
}

{
	if [ $# -ne 0 ]
	then
		if [ -d $1 ]
		then
			cd $1
		else
			echo directory $1 not found
			exit_error
		fi
	else
		mkdir tcpdumpbuild
		cd tcpdumpbuild
	fi
}



# create env
{
	echo " ____________________"
	echo "|                    |"
	echo "| CREATING TOOLCHAIN |"
	echo "|____________________|"

	if [ -d toolchain ]
	then
		echo Toolchain already exist! Nothing to do.
	else
		echo Creating toolchain...
		mkdir toolchain
		bash ${ndk_dir}/build/tools/make-standalone-toolchain.sh --force --toolchain=${toolchain} --platform=android-${android_api} --install-dir=toolchain
		
		if [ $? -ne 0 ]
		then
			rm -fr toolchain
			exit_error
		fi
	fi
	
	export PATH=`pwd`/toolchain/bin:$PATH

	target_host=arm-linux-androideabi
    export AR=$target_host-ar
    export AS=$target_host-clang
    export CC=$target_host-clang
    export CXX=$target_host-clang++
    export LD=$target_host-ld
    export STRIP=$target_host-strip
	export RANLIB=$target_host-ranlib
	export STRIP=$target_host-strip
	export CFLAGS="-static -O2 -fPIE -fPIC -march=armv7-a -mthumb -mfloat-abi=softfp -mfpu=vfpv3-d16 -mfpu=neon -march=armv7-a -Wl,--fix-cortex-a8"
    export LDFLAGS="-pie"
}

# download & untar libpcap + tcpdump
{
	echo " _______________________________"
	echo "|                               |"
	echo "| DOWNLOADING LIBPCAP & TCPDUMP |"
	echo "|_______________________________|"
	
	tcpdump_file=${tcpdump_dir}.tar.gz
	libpcap_file=${libpcap_dir}.tar.gz
	tcpdump_link=http://www.tcpdump.org/release/${tcpdump_file}
	libpcap_link=http://www.tcpdump.org/release/${libpcap_file}
	
	if [ -f ${tcpdump_file} ]
	then
		echo ${tcpdump_file} already downloaded! Nothing to do.
	else
		echo Download ${tcpdump_file}...
		wget ${tcpdump_link}
		wget ${tcpdump_link}.sig
		if [ ! -f ${tcpdump_file} ]
		then
			exit_error
		fi
	fi

	gpg --verify ${tcpdump_file}.sig
	if [ $? -ne 0 ]
	then
		exit_error
	fi

	
	if [ -f ${libpcap_file} ]
	then
		echo ${libpcap_file} already downloaded! Nothing to do.
	else
		echo Download ${libpcap_file}...
		wget ${libpcap_link}
		wget ${libpcap_link}.sig
		if [ ! -f ${libpcap_file} ]
		then
			exit_error
		fi
	fi

	gpg --verify ${libpcap_file}.sig
	if [ $? -ne 0 ]
	then
		exit_error
	fi

	
	if [ -d ${tcpdump_dir} ]
	then
		echo ${tcpdump_dir} directory already exist! Nothing to do.
	else
		echo untar ${tcpdump_file}
		tar -zxf ${tcpdump_file}
	fi
	
	if [ -d ${libpcap_dir} ]
	then
		echo ${libpcap_dir} directory already exist! Nothing to do.
	else
		echo untar ${libpcap_file}
		tar -zxf ${libpcap_file}
	fi
}

# build libpcap
{
	cd ${libpcap_dir}

	echo " _____________________"
	echo "|                     |"
	echo "| CONFIGURING LIBPCAP |"
	echo "|_____________________|"
	
	chmod +x configure
	./configure --host=arm-linux-androideabi --with-pcap=linux

	if [ $? -ne 0 ]
	then
		exit_error
	fi	

	echo " __________________"
	echo "|                  |"
	echo "| BUILDING LIBPCAP |"
	echo "|__________________|"

	chmod +x runlex.sh
	make

	if [ $? -ne 0 ]
	then
		exit_error
	fi

	cd ..
}

# build tcpdump
{
	cd ${tcpdump_dir}
	
	echo " _____________________"
	echo "|                     |"
	echo "| CONFIGURING TCPDUMP |"
	echo "|_____________________|"
	
	#target_host=arm-linux-androideabi
    #export AR=$target_host-ar
    #export AS=$target_host-clang
    #export CC=$target_host-clang
    #export CXX=$target_host-clang++
    #export LD=$target_host-ld
    #export STRIP=$target_host-strip
	#export RANLIB=$target_host-ranlib
	#export STRIP=$target_host-strip
	#export CFLAGS="-static -O2 -fPIC -fPIE -march=armv7-a -mthumb -mfloat-abi=softfp -mfpu=vfpv3-d16 -mfpu=neon -march=armv7-a -Wl,--fix-cortex-a8"
    #export LDFLAGS="-pie"
	
	chmod +x configure
	./configure --host=arm-linux-androideabi --with-pcap=linux

	if [ $? -ne 0 ]
	then
		exit_error
	fi	

	echo " __________________"
	echo "|                  |"
	echo "| BUILDING TCPDUMP |"
	echo "|__________________|"
	
	#setprotoent endprotoen not supported on android
	sed -i".bak" "s/setprotoent/\/\/setprotoent/g" print-isakmp.c
	sed -i".bak" "s/endprotoent/\/\/endprotoent/g" print-isakmp.c

	#NBBY is not defined => FORCE definition
	make #CFLAGS=-DNBBY=8 # for tcpdump < 4.2.1 (CFLAGS refefined in Makefile) => just make
	
	if [ $? -ne 0 ]
	then
		exit_error
	fi
	
	cd ..
}

cp ${tcpdump_dir}/tcpdump .
chmod +x tcpdump

echo " __________________"
echo "|                  |"
echo "| TCPDUMP IS READY |"
echo "|__________________|"
echo `pwd`/tcpdump

WORKING EXAMPLE FOR x86 :

#!/bin/bash

# --------------------------------------
#
#     Title: build-tcpdump
#    Author: Loic Poulain, [email protected]
#
#   Purpose: download & build tcpdump for arm android platform
#
# You have to define your android NDK directory before calling this script
# example:
# $ export NDK=/home/Workspace/android-ndk-r10e
# $ sh build-tcpdump
#
# --------------------------------------

# default, edit versions
tcpdump_ver=4.9.2
libpcap_ver=1.8.1
android_api_def=16
toolchain=x86-4.9
ndk_dir_def=/home/eakteam/ndk-r17b

#-------------------------------------------------------#

tcpdump_dir=tcpdump-${tcpdump_ver}
libpcap_dir=libpcap-${libpcap_ver}


if [ ${NDK} ]
then
	ndk_dir=${NDK}
else
	ndk_dir=${ndk_dir_def}
fi

ndk_dir=`readlink -f ${ndk_dir}`

if [ ${ANDROID_API} ]
then
	android_api=${ANDROID_API}
else
	android_api=${android_api_def}
fi

echo "_______________________"
echo ""
echo "NDK - ${ndk_dir}"
echo "Android API: ${android_api}"
echo "_______________________"


exit_error()
{
	echo " _______"
	echo "|       |"
	echo "| ERROR |"
	echo "|_______|"
	exit 1
}

{
	if [ $# -ne 0 ]
	then
		if [ -d $1 ]
		then
			cd $1
		else
			echo directory $1 not found
			exit_error
		fi
	else
		mkdir tcpdumpbuild
		cd tcpdumpbuild
	fi
}



# create env
{
	echo " ____________________"
	echo "|                    |"
	echo "| CREATING TOOLCHAIN |"
	echo "|____________________|"

	if [ -d toolchain ]
	then
		echo Toolchain already exist! Nothing to do.
	else
		echo Creating toolchain...
		mkdir toolchain
		bash ${ndk_dir}/build/tools/make-standalone-toolchain.sh --force --toolchain=${toolchain} --platform=android-${android_api} --install-dir=toolchain
		
		if [ $? -ne 0 ]
		then
			rm -fr toolchain
			exit_error
		fi
	fi
	
	export PATH=`pwd`/toolchain/bin:$PATH

	target_host=i686-linux-android
    export AR=$target_host-ar
    export AS=$target_host-clang
    export CC=$target_host-clang
    export CXX=$target_host-clang++
    export LD=$target_host-ld
    export STRIP=$target_host-strip
	export RANLIB=$target_host-ranlib
	export STRIP=$target_host-strip
	export CFLAGS="-static -O2 -fPIE -fPIC -mthumb -mfloat-abi=softfp -Wl,--fix-cortex-a8"
    export LDFLAGS="-pie"
}

# download & untar libpcap + tcpdump
{
	echo " _______________________________"
	echo "|                               |"
	echo "| DOWNLOADING LIBPCAP & TCPDUMP |"
	echo "|_______________________________|"
	
	tcpdump_file=${tcpdump_dir}.tar.gz
	libpcap_file=${libpcap_dir}.tar.gz
	tcpdump_link=http://www.tcpdump.org/release/${tcpdump_file}
	libpcap_link=http://www.tcpdump.org/release/${libpcap_file}
	
	if [ -f ${tcpdump_file} ]
	then
		echo ${tcpdump_file} already downloaded! Nothing to do.
	else
		echo Download ${tcpdump_file}...
		wget ${tcpdump_link}
		wget ${tcpdump_link}.sig
		if [ ! -f ${tcpdump_file} ]
		then
			exit_error
		fi
	fi

	gpg --verify ${tcpdump_file}.sig
	if [ $? -ne 0 ]
	then
		exit_error
	fi

	
	if [ -f ${libpcap_file} ]
	then
		echo ${libpcap_file} already downloaded! Nothing to do.
	else
		echo Download ${libpcap_file}...
		wget ${libpcap_link}
		wget ${libpcap_link}.sig
		if [ ! -f ${libpcap_file} ]
		then
			exit_error
		fi
	fi

	gpg --verify ${libpcap_file}.sig
	if [ $? -ne 0 ]
	then
		exit_error
	fi

	
	if [ -d ${tcpdump_dir} ]
	then
		echo ${tcpdump_dir} directory already exist! Nothing to do.
	else
		echo untar ${tcpdump_file}
		tar -zxf ${tcpdump_file}
	fi
	
	if [ -d ${libpcap_dir} ]
	then
		echo ${libpcap_dir} directory already exist! Nothing to do.
	else
		echo untar ${libpcap_file}
		tar -zxf ${libpcap_file}
	fi
}

# build libpcap
{
	cd ${libpcap_dir}

	echo " _____________________"
	echo "|                     |"
	echo "| CONFIGURING LIBPCAP |"
	echo "|_____________________|"
	
	chmod +x configure
	./configure --host=i686-linux-android --with-pcap=linux

	if [ $? -ne 0 ]
	then
		exit_error
	fi	

	echo " __________________"
	echo "|                  |"
	echo "| BUILDING LIBPCAP |"
	echo "|__________________|"

	chmod +x runlex.sh
	make

	if [ $? -ne 0 ]
	then
		exit_error
	fi

	cd ..
}

# build tcpdump
{
	cd ${tcpdump_dir}
	
	echo " _____________________"
	echo "|                     |"
	echo "| CONFIGURING TCPDUMP |"
	echo "|_____________________|"
		
	chmod +x configure
	./configure --host=i686-linux-android --with-pcap=linux

	if [ $? -ne 0 ]
	then
		exit_error
	fi	

	echo " __________________"
	echo "|                  |"
	echo "| BUILDING TCPDUMP |"
	echo "|__________________|"
	
	#setprotoent endprotoen not supported on android
	sed -i".bak" "s/setprotoent/\/\/setprotoent/g" print-isakmp.c
	sed -i".bak" "s/endprotoent/\/\/endprotoent/g" print-isakmp.c

	#NBBY is not defined => FORCE definition
	make #CFLAGS=-DNBBY=8 # for tcpdump < 4.2.1 (CFLAGS refefined in Makefile) => just make
	
	if [ $? -ne 0 ]
	then
		exit_error
	fi
	
	cd ..
}

cp ${tcpdump_dir}/tcpdump .
chmod +x tcpdump

echo " __________________"
echo "|                  |"
echo "| TCPDUMP IS READY |"
echo "|__________________|"
echo `pwd`/tcpdump

@oHeHeHou
Copy link

@eakteam You can try to change "--install-dir=toolchain" to "--install-dir=toolchain_x86" in the CREATING TOOLCHAIN section

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants