Strip libc.so before linking against it
authorFredrik Fornwall <fredrik@fornwall.net>
Sat, 24 Sep 2016 23:30:20 +0000 (19:30 -0400)
committerFredrik Fornwall <fredrik@fornwall.net>
Sat, 24 Sep 2016 23:30:20 +0000 (19:30 -0400)
This avoids creating unwanted sections in the built ELF files that
causes issues when removed.

Fixes #412.

build-package.sh
packages/ncurses/build.sh
packages/termux-elf-cleaner/build.sh
packages/termux-elf-cleaner/termux-elf-cleaner.cpp

index 1aec16c..9d1c8df 100755 (executable)
@@ -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. <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
+
        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
 
index 4e16888..5dab58a 100755 (executable)
@@ -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"
index f97fb0c..ec65d3b 100644 (file)
@@ -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
index 83a4e40..e34c322 100644 (file)
@@ -14,6 +14,7 @@
 # include <elf.h>
 #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;