Skip to content

Commit

Permalink
support for Android 7
Browse files Browse the repository at this point in the history
Remove DT_VERSYM, DT_VERNEEDED, DT_VERNEEDNUM, DT_VERDEF,
DT_VERDEFNUM only on Android 5.

Keep DT_RUNPATH on Android 7 and higher.
  • Loading branch information
Leonid Plyushch committed Feb 24, 2019
1 parent a2a69ef commit 623f314
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions termux-elf-cleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include <sys/types.h>
#include <unistd.h>

#ifndef __ANDROID_API__
#define __ANDROID_API__ 21
#endif

// Include a local elf.h copy as not all platforms have it.
#include "elf.h"

Expand Down Expand Up @@ -67,13 +71,17 @@ 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) {
#if __ANDROID_API__ < 23
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_VERDEFNUM: removed_name = "DT_VERDEFNUM"; break;
#endif
case DT_RPATH: removed_name = "DT_RPATH"; break;
#if __ANDROID_API__ < 24
case DT_RUNPATH: removed_name = "DT_RUNPATH"; break;
#endif
}
if (removed_name != nullptr) {
printf("termux-elf-cleaner: Removing the %s dynamic section entry from '%s'\n", removed_name, file_name);
Expand Down Expand Up @@ -111,8 +119,9 @@ int main(int argc, char const** argv)
{
if (argc < 2 || (argc == 2 && strcmp(argv[1], "-h")==0)) {
fprintf(stderr, "usage: %s <filenames>\n", argv[0]);
fprintf(stderr, "\nProcesses ELF files to remove unsupported section types \n"
"and dynamic section entries which the Android linker warns about.\n");
fprintf(stderr, "\nProcesses ELF files to remove unsupported section types\n"
"and dynamic section entries which the Android linker (API %d)\nwarns about.\n",
__ANDROID_API__);
return 1;
}

Expand Down Expand Up @@ -169,4 +178,3 @@ int main(int argc, char const** argv)
}
return 0;
}

0 comments on commit 623f314

Please sign in to comment.