diff options
author | Stephen Hines <srhines@google.com> | 2012-03-01 23:57:05 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2012-03-01 23:57:05 -0800 |
commit | 141f4435692cc53db032525e1cc602c3b417c42e (patch) | |
tree | 630d5b9b303ec5ad2f33d14fbe65a9f1133d5077 | |
parent | 083a92e47019d49aa96fff68811e5490526b5024 (diff) | |
parent | c9035479f5740de231117ea47d3a6e9b477b173d (diff) | |
download | linkloader-141f4435692cc53db032525e1cc602c3b417c42e.tar.gz |
am c9035479: Merge "Remapping ELF section headers to match loaded code"
* commit 'c9035479f5740de231117ea47d3a6e9b477b173d':
Remapping ELF section headers to match loaded code
-rw-r--r-- | android/librsloader.cpp | 25 | ||||
-rw-r--r-- | android/librsloader.h | 4 |
2 files changed, 27 insertions, 2 deletions
diff --git a/android/librsloader.cpp b/android/librsloader.cpp index 4128d24..1af18f7 100644 --- a/android/librsloader.cpp +++ b/android/librsloader.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011, The Android Open Source Project + * Copyright 2011-2012, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ #include "cutils/log.h" #include <llvm/ADT/OwningPtr.h> +#include <llvm/Support/ELF.h> static inline RSExecRef wrap(ELFObject<32> *object) { return reinterpret_cast<RSExecRef>(object); @@ -58,6 +59,28 @@ rsloaderCreateExec(unsigned char const *buf, return wrap(object.take()); } +extern "C" void rsloaderUpdateSectionHeaders(RSExecRef object_, + unsigned char *buf) { + ELFObject<32> *object = unwrap(object_); + + // Remap the section header addresses to match the loaded code + llvm::ELF::Elf32_Ehdr* header = reinterpret_cast<llvm::ELF::Elf32_Ehdr*>(buf); + + llvm::ELF::Elf32_Shdr* shtab = + reinterpret_cast<llvm::ELF::Elf32_Shdr*>(buf + header->e_shoff); + + for (int i = 0; i < header->e_shnum; i++) { + if (shtab[i].sh_flags & SHF_ALLOC) { + ELFSectionBits<32>* bits = + static_cast<ELFSectionBits<32>*>(object->getSectionByIndex(i)); + if (bits) { + const unsigned char* addr = bits->getBuffer(); + shtab[i].sh_addr = reinterpret_cast<llvm::ELF::Elf32_Addr>(addr); + } + } + } +} + extern "C" void rsloaderDisposeExec(RSExecRef object) { delete unwrap(object); } diff --git a/android/librsloader.h b/android/librsloader.h index 8f0429d..e12fe63 100644 --- a/android/librsloader.h +++ b/android/librsloader.h @@ -1,5 +1,5 @@ /* - * Copyright 2011, The Android Open Source Project + * Copyright 2011-2012, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,8 @@ RSExecRef rsloaderCreateExec(unsigned char const *buf, void *(*find_symbol)(void *, char const *), void *find_symbol_context); +void rsloaderUpdateSectionHeaders(RSExecRef object, unsigned char *buf); + void rsloaderDisposeExec(RSExecRef object); void *rsloaderGetSymbolAddress(RSExecRef object, char const *name); |