Skip to content

Commit

Permalink
Keep DF_1_NODELETE as DT_FLAGS_1 value
Browse files Browse the repository at this point in the history
Android started supporting DF_1_NODELETE in 6.0 - older versions
can keep warning about it.
  • Loading branch information
fornwall committed Nov 4, 2017
1 parent 0bb77ad commit a2a69ef
Showing 1 changed file with 15 additions and 31 deletions.
46 changes: 15 additions & 31 deletions termux-elf-cleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,16 @@
#include "elf.h"

#define DT_VERSYM 0x6ffffff0
#define DT_FLAGS_1 0x6ffffffb
#define DT_VERNEEDED 0x6ffffffe
#define DT_VERNEEDNUM 0x6fffffff

/** As only DF_1_NOW and DF_1_GLOBAL are supported on Android,
* and DF_1_NODELETE is supported after Android 6.
* so we remove it in order to reduce openjdk-9's warnings.
*/
#define DT_FLAGS_1 0x6ffffffb

/** Copy from toolchain's elf.h */
#define DF_1_NOW 0x00000001 /* Set RTLD_NOW for this object. */
#define DF_1_GLOBAL 0x00000002 /* Set RTLD_GLOBAL for this object. */
#define DF_1_NODELETE 0x00000008 /* Set RTLD_NODELETE for this object.*/

/* Copy from android source and modified. */
#define SUPPORTED_DT_FLAGS_1 (DF_1_NOW | DF_1_GLOBAL)
// The supported DT_FLAGS_1 values as of Android 6.0.
#define SUPPORTED_DT_FLAGS_1 (DF_1_NOW | DF_1_GLOBAL | DF_1_NODELETE)

template<typename ElfHeaderType /*Elf{32,64}_Ehdr*/,
typename ElfSectionHeaderType /*Elf{32,64}_Shdr*/,
Expand Down Expand Up @@ -87,29 +81,19 @@ bool process_elf(uint8_t* bytes, size_t elf_file_size, char const* file_name)
dynamic_section_entry->d_tag = DT_NULL;
// Decrease j to process new entry index:
std::swap(dynamic_section[j--], dynamic_section[last_nonnull_entry_idx--]);

} else if (dynamic_section_entry->d_tag == DT_FLAGS_1) {
/**
* Modified by Kiva.
* Remove unsupported DF_1_FLAGS in DT_FLAGS_1 tag.
*/
if ((dynamic_section_entry->d_un.d_val & ~SUPPORTED_DT_FLAGS_1) != 0) {

decltype(dynamic_section_entry->d_un.d_val) new_d_val = 0;
if ((dynamic_section_entry->d_un.d_val & DF_1_NOW) == DF_1_NOW) {
new_d_val |= DF_1_NOW;
}
if ((dynamic_section_entry->d_un.d_val & DF_1_GLOBAL) == DF_1_GLOBAL) {
new_d_val |= DF_1_GLOBAL;
}

if (new_d_val != dynamic_section_entry->d_un.d_val) {
printf("termux-elf-cleaner: Replacing the unsupported DF_1_FLAGS %p with %p from '%s'\n",
dynamic_section_entry->d_un.d_val, new_d_val, file_name);

dynamic_section_entry->d_un.d_val = new_d_val;
}
}
// Remove unsupported DF_1_* flags to avoid linker warnings.
decltype(dynamic_section_entry->d_un.d_val) orig_d_val =
dynamic_section_entry->d_un.d_val;
decltype(dynamic_section_entry->d_un.d_val) new_d_val =
(orig_d_val & SUPPORTED_DT_FLAGS_1);
if (new_d_val != orig_d_val) {
printf("termux-elf-cleaner: Replacing unsupported DF_1_* flags %llu with %llu in '%s'\n",
(unsigned long long) orig_d_val,
(unsigned long long) new_d_val,
file_name);
dynamic_section_entry->d_un.d_val = new_d_val;
}
}
}
} else if (section_header_entry->sh_type == SHT_GNU_verdef ||
Expand Down

0 comments on commit a2a69ef

Please sign in to comment.