Commit 0b131db4 authored by Denis Solonkov's avatar Denis Solonkov Committed by Commit Bot

Collection of minor tweaks and changes.

This CL:
  1) Sets constructor priority to 0, instead of 100 to ensure that it
    is loaded first.
  2) Adds TODO to look into dl_iterate_phdr instead of magic array.
  3) Removed ifndef clang since DoNotOptimize is not clang specific.
  4) Fixes the phdr sorting order to comply with the standard.

Bug: 998082
Change-Id: Id9967f2b8cc004be5284153da45f46e479908e9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1829203
Commit-Queue: Denis Solonkov <solonkovda@google.com>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarAlex Ilin <alexilin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700805}
parent 0a789076
...@@ -30,11 +30,6 @@ extern char __ehdr_start; ...@@ -30,11 +30,6 @@ extern char __ehdr_start;
// This function can be used to prevent a value or expression from being // This function can be used to prevent a value or expression from being
// optimized away by the compiler. // optimized away by the compiler.
//
// This method is clang specific, hence the #error
#ifndef __clang__
#error "DoNotOptimize is clang specific method"
#endif
void DoNotOptimize(void* value) { void DoNotOptimize(void* value) {
__asm__ volatile("" : : "r,m"(value) : "memory"); __asm__ volatile("" : : "r,m"(value) : "memory");
} }
...@@ -44,6 +39,9 @@ void DoNotOptimize(void* value) { ...@@ -44,6 +39,9 @@ void DoNotOptimize(void* value) {
// in the library file. DoNotOptimize method is applied to them at the // in the library file. DoNotOptimize method is applied to them at the
// beginning of the decompression hook to ensure that the arrays are not // beginning of the decompression hook to ensure that the arrays are not
// optimized away. // optimized away.
//
// TODO(https://crbug.com/998082): Check if dl_iterate_phdr can replace the
// magic bytes approach.
unsigned char g_dummy_cut_range_begin[8] = {0x2e, 0x2a, 0xee, 0xf6, unsigned char g_dummy_cut_range_begin[8] = {0x2e, 0x2a, 0xee, 0xf6,
0x45, 0x03, 0xd2, 0x50}; 0x45, 0x03, 0xd2, 0x50};
unsigned char g_dummy_cut_range_end[8] = {0x52, 0x40, 0xeb, 0x9d, unsigned char g_dummy_cut_range_end[8] = {0x52, 0x40, 0xeb, 0x9d,
...@@ -291,9 +289,11 @@ void* ConvertDummyArrayToAddress(void* dummy_array) { ...@@ -291,9 +289,11 @@ void* ConvertDummyArrayToAddress(void* dummy_array) {
return (void*)value; return (void*)value;
} }
void __attribute__((constructor(100))) InitLibraryDecompressor() { void __attribute__((constructor(0))) InitLibraryDecompressor() {
// The constructor only works on 64 bit systems and as such expecting the // The constructor only works on 64 bit systems and as such expecting the
// pointer size to be 8 bytes. // pointer size to be 8 bytes.
// The constructor priority is set to 0(the highest) to ensure that it starts
// as a first constructor.
_Static_assert(sizeof(uint64_t) == sizeof(uintptr_t), _Static_assert(sizeof(uint64_t) == sizeof(uintptr_t),
"Pointer size is not 8 bytes"); "Pointer size is not 8 bytes");
......
...@@ -416,11 +416,17 @@ class ElfHeader(ElfEntry): ...@@ -416,11 +416,17 @@ class ElfHeader(ElfEntry):
"""Orders program LOAD headers by p_vaddr to comply with standard.""" """Orders program LOAD headers by p_vaddr to comply with standard."""
def HeaderToKey(phdr): def HeaderToKey(phdr):
if phdr.p_type == ProgramHeader.Type.PT_LOAD: # ELF standard required PT_INTERP and PT_PHDR to be strictly before
# PT_LOAD.
if phdr.p_type == ProgramHeader.Type.PT_INTERP:
return (0, phdr.p_vaddr) return (0, phdr.p_vaddr)
elif phdr.p_type == ProgramHeader.Type.PT_PHDR:
return (1, phdr.p_vaddr)
elif phdr.p_type == ProgramHeader.Type.PT_LOAD:
return (2, phdr.p_vaddr)
else: else:
# We want to preserve the order of non LOAD segments. # We want to preserve the order of non LOAD segments.
return (1, 0) return (3, 0)
self.phdrs.sort(key=HeaderToKey) self.phdrs.sort(key=HeaderToKey)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment