From 2497d95791cbc8bedfae1d286f4d523ba826633a Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Sat, 24 Sep 2016 19:30:20 -0400 Subject: [PATCH] Strip libc.so before linking against it This avoids creating unwanted sections in the built ELF files that causes issues when removed. Fixes #412. --- build-package.sh | 10 ++++++++-- packages/ncurses/build.sh | 1 + packages/termux-elf-cleaner/build.sh | 2 +- packages/termux-elf-cleaner/termux-elf-cleaner.cpp | 7 +++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/build-package.sh b/build-package.sh index 1aec16ca3..9d1c8df5f 100755 --- a/build-package.sh +++ b/build-package.sh @@ -397,7 +397,7 @@ termux_step_massage () { # 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 @@ -647,20 +647,26 @@ if [ ! -d $TERMUX_STANDALONE_TOOLCHAIN ]; then --api $TERMUX_API_LEVEL \ --arch $_NDK_ARCHNAME \ --install-dir $_TERMUX_TOOLCHAIN_TMPDIR + if [ "arm" = $TERMUX_ARCH ]; then # Fix to allow e.g. 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 + 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 + + $TERMUX_ELF_CLEANER usr/lib/libc.so + mv $_TERMUX_TOOLCHAIN_TMPDIR $TERMUX_STANDALONE_TOOLCHAIN fi diff --git a/packages/ncurses/build.sh b/packages/ncurses/build.sh index 4e1688856..5dab58a66 100755 --- a/packages/ncurses/build.sh +++ b/packages/ncurses/build.sh @@ -5,6 +5,7 @@ _MAJOR_VERSION=6.0 # 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" diff --git a/packages/termux-elf-cleaner/build.sh b/packages/termux-elf-cleaner/build.sh index f97fb0c40..ec65d3bc9 100644 --- a/packages/termux-elf-cleaner/build.sh +++ b/packages/termux-elf-cleaner/build.sh @@ -1,6 +1,6 @@ TERMUX_PKG_HOMEPAGE=https://termux.com/ TERMUX_PKG_DESCRIPTION="Cleaner of ELF files for Android" -TERMUX_PKG_VERSION=1.0 +TERMUX_PKG_VERSION=1.1 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 diff --git a/packages/termux-elf-cleaner/termux-elf-cleaner.cpp b/packages/termux-elf-cleaner/termux-elf-cleaner.cpp index 83a4e4051..e34c3225e 100644 --- a/packages/termux-elf-cleaner/termux-elf-cleaner.cpp +++ b/packages/termux-elf-cleaner/termux-elf-cleaner.cpp @@ -14,6 +14,7 @@ # include #endif +#define DT_VERSYM 0x6ffffff0 #define DT_VERNEEDED 0x6ffffffe #define DT_VERNEEDNUM 0x6fffffff @@ -61,6 +62,7 @@ bool process_elf(uint8_t* bytes, size_t elf_file_size, char const* file_name) 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; @@ -76,6 +78,11 @@ bool process_elf(uint8_t* bytes, size_t elf_file_size, char const* file_name) 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; } } return true;