diff options
author | Stephen Hines <srhines@google.com> | 2012-02-29 20:09:47 -0800 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2012-02-29 20:14:54 -0800 |
commit | ce2e754ed4b1aefe607bbbddd8ce0e6cba824e8f (patch) | |
tree | d7e6555e258fab9865ecf025430eb7b467e23e3d | |
parent | 9f4c28af2b830f6400c32d1f481e680346bbf33f (diff) | |
download | linkloader-ce2e754ed4b1aefe607bbbddd8ce0e6cba824e8f.tar.gz |
Remapping ELF section headers to match loaded code
Remap ELF headers when rsloaderCreateExec is called so the object can be registered with GDB.
Change-Id: I89de5caaee8caad5136d817698cf9fc8a5bd545b
-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 4847fe2..53cb54d 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); @@ -55,6 +56,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); |