This avoids creating unwanted sections in the built ELF files that
causes issues when removed.
Fixes #412.
# Strip binaries. file(1) may fail for certain unusual files, so disable pipefail.
set +e +o pipefail
find . -type f | xargs -r file | grep -E "(executable|shared object)" | grep ELF | cut -f 1 -d : | \
# Strip binaries. file(1) may fail for certain unusual files, so disable pipefail.
set +e +o pipefail
find . -type f | xargs -r file | grep -E "(executable|shared object)" | grep ELF | cut -f 1 -d : | \
- xargs -r $STRIP --strip-unneeded --preserve-dates -R '.gnu.version*'
+ xargs -r $STRIP --strip-unneeded --preserve-dates
set -e -o pipefail
# Remove DT_ entries which the android 5.1 linker warns about:
find . -type f -print0 | xargs -r -0 $TERMUX_ELF_CLEANER
set -e -o pipefail
# Remove DT_ entries which the android 5.1 linker warns about:
find . -type f -print0 | xargs -r -0 $TERMUX_ELF_CLEANER
--api $TERMUX_API_LEVEL \
--arch $_NDK_ARCHNAME \
--install-dir $_TERMUX_TOOLCHAIN_TMPDIR
--api $TERMUX_API_LEVEL \
--arch $_NDK_ARCHNAME \
--install-dir $_TERMUX_TOOLCHAIN_TMPDIR
if [ "arm" = $TERMUX_ARCH ]; then
# Fix to allow e.g. <bits/c++config.h> to be included:
cp $_TERMUX_TOOLCHAIN_TMPDIR/include/c++/4.9.x/arm-linux-androideabi/armv7-a/bits/* \
$_TERMUX_TOOLCHAIN_TMPDIR/include/c++/4.9.x/bits
fi
if [ "arm" = $TERMUX_ARCH ]; then
# Fix to allow e.g. <bits/c++config.h> to be included:
cp $_TERMUX_TOOLCHAIN_TMPDIR/include/c++/4.9.x/arm-linux-androideabi/armv7-a/bits/* \
$_TERMUX_TOOLCHAIN_TMPDIR/include/c++/4.9.x/bits
fi
cd $_TERMUX_TOOLCHAIN_TMPDIR/sysroot
cd $_TERMUX_TOOLCHAIN_TMPDIR/sysroot
for f in $TERMUX_SCRIPTDIR/ndk_patches/*.patch; do
sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" $f | \
sed "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" | \
patch --silent -p1;
done
for f in $TERMUX_SCRIPTDIR/ndk_patches/*.patch; do
sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" $f | \
sed "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" | \
patch --silent -p1;
done
- # elf.h is taken from glibc since the elf.h in the NDK is lacking.
+ # elf.h is taken from glibc since the elf.h in the NDK is lacking.
# sysexits.h is header-only and used by a few programs.
cp $TERMUX_SCRIPTDIR/ndk_patches/{elf.h,sysexits.h} $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/include
# sysexits.h is header-only and used by a few programs.
cp $TERMUX_SCRIPTDIR/ndk_patches/{elf.h,sysexits.h} $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/include
+
+ $TERMUX_ELF_CLEANER usr/lib/libc.so
+
mv $_TERMUX_TOOLCHAIN_TMPDIR $TERMUX_STANDALONE_TOOLCHAIN
fi
mv $_TERMUX_TOOLCHAIN_TMPDIR $TERMUX_STANDALONE_TOOLCHAIN
fi
# in termux_step_post_extract_package below:
_MINOR_VERSION=20160910
TERMUX_PKG_VERSION=${_MAJOR_VERSION}.${_MINOR_VERSION}
# in termux_step_post_extract_package below:
_MINOR_VERSION=20160910
TERMUX_PKG_VERSION=${_MAJOR_VERSION}.${_MINOR_VERSION}
+TERMUX_PKG_BUILD_REVISION=1
TERMUX_PKG_SRCURL=https://mirrors.kernel.org/gnu/ncurses/ncurses-${_MAJOR_VERSION}.tar.gz
# --without-normal disables static libraries:
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="--enable-overwrite --enable-const --without-cxx-binding --without-normal --without-static --with-shared --without-debug --enable-widec --enable-ext-colors --enable-ext-mouse --enable-pc-files --with-pkg-config-libdir=$PKG_CONFIG_LIBDIR --without-ada --without-tests --mandir=$TERMUX_PREFIX/share/man ac_cv_header_locale_h=no"
TERMUX_PKG_SRCURL=https://mirrors.kernel.org/gnu/ncurses/ncurses-${_MAJOR_VERSION}.tar.gz
# --without-normal disables static libraries:
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="--enable-overwrite --enable-const --without-cxx-binding --without-normal --without-static --with-shared --without-debug --enable-widec --enable-ext-colors --enable-ext-mouse --enable-pc-files --with-pkg-config-libdir=$PKG_CONFIG_LIBDIR --without-ada --without-tests --mandir=$TERMUX_PREFIX/share/man ac_cv_header_locale_h=no"
TERMUX_PKG_HOMEPAGE=https://termux.com/
TERMUX_PKG_DESCRIPTION="Cleaner of ELF files for Android"
TERMUX_PKG_HOMEPAGE=https://termux.com/
TERMUX_PKG_DESCRIPTION="Cleaner of ELF files for Android"
termux_step_make_install () {
$CXX $CFLAGS $LDFLAGS -std=c++14 -Wall -Wextra -pedantic -Werror $TERMUX_PKG_BUILDER_DIR/*.cpp -o $TERMUX_PREFIX/bin/termux-elf-cleaner
termux_step_make_install () {
$CXX $CFLAGS $LDFLAGS -std=c++14 -Wall -Wextra -pedantic -Werror $TERMUX_PKG_BUILDER_DIR/*.cpp -o $TERMUX_PREFIX/bin/termux-elf-cleaner
+#define DT_VERSYM 0x6ffffff0
#define DT_VERNEEDED 0x6ffffffe
#define DT_VERNEEDNUM 0x6fffffff
#define DT_VERNEEDED 0x6ffffffe
#define DT_VERNEEDNUM 0x6fffffff
ElfDynamicSectionEntryType* dynamic_section_entry = dynamic_section + j;
char const* removed_name = nullptr;
switch (dynamic_section_entry->d_tag) {
ElfDynamicSectionEntryType* dynamic_section_entry = dynamic_section + j;
char const* removed_name = nullptr;
switch (dynamic_section_entry->d_tag) {
+ case DT_VERSYM: removed_name = "DT_VERSYM"; break;
case DT_VERNEEDED: removed_name = "DT_VERNEEDED"; break;
case DT_VERNEEDNUM: removed_name = "DT_VERNEEDNUM"; break;
case DT_VERDEF: removed_name = "DT_VERDEF"; break;
case DT_VERNEEDED: removed_name = "DT_VERNEEDED"; break;
case DT_VERNEEDNUM: removed_name = "DT_VERNEEDNUM"; break;
case DT_VERDEF: removed_name = "DT_VERDEF"; break;
std::swap(dynamic_section[j--], dynamic_section[last_nonnull_entry_idx--]);
}
}
std::swap(dynamic_section[j--], dynamic_section[last_nonnull_entry_idx--]);
}
}
+ } else if (section_header_entry->sh_type == SHT_GNU_verdef ||
+ section_header_entry->sh_type == SHT_GNU_verneed ||
+ section_header_entry->sh_type == SHT_GNU_versym) {
+ printf("termux-elf-cleaner: Removing version section from '%s'\n", file_name);
+ section_header_entry->sh_type = SHN_UNDEF;