Remove linkloader from frameworks/rs.

Bug: 18322681

Now that we have switched completely to the new shared library object
loading path, we can safely remove the legacy linkloader path.

In frameworks/rs, this removes the actual linkloader code, as well as
all helper calls into linkloader. This change also coalesces code paths
between the support library version of RS and the native version of RS,
since they both now depend on a similar shared library loader. A missing
call to dlclose() on Script teardown is also added on the native library
path.

Change-Id: Ie5cc152d93f5e75383f7c21a4523579cfae8823f
diff --git a/Android.mk b/Android.mk
index 36f9730..723d1da 100644
--- a/Android.mk
+++ b/Android.mk
@@ -55,7 +55,6 @@
 LOCAL_SHARED_LIBRARIES += libbcc libbcinfo libLLVM
 
 LOCAL_C_INCLUDES += frameworks/compile/libbcc/include
-LOCAL_C_INCLUDES += frameworks/rs/cpu_ref/linkloader/include
 
 LOCAL_CXX_STL := libc++
 
@@ -285,87 +284,4 @@
 
 include $(BUILD_HOST_STATIC_LIBRARY)
 
-LLVM_ROOT_PATH := external/llvm
-
-#=============================================================================
-# android librsloader for libbcc (Device)
-#-----------------------------------------------------------------------------
-
-rsloader_SRC_FILES := \
-  cpu_ref/linkloader/android/librsloader.cpp \
-  cpu_ref/linkloader/lib/ELFHeader.cpp \
-  cpu_ref/linkloader/lib/ELFSymbol.cpp \
-  cpu_ref/linkloader/lib/ELFSectionHeader.cpp \
-  cpu_ref/linkloader/lib/ELFTypes.cpp \
-  cpu_ref/linkloader/lib/GOT.cpp \
-  cpu_ref/linkloader/lib/MemChunk.cpp \
-  cpu_ref/linkloader/lib/StubLayout.cpp \
-  cpu_ref/linkloader/utils/helper.cpp \
-  cpu_ref/linkloader/utils/raw_ostream.cpp \
-  cpu_ref/linkloader/utils/rsl_assert.cpp
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := librsloader
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SRC_FILES := $(rsloader_SRC_FILES)
-
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_CXX_STL := libc++
-
-LOCAL_CFLAGS += $(rs_base_CFLAGS)
-LOCAL_CPPFLAGS += -fno-exceptions
-
-LOCAL_C_INCLUDES := \
-  $(LOCAL_PATH)/cpu_ref/linkloader \
-  $(LOCAL_PATH)/cpu_ref/linkloader/include \
-  $(LOCAL_C_INCLUDES)
-
-include $(LLVM_ROOT_PATH)/llvm-device-build.mk
-include $(BUILD_STATIC_LIBRARY)
-
-#=============================================================================
-# android librsloader for libbcc (Host)
-#-----------------------------------------------------------------------------
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := librsloader
-ifneq ($(HOST_OS),windows)
-LOCAL_CLANG := true
-endif
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SRC_FILES := $(rsloader_SRC_FILES)
-
-ifdef USE_MINGW
-LOCAL_SRC_FILES += cpu_ref/linkloader/lib/mmanWindows.cpp
-endif
-
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_CXX_STL := libc++
-
-LOCAL_CFLAGS += $(rs_base_CFLAGS)
-LOCAL_CFLAGS += -D__HOST__
-LOCAL_CPPFLAGS += -fno-exceptions
-
-ifeq ($(HOST_OS),windows)
-LOCAL_C_INCLUDES := \
-  $(LOCAL_PATH)/cpu_ref/linkloader \
-  $(LOCAL_PATH)/cpu_ref/linkloader/include \
-  $(LOCAL_C_INCLUDES)
-else
-LOCAL_C_INCLUDES := \
-  $(LOCAL_PATH)/cpu_ref/linkloader \
-  $(LOCAL_PATH)/cpu_ref/linkloader/include \
-  $(LOCAL_C_INCLUDES)
-endif
-
-include $(LLVM_ROOT_PATH)/llvm-host-build.mk
-include $(BUILD_HOST_STATIC_LIBRARY)
-
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/cpu_ref/linkloader/android/librsloader.cpp b/cpu_ref/linkloader/android/librsloader.cpp
deleted file mode 100644
index fa74a7d..0000000
--- a/cpu_ref/linkloader/android/librsloader.cpp
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "librsloader.h"
-
-#include "ELFObject.h"
-#include "ELFSectionSymTab.h"
-#include "ELFSymbol.h"
-
-#include "utils/serialize.h"
-
-#define LOG_TAG "bcc"
-#include "cutils/log.h"
-
-#include <llvm/Support/ELF.h>
-
-#if defined(__LP64__) || defined(__x86_64__)
-static inline RSExecRef wrap(ELFObject<64> *object) {
-  return reinterpret_cast<RSExecRef>(object);
-}
-#else
-static inline RSExecRef wrap(ELFObject<32> *object) {
-  return reinterpret_cast<RSExecRef>(object);
-}
-#endif
-
-#if defined(__LP64__) || defined(__x86_64__)
-static inline ELFObject<64> *unwrap(RSExecRef object) {
-  return reinterpret_cast<ELFObject<64> *>(object);
-}
-#else
-static inline ELFObject<32> *unwrap(RSExecRef object) {
-  return reinterpret_cast<ELFObject<32> *>(object);
-}
-#endif
-
-extern "C" RSExecRef rsloaderCreateExec(unsigned char const *buf,
-                                        size_t buf_size,
-                                        RSFindSymbolFn find_symbol,
-                                        void *find_symbol_context) {
-  RSExecRef object = rsloaderLoadExecutable(buf, buf_size);
-  if (!object) {
-    return nullptr;
-  }
-
-  if (!rsloaderRelocateExecutable(object, find_symbol, find_symbol_context)) {
-    rsloaderDisposeExec(object);
-    return nullptr;
-  }
-
-  return object;
-}
-
-extern "C" RSExecRef rsloaderLoadExecutable(unsigned char const *buf,
-                                            size_t buf_size) {
-  ArchiveReaderLE AR(buf, buf_size);
-
-#if defined(__LP64__) || defined(__x86_64__)
-  std::unique_ptr<ELFObject<64> > object(ELFObject<64>::read(AR));
-#else
-  std::unique_ptr<ELFObject<32> > object(ELFObject<32>::read(AR));
-#endif
-  if (!object) {
-    ALOGE("Unable to load the ELF object.");
-    return nullptr;
-  }
-
-  return wrap(object.release());
-}
-
-extern "C" int rsloaderRelocateExecutable(RSExecRef object_,
-                                          RSFindSymbolFn find_symbol,
-                                          void *find_symbol_context) {
-#if defined(__LP64__) || defined(__x86_64__)
-  ELFObject<64>* object = unwrap(object_);
-#else
-  ELFObject<32>* object = unwrap(object_);
-#endif
-  object->relocate(find_symbol, find_symbol_context);
-  return (object->getMissingSymbols() == 0);
-}
-
-extern "C" void rsloaderUpdateSectionHeaders(RSExecRef object_,
-                                             unsigned char *buf) {
-#if defined(__LP64__) || defined(__x86_64__)
-  ELFObject<64> *object = unwrap(object_);
-#else
-  ELFObject<32> *object = unwrap(object_);
-#endif
-
-  // Remap the section header addresses to match the loaded code
-#if defined(__LP64__) || defined(__x86_64__)
-  llvm::ELF::Elf64_Ehdr* header = reinterpret_cast<llvm::ELF::Elf64_Ehdr*>(buf);
-#else
-  llvm::ELF::Elf32_Ehdr* header = reinterpret_cast<llvm::ELF::Elf32_Ehdr*>(buf);
-#endif
-
-#if defined(__LP64__) || defined(__x86_64__)
-  llvm::ELF::Elf64_Shdr* shtab =
-      reinterpret_cast<llvm::ELF::Elf64_Shdr*>(buf + header->e_shoff);
-#else
-  llvm::ELF::Elf32_Shdr* shtab =
-      reinterpret_cast<llvm::ELF::Elf32_Shdr*>(buf + header->e_shoff);
-#endif
-
-  for (int i = 0; i < header->e_shnum; i++) {
-    if (shtab[i].sh_flags & SHF_ALLOC) {
-#if defined(__LP64__) || defined(__x86_64__)
-      ELFSectionBits<64>* bits =
-          static_cast<ELFSectionBits<64>*>(object->getSectionByIndex(i));
-#else
-      ELFSectionBits<32>* bits =
-          static_cast<ELFSectionBits<32>*>(object->getSectionByIndex(i));
-#endif
-      if (bits) {
-        const unsigned char* addr = bits->getBuffer();
-#if defined(__LP64__) || defined(__x86_64__)
-        shtab[i].sh_addr = reinterpret_cast<llvm::ELF::Elf64_Addr>(addr);
-#else
-        shtab[i].sh_addr = reinterpret_cast<llvm::ELF::Elf32_Addr>(addr);
-#endif
-      }
-    }
-  }
-}
-
-extern "C" void rsloaderDisposeExec(RSExecRef object) {
-  delete unwrap(object);
-}
-
-extern "C" void *rsloaderGetSymbolAddress(RSExecRef object_,
-                                          char const *name) {
-#if defined(__LP64__) || defined(__x86_64__)
-  ELFObject<64> *object = unwrap(object_);
-
-  ELFSectionSymTab<64> *symtab =
-    static_cast<ELFSectionSymTab<64> *>(object->getSectionByName(".symtab"));
-#else
-  ELFObject<32> *object = unwrap(object_);
-
-  ELFSectionSymTab<32> *symtab =
-    static_cast<ELFSectionSymTab<32> *>(object->getSectionByName(".symtab"));
-#endif
-
-  if (!symtab) {
-    return nullptr;
-  }
-
-#if defined(__LP64__) || defined(__x86_64__)
-  ELFSymbol<64> *symbol = symtab->getByName(name);
-#else
-  ELFSymbol<32> *symbol = symtab->getByName(name);
-#endif
-
-  if (!symbol) {
-    ALOGV("Symbol not found: %s\n", name);
-    return nullptr;
-  }
-
-  int machine = object->getHeader()->getMachine();
-
-  return symbol->getAddress(machine, false);
-}
-
-extern "C" size_t rsloaderGetSymbolSize(RSExecRef object_, char const *name) {
-#if defined(__LP64__) || defined(__x86_64__)
-  ELFObject<64> *object = unwrap(object_);
-
-  ELFSectionSymTab<64> *symtab =
-    static_cast<ELFSectionSymTab<64> *>(object->getSectionByName(".symtab"));
-#else
-  ELFObject<32> *object = unwrap(object_);
-
-  ELFSectionSymTab<32> *symtab =
-    static_cast<ELFSectionSymTab<32> *>(object->getSectionByName(".symtab"));
-#endif
-  if (!symtab) {
-    return 0;
-  }
-
-#if defined(__LP64__) || defined(__x86_64__)
-  ELFSymbol<64> *symbol = symtab->getByName(name);
-#else
-  ELFSymbol<32> *symbol = symtab->getByName(name);
-#endif
-
-  if (!symbol) {
-    ALOGV("Symbol not found: %s\n", name);
-    return 0;
-  }
-
-  return (size_t)symbol->getSize();
-}
-
-extern "C" size_t rsloaderGetFuncCount(RSExecRef object) {
-#if defined(__LP64__) || defined(__x86_64__)
-  ELFSectionSymTab<64> *symtab = static_cast<ELFSectionSymTab<64> *>(
-#else
-  ELFSectionSymTab<32> *symtab = static_cast<ELFSectionSymTab<32> *>(
-#endif
-    unwrap(object)->getSectionByName(".symtab"));
-
-  if (!symtab) {
-    return 0;
-  }
-
-  return symtab->getFuncCount();
-}
-
-extern "C" void rsloaderGetFuncNameList(RSExecRef object,
-                                        size_t size,
-                                        char const **list) {
-#if defined(__LP64__) || defined(__x86_64__)
-  ELFSectionSymTab<64> *symtab = static_cast<ELFSectionSymTab<64> *>(
-#else
-  ELFSectionSymTab<32> *symtab = static_cast<ELFSectionSymTab<32> *>(
-#endif
-    unwrap(object)->getSectionByName(".symtab"));
-
-  if (symtab) {
-    symtab->getFuncNameList(size, list);
-  }
-}
diff --git a/cpu_ref/linkloader/android/librsloader.h b/cpu_ref/linkloader/android/librsloader.h
deleted file mode 100644
index ab8361a..0000000
--- a/cpu_ref/linkloader/android/librsloader.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef LIBRSLOADER_H
-#define LIBRSLOADER_H
-
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct RSExecOpaque;
-typedef struct RSExecOpaque *RSExecRef;
-typedef void *(*RSFindSymbolFn)(void *, char const *);
-
-RSExecRef rsloaderCreateExec(unsigned char const *buf,
-                             size_t buf_size,
-                             RSFindSymbolFn find_symbol,
-                             void *find_symbol_context);
-
-RSExecRef rsloaderLoadExecutable(unsigned char const *buf,
-                                 size_t buf_size);
-
-int rsloaderRelocateExecutable(RSExecRef object,
-                               RSFindSymbolFn find_symbol,
-                               void *find_symbol_context);
-
-void rsloaderUpdateSectionHeaders(RSExecRef object, unsigned char *buf);
-
-void rsloaderDisposeExec(RSExecRef object);
-
-void *rsloaderGetSymbolAddress(RSExecRef object, char const *name);
-
-size_t rsloaderGetSymbolSize(RSExecRef object, char const *name);
-
-size_t rsloaderGetFuncCount(RSExecRef object);
-
-void rsloaderGetFuncNameList(RSExecRef object, size_t size, char const **list);
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* LIBRSLOADER_H */
diff --git a/cpu_ref/linkloader/android/test-librsloader.c b/cpu_ref/linkloader/android/test-librsloader.c
deleted file mode 100644
index 3c9ac2d..0000000
--- a/cpu_ref/linkloader/android/test-librsloader.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "librsloader.h"
-#include "utils/rsl_assert.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-struct func_entry_t {
-  char const *name;
-  size_t name_len;
-  void *addr;
-};
-
-void *find_sym(void *context, char const *name) {
-  static struct func_entry_t const tab[] = {
-#define DEF(NAME, ADDR) \
-    { NAME, sizeof(NAME) - 1, (void *)(&(ADDR)) },
-
-    DEF("printf", printf)
-    DEF("scanf", scanf)
-    DEF("__isoc99_scanf", scanf)
-    DEF("rand", rand)
-    DEF("time", time)
-    DEF("srand", srand)
-#undef DEF
-  };
-
-  static size_t const tab_size = sizeof(tab) / sizeof(struct func_entry_t);
-
-  // Note: Since our table is small, we are using trivial O(n) searching
-  // function.  For bigger table, it will be better to use binary
-  // search or hash function.
-  size_t i;
-  size_t name_len = strlen(name);
-  for (i = 0; i < tab_size; ++i) {
-    if (name_len == tab[i].name_len && strcmp(name, tab[i].name) == 0) {
-      return tab[i].addr;
-    }
-  }
-
-  rsl_assert(0 && "Can't find symbol.");
-  return 0;
-}
-
-int main(int argc, char **argv) {
-  if (argc < 2) {
-    fprintf(stderr, "USAGE: %s [ELF] [ARGS]\n", argv[0]);
-    exit(EXIT_FAILURE);
-  }
-
-  int fd = open(argv[1], O_RDONLY);
-  if (fd < 0) {
-    fprintf(stderr, "ERROR: Unable to open the file: %s\n", argv[1]);
-    exit(EXIT_FAILURE);
-  }
-
-  struct stat sb;
-  if (fstat(fd, &sb) != 0) {
-    fprintf(stderr, "ERROR: Unable to stat the file: %s\n", argv[1]);
-    close(fd);
-    exit(EXIT_FAILURE);
-  }
-
-  unsigned char const *image = (unsigned char const *)
-    mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
-
-  if (image == MAP_FAILED) {
-    fprintf(stderr, "ERROR: Unable to mmap the file: %s\n", argv[1]);
-    close(fd);
-    exit(EXIT_FAILURE);
-  }
-
-  RSExecRef object = rsloaderCreateExec(image, sb.st_size, find_sym, 0);
-  if (!object) {
-    fprintf(stderr, "ERROR: Unable to load elf object.\n");
-    close(fd);
-    exit(EXIT_FAILURE);
-  }
-
-  int (*main_stub)(int, char **) =
-    (int (*)(int, char **))rsloaderGetSymbolAddress(object, "main");
-
-  int ret = main_stub(argc - 1, argv + 1);
-  printf("============================================================\n");
-  printf("ELF object finished with code: %d\n", ret);
-  fflush(stdout);
-
-  rsloaderDisposeExec(object);
-
-  close(fd);
-
-  return EXIT_SUCCESS;
-}
diff --git a/cpu_ref/linkloader/include/ELF.h b/cpu_ref/linkloader/include/ELF.h
deleted file mode 100644
index 6205b98..0000000
--- a/cpu_ref/linkloader/include/ELF.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef ELF_H
-#define ELF_H
-
-#include <llvm/Support/ELF.h>
-// FIXME: Can't using namespace in header file!
-using namespace llvm::ELF;
-
-// These definitions are not defined in include/llvm/Support/ELF.h.
-// So we define them here.
-
-#ifndef ET_LOOS
-#define ET_LOOS 0xfe00
-#endif
-
-#ifndef ET_HIOS
-#define ET_HIOS 0xfeff
-#endif
-
-#endif // ELF_H
diff --git a/cpu_ref/linkloader/include/ELFHeader.h b/cpu_ref/linkloader/include/ELFHeader.h
deleted file mode 100644
index 1251c78..0000000
--- a/cpu_ref/linkloader/include/ELFHeader.h
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_HEADER_H
-#define ELF_HEADER_H
-
-#include "ELFTypes.h"
-#include "ELF.h"
-
-#include <memory>
-#include <string.h>
-
-class ELFHeaderHelperMixin {
-protected:
-  static char const *getClassStr(int clazz);
-  static char const *getEndiannessStr(int endianness);
-  static char const *getOSABIStr(int abi);
-  static char const *getObjectTypeStr(uint16_t type);
-  static char const *getMachineStr(uint16_t machine);
-  static char const *getVersionStr(uint32_t version);
-};
-
-template <unsigned Bitwidth>
-class ELFHeader : private ELFHeaderHelperMixin {
-public:
-  ELF_TYPE_INTRO_TO_TEMPLATE_SCOPE(Bitwidth);
-
-protected:
-  byte_t   e_ident[EI_NIDENT];
-  half_t   e_type;
-  half_t   e_machine;
-  word_t   e_version;
-  addr_t   e_entry;
-  offset_t e_phoff;
-  offset_t e_shoff;
-  word_t   e_flags;
-  half_t   e_ehsize;
-  half_t   e_phentsize;
-  half_t   e_phnum;
-  half_t   e_shentsize;
-  half_t   e_shnum;
-  half_t   e_shstrndx;
-
-protected:
-  ELFHeader() { }
-
-public:
-  byte_t getClass() const {
-    return e_ident[EI_CLASS];
-  }
-
-  byte_t getEndianness() const {
-    return e_ident[EI_DATA];
-  }
-
-  byte_t getVersionFromIdent() const {
-    return e_ident[EI_VERSION];
-  }
-
-  byte_t getOSABI() const {
-    return e_ident[EI_OSABI];
-  }
-
-  byte_t getABIVersion() const {
-    return e_ident[EI_ABIVERSION];
-  }
-
-  bool is32bit() const {
-    return e_ident[EI_CLASS] == ELFCLASS32;
-  }
-
-  bool is64bit() const {
-    return e_ident[EI_CLASS] == ELFCLASS64;
-  }
-
-  bool isBigEndian() const {
-    return e_ident[EI_DATA] == ELFDATA2MSB;
-  }
-
-  bool isLittleEndian() const {
-    return e_ident[EI_DATA] == ELFDATA2LSB;
-  }
-
-  half_t getObjectType() const {
-    return e_type;
-  }
-
-  half_t getMachine() const {
-    return e_machine;
-  }
-
-  word_t getVersion() const {
-    return e_version;
-  }
-
-  addr_t getEntryAddress() const {
-    return e_entry;
-  }
-
-  offset_t getProgramHeaderTableOffset() const {
-    return e_phoff;
-  }
-
-  offset_t getSectionHeaderTableOffset() const {
-    return e_shoff;
-  }
-
-  word_t getFlags() const {
-    return e_flags;
-  }
-
-  half_t getELFHeaderSize() const {
-    return e_ehsize;
-  }
-
-  half_t getProgramHeaderEntrySize() const {
-    return e_phentsize;
-  }
-
-  half_t getProgramHeaderNum() const {
-    return e_phnum;
-  }
-
-  half_t getSectionHeaderEntrySize() const {
-    return e_shentsize;
-  }
-
-  half_t getSectionHeaderNum() const {
-    return e_shnum;
-  }
-
-  half_t getStringSectionIndex() const {
-    return e_shstrndx;
-  }
-
-  template <typename Archiver>
-  static ELFHeader *read(Archiver &AR) {
-    if (!AR) {
-      // Archiver is in bad state before calling read function.
-      // Return nullptr and do nothing.
-      return nullptr;
-    }
-
-    std::unique_ptr<ELFHeader> header(new ELFHeader());
-    if (!header->serialize(AR)) {
-      // Unable to read the structure.  Return nullptr.
-      return nullptr;
-    }
-
-    if (!header->isValid()) {
-      // Header read from archiver is not valid.  Return nullptr.
-      return nullptr;
-    }
-
-    return header.release();
-  }
-
-  void print();
-
-  bool isValid() const {
-    return (isValidELFIdent() && isCompatibleHeaderSize());
-  }
-
-private:
-  template <typename Archiver>
-  bool serialize(Archiver &AR) {
-    AR.prologue(TypeTraits<ELFHeaderTy>::size);
-
-    AR & e_ident;
-    AR & e_type;
-    AR & e_machine;
-    AR & e_version;
-    AR & e_entry;
-    AR & e_phoff;
-    AR & e_shoff;
-    AR & e_flags;
-    AR & e_ehsize;
-    AR & e_phentsize;
-    AR & e_phnum;
-    AR & e_shentsize;
-    AR & e_shnum;
-    AR & e_shstrndx;
-
-    AR.epilogue(TypeTraits<ELFHeaderTy>::size);
-    return AR;
-  }
-
-  bool isValidMagicWord() const {
-    return (memcmp(e_ident, "\x7f" "ELF", 4) == 0);
-  }
-
-  bool isValidClass() const {
-    return ((Bitwidth == 32 && is32bit()) ||
-            (Bitwidth == 64 && is64bit()));
-  }
-
-  bool isValidEndianness() const {
-    return (isBigEndian() || isLittleEndian());
-  }
-
-  bool isValidHeaderVersion() const {
-    return (getVersion() == EV_CURRENT);
-  }
-
-  bool isUnusedZeroedPadding() const {
-    for (size_t i = EI_PAD; i < EI_NIDENT; ++i) {
-      if (e_ident[i] != 0) {
-        return false;
-      }
-    }
-    return true;
-  }
-
-  bool isValidELFIdent() const {
-    return (isValidMagicWord() &&
-            isValidClass() &&
-            isValidEndianness() &&
-            isValidHeaderVersion() &&
-            isUnusedZeroedPadding());
-  }
-
-  bool isCompatibleHeaderSize() const {
-    return (
-      (e_ehsize == TypeTraits<ELFHeaderTy>::size) &&
-      (e_phnum == 0 || e_phentsize == TypeTraits<ELFProgramHeaderTy>::size) &&
-      (e_shnum == 0 || e_shentsize == TypeTraits<ELFSectionHeaderTy>::size));
-  }
-};
-
-#include "impl/ELFHeader.hxx"
-
-#endif // ELF_HEADER_H
diff --git a/cpu_ref/linkloader/include/ELFObject.h b/cpu_ref/linkloader/include/ELFObject.h
deleted file mode 100644
index d750d9e..0000000
--- a/cpu_ref/linkloader/include/ELFObject.h
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_OBJECT_H
-#define ELF_OBJECT_H
-
-#include "ELFTypes.h"
-#include "MemChunk.h"
-
-#include "utils/rsl_assert.h"
-
-#include <memory>
-#include <string>
-#include <vector>
-
-template <unsigned Bitwidth>
-class ELFObject {
-public:
-  ELF_TYPE_INTRO_TO_TEMPLATE_SCOPE(Bitwidth);
-
-private:
-  std::unique_ptr<ELFHeaderTy> header;
-  std::unique_ptr<ELFSectionHeaderTableTy> shtab;
-  std::vector<ELFSectionTy *> stab;
-
-  MemChunk SHNCommonData;
-  unsigned char *SHNCommonDataPtr;
-  size_t SHNCommonDataFreeSize;
-
-  bool missingSymbols;
-
-  // TODO: Need refactor!
-  bool initSHNCommonDataSize(size_t SHNCommonDataSize) {
-    rsl_assert(!SHNCommonDataPtr && "Can't init twice.");
-    if (!SHNCommonData.allocate(SHNCommonDataSize)) {
-      return false;
-    }
-
-    SHNCommonDataPtr = SHNCommonData.getBuffer();
-    SHNCommonDataFreeSize = SHNCommonDataSize;
-    return true;
-  }
-
-private:
-  ELFObject() : SHNCommonDataPtr(nullptr), missingSymbols(false) { }
-
-public:
-  template <typename Archiver>
-  static ELFObject *read(Archiver &AR);
-
-  ELFHeaderTy const *getHeader() const {
-    return header.get();
-  }
-
-  ELFSectionHeaderTableTy const *getSectionHeaderTable() const {
-    return shtab.get();
-  }
-
-  char const *getSectionName(size_t i) const;
-  ELFSectionTy const *getSectionByIndex(size_t i) const;
-  ELFSectionTy *getSectionByIndex(size_t i);
-  ELFSectionTy const *getSectionByName(std::string const &str) const;
-  ELFSectionTy *getSectionByName(std::string const &str);
-
-  inline bool getMissingSymbols() const {
-    return missingSymbols;
-  }
-
-  void *allocateSHNCommonData(size_t size, size_t align = 1) {
-    rsl_assert(size > 0 && align != 0);
-
-    rsl_assert(SHNCommonDataPtr && "Must init common data size before use!");
-
-    // Ensure alignment
-    size_t rem = ((uintptr_t)SHNCommonDataPtr) % align;
-    if (rem != 0) {
-      SHNCommonDataPtr += align - rem;
-      SHNCommonDataFreeSize -= align - rem;
-    }
-
-    // Ensure the free size is sufficient
-    if (SHNCommonDataFreeSize < size) {
-      return nullptr;
-    }
-
-    // Allcoate
-    void *result = SHNCommonDataPtr;
-    SHNCommonDataPtr += size;
-    SHNCommonDataFreeSize -= size;
-
-    return result;
-  }
-
-  void relocate(void *(*find_sym)(void *context, char const *name),
-                void *context);
-
-  void print() const;
-
-  ~ELFObject() {
-    for (size_t i = 0; i < stab.size(); ++i) {
-      // Delete will check the pointer is nullptr or not by himself.
-      delete stab[i];
-    }
-  }
-
-private:
-  void relocateARM(void *(*find_sym)(void *context, char const *name),
-                   void *context,
-                   ELFSectionRelTableTy *reltab,
-                   ELFSectionProgBitsTy *text);
-
-  void relocateAARCH64(void *(*find_sym)(void *context, char const *name),
-                   void *context,
-                   ELFSectionRelTableTy *reltab,
-                   ELFSectionProgBitsTy *text);
-
-  void relocateX86_32(void *(*find_sym)(void *context, char const *name),
-                      void *context,
-                      ELFSectionRelTableTy *reltab,
-                      ELFSectionProgBitsTy *text);
-
-  void relocateX86_64(void *(*find_sym)(void *context, char const *name),
-                      void *context,
-                      ELFSectionRelTableTy *reltab,
-                      ELFSectionProgBitsTy *text);
-
-  void relocateMIPS(void *(*find_sym)(void *context, char const *name),
-                    void *context,
-                    ELFSectionRelTableTy *reltab,
-                    ELFSectionProgBitsTy *text);
-
-  void relocateMIPS64(void *(*find_sym)(void *context, char const *name),
-                      void *context,
-                      ELFSectionRelTableTy *reltab,
-                      ELFSectionProgBitsTy *text);
-};
-
-#include "impl/ELFObject.hxx"
-
-#endif // ELF_OBJECT_H
diff --git a/cpu_ref/linkloader/include/ELFReloc.h b/cpu_ref/linkloader/include/ELFReloc.h
deleted file mode 100644
index a6d7f5e..0000000
--- a/cpu_ref/linkloader/include/ELFReloc.h
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_RELOC_H
-#define ELF_RELOC_H
-
-#include "ELFTypes.h"
-#include "utils/rsl_assert.h"
-
-#include <string>
-#include <stdint.h>
-
-template <unsigned Bitwidth>
-class ELFReloc_CRTP {
-public:
-  ELF_TYPE_INTRO_TO_TEMPLATE_SCOPE(Bitwidth);
-
-protected:
-  size_t index;
-
-  addr_t    r_offset;
-  relinfo_t r_info;
-  addend_t  r_addend;
-
-protected:
-  ELFReloc_CRTP() : index(0), r_offset(0), r_addend(0) { }
-  ~ELFReloc_CRTP() { }
-
-public:
-  size_t getIndex() const {
-    return index;
-  }
-
-  addr_t getOffset() const {
-    return r_offset;
-  }
-
-  addend_t getAddend() const {
-    return r_addend;
-  }
-
-  bool isValid() const {
-    // FIXME: Should check the correctness of the relocation entite.
-    return true;
-  }
-
-  template <typename Archiver>
-  static ELFRelocTy *readRel(Archiver &AR, size_t index);
-
-  template <typename Archiver>
-  static ELFRelocTy *readRela(Archiver &AR, size_t index);
-
-  void print(bool shouldPrintHeader = false) const;
-
-private:
-  ELFRelocTy *concrete() {
-    return static_cast<ELFRelocTy *>(this);
-  }
-
-  ELFRelocTy const *concrete() const {
-    return static_cast<ELFRelocTy const *>(this);
-  }
-
-  template <typename Archiver>
-  bool serializeRel(Archiver &AR) {
-    rsl_assert(r_addend == 0 && "r_addend should be zero before serialization.");
-
-    AR.prologue(TypeTraits<ELFRelocRelTy>::size);
-
-    AR & r_offset;
-    AR & r_info;
-
-    AR.epilogue(TypeTraits<ELFRelocRelTy>::size);
-    return AR;
-  }
-
-  template <typename Archiver>
-  bool serializeRela(Archiver &AR) {
-    AR.prologue(TypeTraits<ELFRelocRelaTy>::size);
-
-    AR & r_offset;
-    AR & r_info;
-    AR & r_addend;
-
-    AR.epilogue(TypeTraits<ELFRelocRelaTy>::size);
-    return AR;
-  }
-
-};
-
-template <>
-class ELFReloc<32> : public ELFReloc_CRTP<32> {
-  friend class ELFReloc_CRTP<32>;
-
-private:
-  ELFReloc() {
-  }
-
-public:
-  word_t getSymTabIndex() const {
-#define ELF32_R_SYM(i)  ((i)>>8)
-    return ELF32_R_SYM(this->r_info);
-#undef ELF32_R_SYM
-  }
-
-  word_t getType() const {
-#define ELF32_R_TYPE(i)   ((unsigned char)(i))
-    return ELF32_R_TYPE(this->r_info);
-#undef ELF32_R_TYPE
-  }
-
-};
-
-template <>
-class ELFReloc<64> : public ELFReloc_CRTP<64> {
-  friend class ELFReloc_CRTP<64>;
-
-private:
-  ELFReloc() {
-  }
-
-public:
-  xword_t getSymTabIndex() const {
-#if defined(__mips__)
-/*
- * Packed r_info on MIPS is:
- * r_sym (4) - r_ssym (1) - r_type3 (1) - r_type2 (1) - r_type (1)
- * Each entry represents up to three actual relocations.
- * Thus, the macros look different.
- */
-#define ELF64_R_SYM(i)    ((i)&0xffffffffL)
-#else
-#define ELF64_R_SYM(i)    ((i)>>32)
-#endif
-    return ELF64_R_SYM(this->r_info);
-#undef ELF64_R_SYM
-  }
-
-  xword_t getType() const {
-#if defined(__mips__)
-#define ELF64_R_TYPE(i)   ((i)>>32)
-#else
-#define ELF64_R_TYPE(i)   ((i)&0xffffffffL)
-#endif
-    return ELF64_R_TYPE(this->r_info);
-#undef ELF64_R_TYPE
-  }
-};
-
-#include "impl/ELFReloc.hxx"
-
-#endif // ELF_RELOC_H
diff --git a/cpu_ref/linkloader/include/ELFSection.h b/cpu_ref/linkloader/include/ELFSection.h
deleted file mode 100644
index 1548413..0000000
--- a/cpu_ref/linkloader/include/ELFSection.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_H
-#define ELF_SECTION_H
-
-#include "ELFTypes.h"
-
-template <unsigned Bitwidth>
-class ELFSection {
-public:
-  ELF_TYPE_INTRO_TO_TEMPLATE_SCOPE(Bitwidth);
-
-protected:
-  ELFSection() { }
-
-public:
-  virtual ~ELFSection() { }
-
-  virtual void print() const = 0;
-
-  template <typename Archiver>
-  static ELFSection *read(Archiver &AR, ELFObjectTy *,
-                          ELFSectionHeaderTy const *);
-};
-
-#include "impl/ELFSection.hxx"
-
-#endif // ELF_SECTION_H
diff --git a/cpu_ref/linkloader/include/ELFSectionBits.h b/cpu_ref/linkloader/include/ELFSectionBits.h
deleted file mode 100644
index 33b4259..0000000
--- a/cpu_ref/linkloader/include/ELFSectionBits.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_BITS_H
-#define ELF_SECTION_BITS_H
-
-#include "ELFTypes.h"
-#include "ELFSection.h"
-#include "MemChunk.h"
-
-template <unsigned Bitwidth>
-class ELFSectionBits : public ELFSection<Bitwidth> {
-protected:
-  ELFSectionHeader<Bitwidth> const *sh;
-  MemChunk chunk;
-
-protected:
-  ELFSectionBits() : sh(nullptr) { }
-
-public:
-  virtual void print() const;
-
-  bool protect();
-
-  unsigned char const *getBuffer() const {
-    return chunk.getBuffer();
-  }
-
-  unsigned char *getBuffer() {
-    return chunk.getBuffer();
-  }
-
-  unsigned char &operator[](size_t index) {
-    return chunk[index];
-  }
-
-  unsigned char const &operator[](size_t index) const {
-    return chunk[index];
-  }
-
-  size_t size() const {
-    return chunk.size();
-  }
-
-};
-
-#include "impl/ELFSectionBits.hxx"
-
-#endif // ELF_SECTION_BITS_H
diff --git a/cpu_ref/linkloader/include/ELFSectionHeader.h b/cpu_ref/linkloader/include/ELFSectionHeader.h
deleted file mode 100644
index a8881f2..0000000
--- a/cpu_ref/linkloader/include/ELFSectionHeader.h
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_HEADER_H
-#define ELF_SECTION_HEADER_H
-
-#include "ELFTypes.h"
-
-#include <stdint.h>
-
-class ELFSectionHeaderHelperMixin {
-protected:
-  static char const *getSectionTypeStr(uint32_t type);
-};
-
-template <unsigned Bitwidth>
-class ELFSectionHeader_CRTP : private ELFSectionHeaderHelperMixin {
-public:
-  ELF_TYPE_INTRO_TO_TEMPLATE_SCOPE(Bitwidth);
-
-protected:
-  ELFObjectTy const *owner;
-
-  size_t index;
-
-  word_t sh_name;
-  word_t sh_type;
-  addr_t sh_addr;
-  offset_t sh_offset;
-  word_t sh_link;
-  word_t sh_info;
-
-protected:
-  ELFSectionHeader_CRTP() { }
-  ~ELFSectionHeader_CRTP() { }
-
-public:
-  size_t getIndex() const {
-    return index;
-  }
-
-  word_t getNameIndex() const {
-    return sh_name;
-  }
-
-  char const *getName() const;
-
-  word_t getType() const {
-    return sh_type;
-  }
-
-  addr_t getAddress() const {
-    return sh_addr;
-  }
-
-  offset_t getOffset() const {
-    return sh_offset;
-  }
-
-  word_t getLink() const {
-    return sh_link;
-  }
-
-  word_t getExtraInfo() const {
-    return sh_info;
-  }
-
-  bool isValid() const {
-    // FIXME: Should check the correctness of the section header.
-    return true;
-  }
-
-  template <typename Archiver>
-  static ELFSectionHeaderTy *
-  read(Archiver &AR, ELFObjectTy const *owner, size_t index = 0);
-
-  void print(bool shouldPrintHeader = false) const;
-
-private:
-  ELFSectionHeaderTy *concrete() {
-    return static_cast<ELFSectionHeaderTy *>(this);
-  }
-
-  ELFSectionHeaderTy const *concrete() const {
-    return static_cast<ELFSectionHeaderTy const *>(this);
-  }
-};
-
-
-#include "impl/ELFSectionHeader.hxx"
-
-template <>
-class ELFSectionHeader<32> : public ELFSectionHeader_CRTP<32> {
-  friend class ELFSectionHeader_CRTP<32>;
-
-private:
-  word_t sh_flags;
-  word_t sh_size;
-  word_t sh_addralign;
-  word_t sh_entsize;
-
-private:
-  ELFSectionHeader() {
-  }
-
-  template <typename Archiver>
-  bool serialize(Archiver &AR) {
-    AR.prologue(TypeTraits<ELFSectionHeader>::size);
-
-    AR & sh_name;
-    AR & sh_type;
-    AR & sh_flags;
-    AR & sh_addr;
-    AR & sh_offset;
-    AR & sh_size;
-    AR & sh_link;
-    AR & sh_info;
-    AR & sh_addralign;
-    AR & sh_entsize;
-
-    AR.epilogue(TypeTraits<ELFSectionHeader>::size);
-    return AR;
-  }
-
-public:
-  word_t getFlags() const {
-    return sh_flags;
-  }
-
-  word_t getSize() const {
-    return sh_size;
-  }
-
-  word_t getAddressAlign() const {
-    return sh_addralign;
-  }
-
-  word_t getEntrySize() const {
-    return sh_entsize;
-  }
-};
-
-template <>
-class ELFSectionHeader<64> : public ELFSectionHeader_CRTP<64> {
-  friend class ELFSectionHeader_CRTP<64>;
-
-private:
-  xword_t sh_flags;
-  xword_t sh_size;
-  xword_t sh_addralign;
-  xword_t sh_entsize;
-
-private:
-  ELFSectionHeader() {
-  }
-
-  template <typename Archiver>
-  bool serialize(Archiver &AR) {
-    AR.prologue(TypeTraits<ELFSectionHeader>::size);
-
-    AR & sh_name;
-    AR & sh_type;
-    AR & sh_flags;
-    AR & sh_addr;
-    AR & sh_offset;
-    AR & sh_size;
-    AR & sh_link;
-    AR & sh_info;
-    AR & sh_addralign;
-    AR & sh_entsize;
-
-    AR.epilogue(TypeTraits<ELFSectionHeader>::size);
-    return AR;
-  }
-
-public:
-  xword_t getFlags() const {
-    return sh_flags;
-  }
-
-  xword_t getSize() const {
-    return sh_size;
-  }
-
-  xword_t getAddressAlign() const {
-    return sh_addralign;
-  }
-
-  xword_t getEntrySize() const {
-    return sh_entsize;
-  }
-};
-
-#endif // ELF_SECTION_HEADER_H
diff --git a/cpu_ref/linkloader/include/ELFSectionHeaderTable.h b/cpu_ref/linkloader/include/ELFSectionHeaderTable.h
deleted file mode 100644
index 3192cfe..0000000
--- a/cpu_ref/linkloader/include/ELFSectionHeaderTable.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_HEADER_TABLE_H
-#define ELF_SECTION_HEADER_TABLE_H
-
-#include "ELFTypes.h"
-
-#include <llvm/ADT/StringMap.h>
-
-#include <vector>
-#include <string>
-
-template <unsigned Bitwidth>
-class ELFSectionHeaderTable {
-public:
-  ELF_TYPE_INTRO_TO_TEMPLATE_SCOPE(Bitwidth);
-
-private:
-  std::vector<ELFSectionHeaderTy *> table;
-  llvm::StringMap<ELFSectionHeaderTy *> name_map;
-
-private:
-  ELFSectionHeaderTable() {
-  }
-
-public:
-  ~ELFSectionHeaderTable();
-
-  template <typename Archiver>
-  static ELFSectionHeaderTableTy *read(Archiver &AR, ELFObjectTy *owner);
-
-  ELFSectionHeaderTy const *operator[](size_t i) const {
-    return table[i];
-  }
-
-  ELFSectionHeaderTy *operator[](size_t i) {
-    return table[i];
-  }
-
-  void buildNameMap();
-
-  ELFSectionHeaderTy const *getByName(const std::string &name) const;
-  ELFSectionHeaderTy *getByName(const std::string &name);
-
-  void print() const;
-};
-
-#include "impl/ELFSectionHeaderTable.hxx"
-
-#endif // ELF_SECTION_HEADER_TABLE_H
diff --git a/cpu_ref/linkloader/include/ELFSectionNoBits.h b/cpu_ref/linkloader/include/ELFSectionNoBits.h
deleted file mode 100644
index 5c4b3f2..0000000
--- a/cpu_ref/linkloader/include/ELFSectionNoBits.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_NOBITS_H
-#define ELF_SECTION_NOBITS_H
-
-#include "ELFTypes.h"
-#include "ELFSectionBits.h"
-#include "ELFSectionHeader.h"
-#include "MemChunk.h"
-
-template <unsigned Bitwidth>
-class ELFSectionNoBits : public ELFSectionBits<Bitwidth> {
-public:
-  ELF_TYPE_INTRO_TO_TEMPLATE_SCOPE(Bitwidth);
-
-public:
-  template <typename Archiver>
-  static ELFSectionNoBits *read(Archiver &AR, ELFSectionHeaderTy const *sh);
-};
-
-#include "impl/ELFSectionNoBits.hxx"
-
-#endif // ELF_SECTION_NOBITS_H
diff --git a/cpu_ref/linkloader/include/ELFSectionProgBits.h b/cpu_ref/linkloader/include/ELFSectionProgBits.h
deleted file mode 100644
index 9c1d428..0000000
--- a/cpu_ref/linkloader/include/ELFSectionProgBits.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_PROGBITS_H
-#define ELF_SECTION_PROGBITS_H
-
-#include "ELFTypes.h"
-#include "ELFSectionBits.h"
-#include "ELFSectionHeader.h"
-#include "MemChunk.h"
-#include "StubLayout.h"
-
-template <unsigned Bitwidth>
-class ELFSectionProgBits : public ELFSectionBits<Bitwidth> {
-public:
-  ELF_TYPE_INTRO_TO_TEMPLATE_SCOPE(Bitwidth);
-
-private:
-  StubLayout *stubs;
-
-public:
-  template <typename Archiver>
-  static ELFSectionProgBits *read(Archiver &AR,
-                                  ELFObjectTy *owner,
-                                  ELFSectionHeaderTy const *sh);
-
-  StubLayout *getStubLayout() {
-    return stubs;
-  }
-
-  ELFSectionProgBits(int machine) {
-    switch(machine) {
-    case EM_ARM:
-      stubs = new StubLayoutARM();
-      break;
-
-    case EM_AARCH64:
-      stubs = new StubLayoutAARCH64();
-      break;
-
-    case EM_MIPS:
-      stubs = new StubLayoutMIPS();
-      break;
-
-    case EM_386:
-      stubs = new StubLayoutX86();
-      break;
-
-    case EM_X86_64:
-      stubs = new StubLayoutX86_64();
-      break;
-
-    default:
-      stubs = nullptr;
-    }
-  }
-
-  ~ELFSectionProgBits() {
-    if (stubs)
-      delete stubs;
-  }
-
-private:
-  template <typename Archiver>
-  bool serialize(Archiver &AR) {
-    ELFSectionHeaderTy const *sh = this->sh;
-    MemChunk &chunk = this->chunk;
-
-    AR.seek(sh->getOffset(), true);
-    AR.prologue(sh->getSize());
-    AR.readBytes(chunk.getBuffer(), sh->getSize());
-    AR.epilogue(sh->getSize());
-
-    return AR;
-  }
-};
-
-#include "impl/ELFSectionProgBits.hxx"
-
-#endif // ELF_SECTION_PROGBITS_H
diff --git a/cpu_ref/linkloader/include/ELFSectionRelTable.h b/cpu_ref/linkloader/include/ELFSectionRelTable.h
deleted file mode 100644
index 2799501..0000000
--- a/cpu_ref/linkloader/include/ELFSectionRelTable.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_REL_TABLE_H
-#define ELF_SECTION_REL_TABLE_H
-
-#include "ELFTypes.h"
-#include "ELFSection.h"
-
-#include <string>
-#include <vector>
-
-template <unsigned Bitwidth>
-class ELFSectionRelTable : public ELFSection<Bitwidth> {
-public:
-  ELF_TYPE_INTRO_TO_TEMPLATE_SCOPE(Bitwidth);
-
-private:
-  std::vector<ELFRelocTy *> table;
-
-private:
-  ELFSectionRelTable() { }
-
-public:
-  virtual ~ELFSectionRelTable();
-
-  virtual void print() const;
-
-  template <typename Archiver>
-  static ELFSectionRelTable *read(Archiver &AR, ELFSectionHeaderTy const *sh);
-
-  size_t size() const {
-    return table.size();
-  }
-
-  ELFRelocTy const *operator[](size_t index) const {
-    return table[index];
-  }
-
-  ELFRelocTy *operator[](size_t index) {
-    return table[index];
-  }
-
-  size_t getMaxNumStubs(ELFObjectTy const *) const;
-};
-
-#include "impl/ELFSectionRelTable.hxx"
-
-#endif // ELF_SECTION_REL_TABLE_H
diff --git a/cpu_ref/linkloader/include/ELFSectionStrTab.h b/cpu_ref/linkloader/include/ELFSectionStrTab.h
deleted file mode 100644
index 458dfa3..0000000
--- a/cpu_ref/linkloader/include/ELFSectionStrTab.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_STRTAB_H
-#define ELF_SECTION_STRTAB_H
-
-#include "ELFTypes.h"
-#include "ELFSection.h"
-
-#include <vector>
-
-template <unsigned Bitwidth>
-class ELFSectionStrTab : public ELFSection<Bitwidth> {
-public:
-  ELF_TYPE_INTRO_TO_TEMPLATE_SCOPE(Bitwidth);
-
-private:
-  ELFSectionHeaderTy const *section_header;
-  std::vector<char> buf;
-
-private:
-  ELFSectionStrTab() { }
-
-public:
-  template <typename Archiver>
-  static ELFSectionStrTab *read(Archiver &AR, ELFSectionHeaderTy const *sh);
-
-  virtual void print() const;
-
-  char const *operator[](size_t index) const {
-    return &*buf.begin() + index;
-  }
-};
-
-#include "impl/ELFSectionStrTab.hxx"
-
-#endif // ELF_SECTION_STRTAB_H
diff --git a/cpu_ref/linkloader/include/ELFSectionSymTab.h b/cpu_ref/linkloader/include/ELFSectionSymTab.h
deleted file mode 100644
index 821067f..0000000
--- a/cpu_ref/linkloader/include/ELFSectionSymTab.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_SYMTAB_H
-#define ELF_SECTION_SYMTAB_H
-
-#include "ELFTypes.h"
-
-#include <llvm/ADT/StringMap.h>
-
-#include <vector>
-#include <string>
-
-template <unsigned Bitwidth>
-class ELFSectionSymTab : public ELFSection<Bitwidth> {
-public:
-  ELF_TYPE_INTRO_TO_TEMPLATE_SCOPE(Bitwidth);
-
-private:
-  std::vector<ELFSymbolTy *> table;
-  llvm::StringMap<ELFSymbolTy *> name_map;
-
-private:
-  ELFSectionSymTab() { }
-
-public:
-  ~ELFSectionSymTab();
-
-  template <typename Archiver>
-  static ELFSectionSymTab *
-  read(Archiver &AR, ELFObjectTy *owner, ELFSectionHeaderTy const *sh);
-
-  virtual void print() const;
-
-  size_t size() const {
-    return table.size();
-  }
-
-  ELFSymbolTy const *operator[](size_t index) const {
-    return table[index];
-  }
-
-  ELFSymbolTy *operator[](size_t index) {
-    return table[index];
-  }
-
-  void buildNameMap();
-
-  ELFSymbolTy const *getByName(std::string const &name) const;
-
-  ELFSymbolTy *getByName(std::string const &name) {
-    return const_cast<ELFSymbolTy *>(
-           const_cast<ELFSectionSymTabTy const *>(this)->getByName(name));
-  }
-
-  size_t getFuncCount() const;
-
-  void getFuncNameList(size_t size, char const **list) const;
-
-  size_t getExternFuncCount() const;
-
-};
-
-#include "impl/ELFSectionSymTab.hxx"
-
-#endif // ELF_SECTION_SYMTAB_H
diff --git a/cpu_ref/linkloader/include/ELFSymbol.h b/cpu_ref/linkloader/include/ELFSymbol.h
deleted file mode 100644
index 65a97cc..0000000
--- a/cpu_ref/linkloader/include/ELFSymbol.h
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SYMBOL_H
-#define ELF_SYMBOL_H
-
-#include "ELFTypes.h"
-#include "ELF.h"
-
-#include <string>
-#include <algorithm>
-
-#include <stdint.h>
-#include <stdlib.h>
-
-class ELFSymbolHelperMixin {
-protected:
-  static char const *getTypeStr(uint8_t);
-  static char const *getBindingAttributeStr(uint8_t);
-  static char const *getVisibilityStr(uint8_t);
-};
-
-template <unsigned Bitwidth>
-class ELFSymbol_CRTP : private ELFSymbolHelperMixin {
-public:
-  ELF_TYPE_INTRO_TO_TEMPLATE_SCOPE(Bitwidth);
-
-protected:
-  ELFObject<Bitwidth> const *owner;
-
-  size_t index;
-
-  word_t st_name;
-  byte_t st_info;
-  byte_t st_other;
-  half_t st_shndx;
-  addr_t st_value;
-  symsize_t st_size;
-
-  mutable void *my_addr;
-
-protected:
-  ELFSymbol_CRTP() { my_addr = 0; }
-
-  ~ELFSymbol_CRTP() {
-#if 0
-    if (my_addr != 0 &&
-        getType() == STT_OBJECT &&
-        getSectionIndex() == SHN_COMMON) {
-      std::free(my_addr);
-    }
-#endif
-  }
-
-public:
-  size_t getIndex() const {
-    return index;
-  }
-
-  word_t getNameIndex() const {
-    return st_name;
-  }
-
-  char const *getName() const;
-
-// I don't want to include elf.h in .h file, so define those macro by ourself.
-#define ELF_ST_BIND(i)   ((i)>>4)
-#define ELF_ST_TYPE(i)   ((i)&0xf)
-#define ELF_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
-  byte_t getType() const {
-    return ELF_ST_TYPE(st_info);
-  }
-
-  byte_t getBindingAttribute() const {
-    return ELF_ST_BIND(st_info);
-  }
-#undef ELF_ST_BIND
-#undef ELF_ST_TYPE
-#undef ELF_ST_INFO
-
-#define ELF_ST_VISIBILITY(o) ((o)&0x3)
-  byte_t getVisibility() const {
-    return ELF_ST_VISIBILITY(st_other);
-  }
-#undef ELF_ST_VISIBILITY
-
-  half_t getSectionIndex() const {
-    return st_shndx;
-  }
-
-  addr_t getValue() const {
-    return st_value;
-  }
-
-  symsize_t getSize() const {
-    return st_size;
-  }
-
-  void *getAddress(int machine, bool autoAlloc = true) const;
-
-  void setAddress(void *addr) {
-    my_addr = addr;
-  }
-
-  bool isValid() const {
-    // FIXME: Should check the correctness of the section header.
-    return true;
-  }
-
-  bool isConcreteFunc() const {
-    return getType() == STT_FUNC;
-  }
-
-  bool isExternFunc() const {
-    return getType() == STT_NOTYPE;
-  }
-
-  template <typename Archiver>
-  static ELFSymbolTy *
-  read(Archiver &AR, ELFObject<Bitwidth> const *owner, size_t index = 0);
-
-  void print(bool shouldPrintHeader = false) const;
-
-private:
-  ELFSymbolTy *concrete() {
-    return static_cast<ELFSymbolTy *>(this);
-  }
-
-  ELFSymbolTy const *concrete() const {
-    return static_cast<ELFSymbolTy const *>(this);
-  }
-};
-
-template <>
-class ELFSymbol<32> : public ELFSymbol_CRTP<32> {
-  friend class ELFSymbol_CRTP<32>;
-
-private:
-  ELFSymbol() {
-  }
-
-  template <typename Archiver>
-  bool serialize(Archiver &AR) {
-    AR.prologue(TypeTraits<ELFSymbol>::size);
-
-    AR & st_name;
-    AR & st_value;
-    AR & st_size;
-    AR & st_info;
-    AR & st_other;
-    AR & st_shndx;
-
-    AR.epilogue(TypeTraits<ELFSymbol>::size);
-    return AR;
-  }
-};
-
-template <>
-class ELFSymbol<64> : public ELFSymbol_CRTP<64> {
-  friend class ELFSymbol_CRTP<64>;
-
-private:
-  ELFSymbol() {
-  }
-
-  template <typename Archiver>
-  bool serialize(Archiver &AR) {
-    AR.prologue(TypeTraits<ELFSymbol>::size);
-
-    AR & st_name;
-    AR & st_info;
-    AR & st_other;
-    AR & st_shndx;
-    AR & st_value;
-    AR & st_size;
-
-    AR.epilogue(TypeTraits<ELFSymbol>::size);
-    return AR;
-  }
-};
-
-#include "impl/ELFSymbol.hxx"
-
-#endif // ELF_SYMBOL_H
diff --git a/cpu_ref/linkloader/include/ELFTypes.h b/cpu_ref/linkloader/include/ELFTypes.h
deleted file mode 100644
index 3e99f78..0000000
--- a/cpu_ref/linkloader/include/ELFTypes.h
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_TYPES_H
-#define ELF_TYPES_H
-
-#include "utils/traits.h"
-
-#include <stdint.h>
-#include <llvm/Support/raw_ostream.h>
-
-
-// ELF structure forward declarations
-template <unsigned Bitwidth> class ELFHeader;
-template <unsigned Bitwidth> class ELFObject;
-template <unsigned Bitwidth> class ELFProgramHeader;
-template <unsigned Bitwidth> class ELFReloc;
-template <unsigned Bitwidth> class ELFRelocRel; // For TypeTraits
-template <unsigned Bitwidth> class ELFRelocRela; // For TypeTraits
-template <unsigned Bitwidth> class ELFSection;
-template <unsigned Bitwidth> class ELFSectionBits;
-template <unsigned Bitwidth> class ELFSectionHeader;
-template <unsigned Bitwidth> class ELFSectionHeaderTable;
-template <unsigned Bitwidth> class ELFSectionNoBits;
-template <unsigned Bitwidth> class ELFSectionProgBits;
-template <unsigned Bitwidth> class ELFSectionRelTable;
-template <unsigned Bitwidth> class ELFSectionStrTab;
-template <unsigned Bitwidth> class ELFSectionSymTab;
-template <unsigned Bitwidth> class ELFSymbol;
-
-// Note: Following TypeTraits specialization MUST be compliant to the
-// System V Application Binary Interface, Chap 4, Data Representation.
-
-TYPE_TRAITS_SPECIALIZE(ELFHeader<32>        , 52, 4)
-TYPE_TRAITS_SPECIALIZE(ELFHeader<64>        , 64, 8)
-
-TYPE_TRAITS_SPECIALIZE(ELFProgramHeader<32> , 32, 4)
-TYPE_TRAITS_SPECIALIZE(ELFProgramHeader<64> , 56, 8)
-
-TYPE_TRAITS_SPECIALIZE(ELFSectionHeader<32> , 40, 4)
-TYPE_TRAITS_SPECIALIZE(ELFSectionHeader<64> , 64, 8)
-
-TYPE_TRAITS_SPECIALIZE(ELFSymbol<32>        , 16, 4)
-TYPE_TRAITS_SPECIALIZE(ELFSymbol<64>        , 24, 8)
-
-TYPE_TRAITS_SPECIALIZE(ELFRelocRel<32>      , 8, 4)
-TYPE_TRAITS_SPECIALIZE(ELFRelocRel<64>      , 16, 8)
-
-TYPE_TRAITS_SPECIALIZE(ELFRelocRela<32>     , 12, 4)
-TYPE_TRAITS_SPECIALIZE(ELFRelocRela<64>     , 24, 8)
-
-
-// ELF primitive type wrappers
-namespace detail {
-#define ELF_TYPE_WRAPPER(TYPE, IMPL)                                        \
-  struct TYPE {                                                             \
-    IMPL value;                                                             \
-                                                                            \
-    TYPE() : value(0) { }                                                   \
-    TYPE(IMPL val) : value(val) { }                                         \
-                                                                            \
-    TYPE &operator=(TYPE const &with) { value = with.value; return *this; } \
-    TYPE &operator=(IMPL val) { value = val; return *this; }                \
-                                                                            \
-    operator IMPL() const { return value; }                                 \
-  };
-
-  ELF_TYPE_WRAPPER(ELFHalf      , uint16_t)
-  ELF_TYPE_WRAPPER(ELFWord      , uint32_t)
-  ELF_TYPE_WRAPPER(ELFSword     , int32_t)
-  ELF_TYPE_WRAPPER(ELFXword     , uint64_t)
-  ELF_TYPE_WRAPPER(ELFSxword    , int64_t)
-  ELF_TYPE_WRAPPER(ELF32Address , uint32_t)
-  ELF_TYPE_WRAPPER(ELF32Offset  , uint32_t)
-  ELF_TYPE_WRAPPER(ELF64Address , uint64_t)
-  ELF_TYPE_WRAPPER(ELF64Offset  , uint64_t)
-
-#undef ELF_TYPE_WRAPPER
-
-  extern llvm::raw_ostream &operator<<(llvm::raw_ostream &,
-                                       ELF32Address const &);
-  extern llvm::raw_ostream &operator<<(llvm::raw_ostream &,
-                                       ELF32Offset const &);
-  extern llvm::raw_ostream &operator<<(llvm::raw_ostream &,
-                                       ELF64Address const &);
-  extern llvm::raw_ostream &operator<<(llvm::raw_ostream &,
-                                       ELF64Offset const &);
-}
-
-// Note: Following TypeTraits specialization MUST be compliant to the
-// System V Application Binary Interface, Chap 4, Data Representation.
-
-TYPE_TRAITS_SPECIALIZE(detail::ELFHalf      , 2, 2)
-TYPE_TRAITS_SPECIALIZE(detail::ELFWord      , 4, 4)
-TYPE_TRAITS_SPECIALIZE(detail::ELFSword     , 4, 4)
-TYPE_TRAITS_SPECIALIZE(detail::ELFXword     , 8, 8)
-TYPE_TRAITS_SPECIALIZE(detail::ELFSxword    , 8, 8)
-TYPE_TRAITS_SPECIALIZE(detail::ELF32Address , 4, 4)
-TYPE_TRAITS_SPECIALIZE(detail::ELF32Offset  , 4, 4)
-TYPE_TRAITS_SPECIALIZE(detail::ELF64Address , 8, 8)
-TYPE_TRAITS_SPECIALIZE(detail::ELF64Offset  , 8, 8)
-
-template <unsigned Bitwidth>
-struct ELFPrimitiveTypes;
-
-template <>
-struct ELFPrimitiveTypes<32> {
-  typedef detail::ELF32Address  address;
-  typedef detail::ELF32Offset   offset;
-
-  typedef unsigned char         byte;
-  typedef detail::ELFHalf       half;
-  typedef detail::ELFWord       word;
-  typedef detail::ELFSword      sword;
-
-  typedef detail::ELFWord       relinfo;
-  typedef detail::ELFSword      addend;
-  typedef detail::ELFWord       symsize;
-
-  // Note: Don't use these types.  They are not in the specification of
-  // ELF 32.  However, we need these typedefs to define the type introduce
-  // macro.
-  typedef void xword;
-  typedef void sxword;
-};
-
-template <>
-struct ELFPrimitiveTypes<64> {
-  typedef detail::ELF64Address  address;
-  typedef detail::ELF64Offset   offset;
-
-  typedef unsigned char         byte;
-  typedef detail::ELFHalf       half;
-  typedef detail::ELFWord       word;
-  typedef detail::ELFSword      sword;
-  typedef detail::ELFXword      xword;
-  typedef detail::ELFSxword     sxword;
-
-  typedef detail::ELFXword      relinfo;
-  typedef detail::ELFSxword     addend;
-  typedef detail::ELFXword      symsize;
-};
-
-
-// Macros to introduce these ELF types to a specific scope
-
-#define ELF_STRUCT_TYPE_INTRO_TO_SCOPE(BITWIDTH)                            \
-  typedef ELFHeader<BITWIDTH>             ELFHeaderTy;                      \
-  typedef ELFObject<BITWIDTH>             ELFObjectTy;                      \
-  typedef ELFProgramHeader<BITWIDTH>      ELFProgramHeaderTy;               \
-  typedef ELFReloc<BITWIDTH>              ELFRelocTy;                       \
-  typedef ELFRelocRel<BITWIDTH>           ELFRelocRelTy;                    \
-  typedef ELFRelocRela<BITWIDTH>          ELFRelocRelaTy;                   \
-  typedef ELFSection<BITWIDTH>            ELFSectionTy;                     \
-  typedef ELFSectionBits<BITWIDTH>        ELFSectionBitsTy;                 \
-  typedef ELFSectionHeader<BITWIDTH>      ELFSectionHeaderTy;               \
-  typedef ELFSectionHeaderTable<BITWIDTH> ELFSectionHeaderTableTy;          \
-  typedef ELFSectionNoBits<BITWIDTH>      ELFSectionNoBitsTy;               \
-  typedef ELFSectionProgBits<BITWIDTH>    ELFSectionProgBitsTy;             \
-  typedef ELFSectionRelTable<BITWIDTH>    ELFSectionRelTableTy;             \
-  typedef ELFSectionStrTab<BITWIDTH>      ELFSectionStrTabTy;               \
-  typedef ELFSectionSymTab<BITWIDTH>      ELFSectionSymTabTy;               \
-  typedef ELFSymbol<BITWIDTH>             ELFSymbolTy;
-
-
-#define ELF_TYPE_INTRO_TO_TEMPLATE_SCOPE(BITWIDTH)                          \
-  /* ELF structures */                                                      \
-  ELF_STRUCT_TYPE_INTRO_TO_SCOPE(BITWIDTH)                                  \
-                                                                            \
-  /* ELF primitives */                                                      \
-  typedef typename ELFPrimitiveTypes<BITWIDTH>::address addr_t;             \
-  typedef typename ELFPrimitiveTypes<BITWIDTH>::offset  offset_t;           \
-  typedef typename ELFPrimitiveTypes<BITWIDTH>::byte    byte_t;             \
-  typedef typename ELFPrimitiveTypes<BITWIDTH>::half    half_t;             \
-  typedef typename ELFPrimitiveTypes<BITWIDTH>::word    word_t;             \
-  typedef typename ELFPrimitiveTypes<BITWIDTH>::sword   sword_t;            \
-  typedef typename ELFPrimitiveTypes<BITWIDTH>::xword   xword_t;            \
-  typedef typename ELFPrimitiveTypes<BITWIDTH>::sxword  sxword_t;           \
-  typedef typename ELFPrimitiveTypes<BITWIDTH>::relinfo relinfo_t;          \
-  typedef typename ELFPrimitiveTypes<BITWIDTH>::addend  addend_t;           \
-  typedef typename ELFPrimitiveTypes<BITWIDTH>::symsize symsize_t;
-
-
-#define ELF_TYPE_INTRO_TO_SCOPE(BITWIDTH)                                   \
-  /* ELF structures */                                                      \
-  ELF_STRUCT_TYPE_INTRO_TO_SCOPE(BITWIDTH)                                  \
-                                                                            \
-  /* ELF primitives */                                                      \
-  typedef ELFPrimitiveTypes<BITWIDTH>::address  addr_t;                     \
-  typedef ELFPrimitiveTypes<BITWIDTH>::offset   offset_t;                   \
-  typedef ELFPrimitiveTypes<BITWIDTH>::byte     byte_t;                     \
-  typedef ELFPrimitiveTypes<BITWIDTH>::half     half_t;                     \
-  typedef ELFPrimitiveTypes<BITWIDTH>::word     word_t;                     \
-  typedef ELFPrimitiveTypes<BITWIDTH>::sword    sword_t;                    \
-  typedef ELFPrimitiveTypes<BITWIDTH>::xword    xword_t;                    \
-  typedef ELFPrimitiveTypes<BITWIDTH>::sxword   sxword_t;                   \
-  typedef ELFPrimitiveTypes<BITWIDTH>::relinfo  relinfo_t;                  \
-  typedef ELFPrimitiveTypes<BITWIDTH>::addend   addend_t;                   \
-  typedef ELFPrimitiveTypes<BITWIDTH>::symsize  symsize_t;
-
-
-#endif // ELF_TYPES_H
diff --git a/cpu_ref/linkloader/include/GOT.h b/cpu_ref/linkloader/include/GOT.h
deleted file mode 100644
index 0b689fe..0000000
--- a/cpu_ref/linkloader/include/GOT.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef GOT_H
-#define GOT_H
-
-#include "utils/rsl_assert.h"
-#include "ELF.h"
-
-#define GP_OFFSET    ((int)0x8000)
-#ifdef __LP64__
-#define GOT_SIZE    (1 << 17) // bytes
-#define GOT_ENTRY_SIZE    8   // bytes
-#else
-#define GOT_SIZE    (1 << 16) // bytes
-#define GOT_ENTRY_SIZE    4   // bytes
-#endif
-#define NUM_OF_GOT_ENTRY  (GOT_SIZE/GOT_ENTRY_SIZE)
-
-void *got_address();
-int search_got(int symbol_index, void *addr, uint8_t bind_type);
-void set_got_address(void *addr);
-
-#endif // GOT_H
diff --git a/cpu_ref/linkloader/include/MemChunk.h b/cpu_ref/linkloader/include/MemChunk.h
deleted file mode 100644
index c4d78c9..0000000
--- a/cpu_ref/linkloader/include/MemChunk.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef MEM_CHUNK_H
-#define MEM_CHUNK_H
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdlib.h>
-
-typedef void *(*AllocFunc) (size_t, uint32_t);
-typedef void (*FreeFunc) (void *);
-
-class MemChunk {
-private:
-  unsigned char *buf;
-  size_t buf_size;
-  bool bVendorBuf;
-
-  static AllocFunc VendorAlloc;
-  static FreeFunc VendorFree;
-
-  bool invalidBuf() const;
-
-public:
-  MemChunk();
-
-  ~MemChunk();
-
-  bool allocate(size_t size);
-
-  void print() const;
-
-  bool protect(int prot);
-
-  unsigned char const *getBuffer() const {
-    return buf;
-  }
-
-  unsigned char *getBuffer() {
-    return buf;
-  }
-
-  unsigned char &operator[](size_t index) {
-    return buf[index];
-  }
-
-  unsigned char const &operator[](size_t index) const {
-    return buf[index];
-  }
-
-  size_t size() const {
-    return buf_size;
-  }
-
-  // The allocation function must return page-aligned memory or we will be
-  // unable to mprotect the region appropriately.
-  static void registerAllocFreeCallbacks(AllocFunc a, FreeFunc f) {
-    VendorAlloc = a;
-    VendorFree = f;
-  }
-};
-
-#endif // MEM_CHUNK_H
diff --git a/cpu_ref/linkloader/include/StubLayout.h b/cpu_ref/linkloader/include/StubLayout.h
deleted file mode 100644
index 0c2e950..0000000
--- a/cpu_ref/linkloader/include/StubLayout.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef STUB_LAYOUT_H
-#define STUB_LAYOUT_H
-
-#include <map>
-#include <stdlib.h>
-
-class StubLayout {
-private:
-  unsigned char *table;
-  size_t count;
-
-  std::map<void *, void *> stub_index;
-
-public:
-  StubLayout();
-  virtual ~StubLayout() { }
-
-  void initStubTable(unsigned char *table, size_t count);
-  void *allocateStub(void *addr = 0);
-
-  size_t calcStubTableSize(size_t count) const;
-  virtual size_t getUnitStubSize() const = 0;
-
-private:
-  virtual void setStubAddress(void *stub, void *addr) = 0;
-
-};
-
-class StubLayoutARM : public StubLayout {
-public:
-  StubLayoutARM() { }
-  size_t getUnitStubSize() const;
-
-private:
-  virtual void setStubAddress(void *stub, void *addr);
-};
-
-class StubLayoutAARCH64 : public StubLayout {
-public:
-  StubLayoutAARCH64() { }
-  size_t getUnitStubSize() const;
-
-private:
-  virtual void setStubAddress(void *stub, void *addr);
-};
-
-class StubLayoutMIPS : public StubLayout {
-public:
-  StubLayoutMIPS() { }
-  size_t getUnitStubSize() const;
-
-private:
-  virtual void setStubAddress(void *stub, void *addr);
-};
-
-class StubLayoutX86 : public StubLayout {
-public:
-  StubLayoutX86() { }
-  size_t getUnitStubSize() const;
-
-private:
-  virtual void setStubAddress(void *stub, void *addr);
-};
-
-class StubLayoutX86_64 : public StubLayout {
-public:
-  StubLayoutX86_64() { }
-  size_t getUnitStubSize() const;
-
-private:
-  virtual void setStubAddress(void *stub, void *addr);
-};
-
-#endif // STUB_LAYOUT_H
diff --git a/cpu_ref/linkloader/include/impl/ELFHeader.hxx b/cpu_ref/linkloader/include/impl/ELFHeader.hxx
deleted file mode 100644
index 993b0e2..0000000
--- a/cpu_ref/linkloader/include/impl/ELFHeader.hxx
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_HEADER_HXX
-#define ELF_HEADER_HXX
-
-#include "utils/raw_ostream.h"
-
-#include <llvm/Support/raw_ostream.h>
-#include <llvm/Support/Format.h>
-
-template <unsigned Bitwidth>
-void ELFHeader<Bitwidth>::print() {
-  using namespace llvm;
-
-  out() << fillformat('=', 79) << '\n';
-  out().changeColor(raw_ostream::WHITE, true);
-  out() << "ELF Header\n";
-  out().resetColor();
-  out() << fillformat('-', 79) << '\n';
-
-#define PRINT_LINT(title, value) \
-  out() << format("  %-32s : ", (char const *)(title)) << (value) << '\n'
-  PRINT_LINT("Class",                 getClassStr(getClass()));
-  PRINT_LINT("Endianness",            getEndiannessStr(getEndianness()));
-  PRINT_LINT("Header Version",        (unsigned)getVersion());
-  PRINT_LINT("OS ABI",                getOSABIStr(getOSABI()));
-  PRINT_LINT("ABI Version",           (unsigned)getABIVersion());
-  PRINT_LINT("Object Type",           getObjectTypeStr(getObjectType()));
-  PRINT_LINT("Machine",               getMachineStr(getMachine()));
-  PRINT_LINT("Version",               getVersionStr(getVersion()));
-  PRINT_LINT("Entry Address",         getEntryAddress());
-  PRINT_LINT("Program Header Offset", getProgramHeaderTableOffset());
-  PRINT_LINT("Section Header Offset", getSectionHeaderTableOffset());
-  PRINT_LINT("Flags",                 getFlags());
-  PRINT_LINT("ELF Header Size",       getELFHeaderSize());
-  PRINT_LINT("Program Header Size",   getProgramHeaderEntrySize());
-  PRINT_LINT("Program Header Num",    getProgramHeaderNum());
-  PRINT_LINT("Section Header Size",   getSectionHeaderEntrySize());
-  PRINT_LINT("Section Header Num",    getSectionHeaderNum());
-  PRINT_LINT("String Section Index",  getStringSectionIndex());
-#undef PRINT_LINT
-
-  out() << fillformat('=', 79) << "\n\n";
-}
-
-#endif // ELF_HEADER_HXX
diff --git a/cpu_ref/linkloader/include/impl/ELFObject.hxx b/cpu_ref/linkloader/include/impl/ELFObject.hxx
deleted file mode 100644
index 8114598..0000000
--- a/cpu_ref/linkloader/include/impl/ELFObject.hxx
+++ /dev/null
@@ -1,1378 +0,0 @@
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_OBJECT_HXX
-#define ELF_OBJECT_HXX
-
-#include <android/log.h>
-
-#include "ELFHeader.h"
-#include "ELFReloc.h"
-#include "ELFSection.h"
-#include "ELFSectionHeaderTable.h"
-#include "StubLayout.h"
-#include "GOT.h"
-#include "ELF.h"
-
-#include <llvm/ADT/SmallVector.h>
-
-#include "utils/rsl_assert.h"
-
-
-template <unsigned Bitwidth>
-template <typename Archiver>
-inline ELFObject<Bitwidth> *
-ELFObject<Bitwidth>::read(Archiver &AR) {
-  std::unique_ptr<ELFObjectTy> object(new ELFObjectTy());
-
-  // Read header
-  object->header.reset(ELFHeaderTy::read(AR));
-  if (!object->header) {
-    return 0;
-  }
-
-  // Read section table
-  object->shtab.reset(ELFSectionHeaderTableTy::read(AR, object.get()));
-  if (!object->shtab) {
-    return 0;
-  }
-
-  // Read each section
-  llvm::SmallVector<size_t, 4> progbits_ndx;
-  for (size_t i = 0; i < object->header->getSectionHeaderNum(); ++i) {
-    if ((*object->shtab)[i]->getType() == SHT_PROGBITS) {
-      object->stab.push_back(NULL);
-      progbits_ndx.push_back(i);
-    } else {
-      std::unique_ptr<ELFSectionTy> sec(
-        ELFSectionTy::read(AR, object.get(), (*object->shtab)[i]));
-      object->stab.push_back(sec.release());
-    }
-  }
-
-  object->shtab->buildNameMap();
-  ELFSectionSymTabTy *symtab =
-    static_cast<ELFSectionSymTabTy *>(object->getSectionByName(".symtab"));
-  rsl_assert(symtab && "Symtab is required.");
-  symtab->buildNameMap();
-
-  for (size_t i = 0; i < progbits_ndx.size(); ++i) {
-    size_t index = progbits_ndx[i];
-
-    std::unique_ptr<ELFSectionTy> sec(
-      ELFSectionTy::read(AR, object.get(), (*object->shtab)[index]));
-    object->stab[index] = sec.release();
-  }
-
-  return object.release();
-}
-
-template <unsigned Bitwidth>
-inline char const *ELFObject<Bitwidth>::getSectionName(size_t i) const {
-  ELFSectionTy const *sec = stab[header->getStringSectionIndex()];
-
-  if (sec) {
-    ELFSectionStrTabTy const &st =
-      static_cast<ELFSectionStrTabTy const &>(*sec);
-    return st[i];
-  }
-
-  return NULL;
-}
-
-template <unsigned Bitwidth>
-inline ELFSection<Bitwidth> const *
-ELFObject<Bitwidth>::getSectionByIndex(size_t i) const {
-  return stab[i];
-}
-
-template <unsigned Bitwidth>
-inline ELFSection<Bitwidth> *
-ELFObject<Bitwidth>::getSectionByIndex(size_t i) {
-  return stab[i];
-}
-
-template <unsigned Bitwidth>
-inline ELFSection<Bitwidth> const *
-ELFObject<Bitwidth>::getSectionByName(std::string const &str) const {
-  size_t idx = getSectionHeaderTable()->getByName(str)->getIndex();
-  return stab[idx];
-}
-
-template <unsigned Bitwidth>
-inline ELFSection<Bitwidth> *
-ELFObject<Bitwidth>::getSectionByName(std::string const &str) {
-  ELFObjectTy const *const_this = this;
-  ELFSectionTy const *sptr = const_this->getSectionByName(str);
-  // Const cast for the same API's const and non-const versions.
-  return const_cast<ELFSectionTy *>(sptr);
-}
-
-
-template <unsigned Bitwidth>
-inline void ELFObject<Bitwidth>::
-relocateARM(void *(*find_sym)(void *context, char const *name),
-            void *context,
-            ELFSectionRelTableTy *reltab,
-            ELFSectionProgBitsTy *text) {
-  // FIXME: Should be implement in independent files.
-  rsl_assert(Bitwidth == 32 && "ARM only have 32 bits.");
-
-  ELFSectionSymTabTy *symtab =
-    static_cast<ELFSectionSymTabTy *>(getSectionByName(".symtab"));
-  rsl_assert(symtab && "Symtab is required.");
-
-  for (size_t i = 0; i < reltab->size(); ++i) {
-    // FIXME: Can not implement here, use Fixup!
-    ELFRelocTy *rel = (*reltab)[i];
-    ELFSymbolTy *sym = (*symtab)[rel->getSymTabIndex()];
-
-    // FIXME: May be not uint32_t *.
-    typedef int32_t Inst_t;
-    Inst_t *inst = (Inst_t *)&(*text)[rel->getOffset()];
-    Inst_t P = (Inst_t)(int64_t)inst;
-    Inst_t A = 0;
-    Inst_t S = (Inst_t)(int64_t)sym->getAddress(EM_ARM);
-    Inst_t T = 0;
-
-    if (sym->isConcreteFunc() && (sym->getValue() & 0x1)) {
-      T = 1;
-    }
-    relinfo_t reltype = rel->getType();
-    switch (reltype) {
-    default:
-      rsl_assert(0 && "Not implemented relocation type.");
-      break;
-
-    case R_ARM_ABS32:
-      {
-        if (S == 0 && sym->getType() == STT_NOTYPE) {
-          void *ext_sym = find_sym(context, sym->getName());
-          if (!ext_sym) {
-            missingSymbols = true;
-          }
-          S = (Inst_t)(uintptr_t)ext_sym;
-          sym->setAddress(ext_sym);
-        }
-        A = *inst;
-        *inst = (S + A) | T;
-      }
-      break;
-
-      // FIXME: Predefine relocation codes.
-    case R_ARM_CALL:
-    case R_ARM_THM_CALL:
-    case R_ARM_JUMP24:
-    case R_ARM_THM_JUMP24:
-      {
-#define SIGN_EXTEND(x, l) (((x)^(1<<((l)-1)))-(1<<(l-1)))
-        if (reltype == R_ARM_CALL || reltype == R_ARM_JUMP24) {
-          A = (Inst_t)(int64_t)SIGN_EXTEND(*inst & 0xFFFFFF, 24);
-          A <<= 2;
-        } else {
-          // Hack for two 16bit.
-          *inst = ((*inst >> 16) & 0xFFFF) | (*inst << 16);
-          Inst_t s  = (*inst >> 26) & 0x1u,    // 26
-                 u  = (*inst >> 16) & 0x3FFu,  // 25-16
-                 l  =  *inst        & 0x7FFu, // 10-0
-                 j1 = (*inst >> 13) & 0x1u,    // 13
-                 j2 = (*inst >> 11) & 0x1u;    // 11
-          Inst_t i1 = (~(j1 ^ s)) & 0x1u,
-                 i2 = (~(j2 ^ s)) & 0x1u;
-          // [31-25][24][23][22][21-12][11-1][0]
-          //      0   s  i1  i2      u     l  0
-          A = SIGN_EXTEND((s << 23) | (i1 << 22) | (i2 << 21) | (u << 11) | l, 24);
-          A <<= 1;
-        }
-#undef SIGN_EXTEND
-
-        void *callee_addr = sym->getAddress(EM_ARM);
-
-        switch (sym->getType()) {
-        default:
-          rsl_assert(0 && "Wrong type for R_ARM_CALL relocation.");
-          abort();
-          break;
-
-        case STT_FUNC:
-          // NOTE: Callee function is in the object file, but it may be
-          // in different PROGBITS section (which may be far call).
-
-          if (callee_addr == 0) {
-            rsl_assert(0 && "We should get function address at previous "
-                   "sym->getAddress(EM_ARM) function call.");
-            abort();
-          }
-          break;
-
-        case STT_NOTYPE:
-          // NOTE: Callee function is an external function.  Call find_sym
-          // if it has not resolved yet.
-
-          if (callee_addr == 0) {
-            callee_addr = find_sym(context, sym->getName());
-            if (!callee_addr) {
-              missingSymbols = true;
-            }
-            sym->setAddress(callee_addr);
-          }
-          break;
-        }
-
-        // Get the stub for this function
-        StubLayout *stub_layout = text->getStubLayout();
-
-        if (!stub_layout) {
-          llvm::errs() << "unable to get stub layout." << "\n";
-          abort();
-        }
-
-        void *stub = stub_layout->allocateStub(callee_addr);
-
-        if (!stub) {
-          llvm::errs() << "unable to allocate stub." << "\n";
-          abort();
-        }
-
-        //LOGI("Function %s: using stub %p\n", sym->getName(), stub);
-        S = (uint32_t)(uintptr_t)stub;
-
-        if (reltype == R_ARM_CALL || reltype == R_ARM_JUMP24) {
-          // Relocate the R_ARM_CALL relocation type
-          uint32_t result = (S + A - P) >> 2;
-
-          if (result > 0x007FFFFF && result < 0xFF800000) {
-            rsl_assert(0 && "Stub is still too far");
-            abort();
-          }
-
-          *inst = ((result) & 0x00FFFFFF) | (*inst & 0xFF000000);
-        } else {
-          P &= ~0x3;  // Base address align to 4 bytes.  (For BLX.)
-
-          // Relocate the R_ARM_THM_CALL relocation type
-          uint32_t result = (S + A - P) >> 1;
-
-          if (result > 0x007FFFFF && result < 0xFF800000) {
-            rsl_assert(0 && "Stub is still too far");
-            abort();
-          }
-
-          //*inst &= 0xF800D000u;
-          // Rewrite instruction to BLX.  (Stub is always ARM.)
-          *inst &= 0xF800C000u;
-          // [31-25][24][23][22][21-12][11-1][0]
-          //      0   s  i1  i2      u     l  0
-          Inst_t s  = (result >> 23) & 0x1u,   // 26
-                 u  = (result >> 11) & 0x3FFu, // 25-16
-                 // For BLX, bit [0] is 0.
-                 l  =  result        & 0x7FEu, // 10-0
-                 i1 = (result >> 22) & 0x1u,
-                 i2 = (result >> 21) & 0x1u;
-          Inst_t j1 = ((~i1) ^ s) & 0x01u,       // 13
-                 j2 = ((~i2) ^ s) & 0x01u;       // 11
-          *inst |= s << 26;
-          *inst |= u << 16;
-          *inst |= l;
-          *inst |= j1 << 13;
-          *inst |= j2 << 11;
-          // Hack for two 16bit.
-          *inst = ((*inst >> 16) & 0xFFFF) | (*inst << 16);
-        }
-      }
-      break;
-    case R_ARM_MOVT_ABS:
-    case R_ARM_MOVW_ABS_NC:
-    case R_ARM_THM_MOVW_ABS_NC:
-    case R_ARM_THM_MOVT_ABS:
-      {
-        if (S == 0 && sym->getType() == STT_NOTYPE) {
-          void *ext_sym = find_sym(context, sym->getName());
-          if (!ext_sym) {
-            missingSymbols = true;
-          }
-          S = (Inst_t)(uintptr_t)ext_sym;
-          sym->setAddress(ext_sym);
-        }
-        if (reltype == R_ARM_MOVT_ABS
-            || reltype == R_ARM_THM_MOVT_ABS) {
-          S >>= 16;
-        }
-
-        if (reltype == R_ARM_MOVT_ABS
-            || reltype == R_ARM_MOVW_ABS_NC) {
-          // No need sign extend.
-          A = ((*inst & 0xF0000) >> 4) | (*inst & 0xFFF);
-          uint32_t result = (S + A);
-          *inst = (((result) & 0xF000) << 4) |
-            ((result) & 0xFFF) |
-            (*inst & 0xFFF0F000);
-        } else {
-          // Hack for two 16bit.
-          *inst = ((*inst >> 16) & 0xFFFF) | (*inst << 16);
-          // imm16: [19-16][26][14-12][7-0]
-          A = (((*inst >>  4) & 0xF000u) |
-               ((*inst >> 15) & 0x0800u) |
-               ((*inst >>  4) & 0x0700u) |
-               ( *inst        & 0x00FFu));
-          uint32_t result;
-          if (reltype == R_ARM_THM_MOVT_ABS) {
-            result = (S + A);
-          } else {
-            result = (S + A) | T;
-          }
-          // imm16: [19-16][26][14-12][7-0]
-          *inst &= 0xFBF08F00u;
-          *inst |= (result & 0xF000u) << 4;
-          *inst |= (result & 0x0800u) << 15;
-          *inst |= (result & 0x0700u) << 4;
-          *inst |= (result & 0x00FFu);
-          // Hack for two 16bit.
-          *inst = ((*inst >> 16) & 0xFFFF) | (*inst << 16);
-        }
-      }
-      break;
-    }
-    //llvm::errs() << "S:     " << (void *)S << '\n';
-    //llvm::errs() << "A:     " << (void *)A << '\n';
-    //llvm::errs() << "P:     " << (void *)P << '\n';
-    //llvm::errs() << "S+A:   " << (void *)(S+A) << '\n';
-    //llvm::errs() << "S+A-P: " << (void *)(S+A-P) << '\n';
-  }
-}
-
-template <unsigned Bitwidth>
-inline void ELFObject<Bitwidth>::
-relocateAARCH64(void *(*find_sym)(void *context, char const *name),
-            void *context,
-            ELFSectionRelTableTy *reltab,
-            ELFSectionProgBitsTy *text) {
-  // FIXME: Should be implement in independent files.
-  rsl_assert(Bitwidth == 64 && "AARCH64 only have 64 bits.");
-
-  // Change this to true to enable some debugging in the log.
-  const bool kDebugSymbolPrint = false;
-
-  ELFSectionSymTabTy *symtab =
-    static_cast<ELFSectionSymTabTy *>(getSectionByName(".symtab"));
-  rsl_assert(symtab && "Symtab is required.");
-
-  for (size_t i = 0; i < reltab->size(); ++i) {
-    ELFRelocTy *rel = (*reltab)[i];
-    ELFSymbolTy *sym = (*symtab)[rel->getSymTabIndex()];
-
-    typedef int64_t Inst_t;
-    Inst_t *inst = (Inst_t *)&(*text)[rel->getOffset()];
-    int32_t* inst32 = reinterpret_cast<int32_t*>(inst);
-    int16_t* inst16 = reinterpret_cast<int16_t*>(inst);
-    Inst_t P = (Inst_t)(int64_t)inst;
-    Inst_t A = 0;
-    Inst_t S = (Inst_t)(int64_t)sym->getAddress(EM_AARCH64);
-    Inst_t Page_P = P & ~0xfff;         // Page address.
-
-    if (S == 0 && sym->getType() == STT_NOTYPE) {
-      void *ext_sym = find_sym(context, sym->getName());
-      if (!ext_sym) {
-        missingSymbols = true;
-      }
-      S = (Inst_t)(uintptr_t)ext_sym;
-      sym->setAddress(ext_sym);
-    }
-
-    if (kDebugSymbolPrint) {
-      __android_log_print(ANDROID_LOG_INFO, "rs", "AARCH64 relocation symbol %s value is %llx\n",
-          sym->getName(), (unsigned long long)S);
-    }
-
-    // TODO: add other relocations when we know what ones are used.
-    relinfo_t reltype = rel->getType();
-    switch (reltype) {
-    default:
-      __android_log_print(ANDROID_LOG_ERROR, "rs",
-        "Unimplemented AARCH64 relocation type %d(0x%x)\n", static_cast<uint32_t>(reltype),
-        static_cast<uint32_t>(reltype));
-      rsl_assert(0 && "Unimplemented relocation type.");
-      break;
-
-    case R_AARCH64_ABS64:
-        A = *inst + rel->getAddend();
-        *inst = S + A;
-      break;
-
-    case R_AARCH64_ABS32:
-        A = *inst + rel->getAddend();
-        *inst32 = static_cast<int32_t>(S + A);
-      break;
-
-    case R_AARCH64_ABS16:
-        A = *inst + rel->getAddend();
-        *inst16 = static_cast<int16_t>(S + A);
-      break;
-
-    case R_AARCH64_PREL64:
-        A = *inst + rel->getAddend();
-        *inst = S + A - P;
-      break;
-
-    case R_AARCH64_PREL32:
-        A = *inst32 + rel->getAddend();
-        *inst32 = static_cast<int32_t>(S + A - P);
-      break;
-
-    case R_AARCH64_PREL16:
-        A = *inst16 + rel->getAddend();
-        *inst16 = static_cast<int16_t>(S + A - P);
-      break;
-
-    case R_AARCH64_ADR_PREL_PG_HI21:
-      // Relocate an ADRP instruction to the page
-      {
-        A = rel->getAddend();
-        int32_t immed = ((S + A) & ~0xfff) - Page_P;
-        immed >>= 12;
-        uint32_t immlo = immed & 0b11;              // 2 bits.
-        uint32_t immhi = (immed >> 2) & 0x7FFFF;   // 19 bits.
-        *inst32 |= static_cast<int32_t>(immlo << 29 | immhi << 5);
-      }
-      break;
-
-    case R_AARCH64_ADR_PREL_LO21:
-      {
-        A = rel->getAddend();
-        int32_t immed = S + A - P;
-        uint32_t immlo = immed & 0b11;              // 2 bits.
-        uint32_t immhi = (immed >> 2) & 0x7FFFF;   // 19 bits.
-        *inst32 |= static_cast<int32_t>(immlo << 29 | immhi << 5);
-      }
-      break;
-
-    case R_AARCH64_ADD_ABS_LO12_NC:
-      // ADD instruction immediate value.
-      {
-        A = rel->getAddend();
-        int32_t immed = S + A;
-        uint32_t imm12 = (immed & 0xFFF);   // 12 bits.
-        *inst32 |= static_cast<int32_t>(imm12 << 10);
-      }
-      break;
-
-    case R_AARCH64_LDST8_ABS_LO12_NC:
-    case R_AARCH64_LDST16_ABS_LO12_NC:
-    case R_AARCH64_LDST32_ABS_LO12_NC:
-    case R_AARCH64_LDST64_ABS_LO12_NC:
-    case R_AARCH64_LDST128_ABS_LO12_NC:
-      {
-        // Set LD/ST (unsigned) immediate instruction to the low 12 bits, shifted depending
-        // on relocation.
-        A = rel->getAddend();
-        uint32_t shift = 0;
-        switch (reltype) {
-          case R_AARCH64_LDST8_ABS_LO12_NC: shift = 0; break;
-          case R_AARCH64_LDST16_ABS_LO12_NC: shift = 1; break;
-          case R_AARCH64_LDST32_ABS_LO12_NC: shift = 2; break;
-          case R_AARCH64_LDST64_ABS_LO12_NC: shift = 3; break;
-          case R_AARCH64_LDST128_ABS_LO12_NC: shift = 4; break;
-          default:
-            rsl_assert("Cannot reach");
-        }
-
-        // Form imm12 by taking 12 bits and shifting by appropriate amount.
-        uint32_t imm12 = ((S + A) & 0xFFF) >> shift;
-
-        // Put it into the instruction.
-        *inst32 |= static_cast<int32_t>(imm12 << 10);
-      }
-      break;
-
-    case R_AARCH64_CALL26:
-    case R_AARCH64_JUMP26:
-      {
-#define SIGN_EXTEND(x, l) (((x)^(1<<((l)-1)))-(1<<(l-1)))
-        A = (Inst_t)(int64_t)SIGN_EXTEND(*inst32 & 0x3FFFFFF, 26);
-        A <<= 2;
-#undef SIGN_EXTEND
-
-        void *callee_addr = sym->getAddress(EM_AARCH64);
-        bool call_via_stub = false;     // Call via a stub (linker veneer).
-
-        switch (sym->getType()) {
-        default:
-          rsl_assert(0 && "Wrong type for R_ARM_CALL relocation.");
-          abort();
-          break;
-
-        case STT_FUNC:
-          // NOTE: Callee function is in the object file, but it may be
-          // in different PROGBITS section (which may be far call).
-
-          if (callee_addr == 0) {
-            rsl_assert(0 && "We should get function address at previous "
-                   "sym->getAddress(EM_ARM) function call.");
-            abort();
-          }
-          break;
-
-        case STT_NOTYPE:
-          // NOTE: Callee function is an external function.  Call find_sym
-          // if it has not resolved yet.
-
-          if (callee_addr == 0) {
-            callee_addr = find_sym(context, sym->getName());
-            if (!callee_addr) {
-              missingSymbols = true;
-            }
-            sym->setAddress(callee_addr);
-          }
-          break;
-        }
-
-        S = reinterpret_cast<int64_t>(callee_addr);
-        uint32_t result = (S + A - P) >> 2;
-
-        // See if we can do the branch without a stub.
-        if (result > 0x01FFFFFF && result < 0xFE000000) {
-          // Not in range, need a stub.
-          call_via_stub = true;
-        }
-
-        // Calling via a stub makes a BL instruction to a stub containing the following code:
-        // ldr x16, addr
-        // br x16
-        // addr:
-        // .word low32
-        // .word high32
-        //
-        // This loads the PC value from the 64 bits at PC + 8.  Since AARCH64 can't
-        // manipulate the PC directly we have to load a register and branch to the contents.
-        if (call_via_stub) {
-          // Get the stub for this function
-          StubLayout *stub_layout = text->getStubLayout();
-
-          if (!stub_layout) {
-            __android_log_print(ANDROID_LOG_ERROR, "rs", "unable to get stub layout\n");
-            llvm::errs() << "unable to get stub layout." << "\n";
-            abort();
-          }
-
-          void *stub = stub_layout->allocateStub(callee_addr);
-
-          if (!stub) {
-            __android_log_print(ANDROID_LOG_ERROR, "rs", "unable to allocate stub\n");
-            llvm::errs() << "unable to allocate stub." << "\n";
-            abort();
-          }
-
-          //LOGI("Function %s: using stub %p\n", sym->getName(), stub);
-          S = (uint64_t)(uintptr_t)stub;
-
-          result = (S + A - P) >> 2;
-
-          if (result > 0x01FFFFFF && result < 0xFE000000) {
-            __android_log_print(ANDROID_LOG_ERROR, "rs", "stub is still too far\n");
-            rsl_assert(0 && "Stub is still too far");
-            abort();
-          }
-        }
-
-        // 'result' contains the offset from PC to the destination address, encoded
-        // in the correct form for the BL or B instructions.
-        *inst32 = (result & 0x03FFFFFF) | (*inst & 0xFC000000);
-      }
-      break;
-    case R_AARCH64_MOVW_UABS_G0:
-    case R_AARCH64_MOVW_UABS_G0_NC:
-    case R_AARCH64_MOVW_UABS_G1:
-    case R_AARCH64_MOVW_UABS_G1_NC:
-    case R_AARCH64_MOVW_UABS_G2:
-    case R_AARCH64_MOVW_UABS_G2_NC:
-    case R_AARCH64_MOVW_UABS_G3:
-      {
-        int shift = 0;
-        switch (reltype) {
-        case R_AARCH64_MOVW_UABS_G0:
-        case R_AARCH64_MOVW_UABS_G0_NC: shift = 0; break;
-        case R_AARCH64_MOVW_UABS_G1:
-        case R_AARCH64_MOVW_UABS_G1_NC: shift = 16; break;
-        case R_AARCH64_MOVW_UABS_G2:
-        case R_AARCH64_MOVW_UABS_G2_NC: shift = 32; break;
-        case R_AARCH64_MOVW_UABS_G3: shift = 48; break;
-        }
-
-        A = (*inst32 >> 5) & 0xFFFF;
-        uint32_t value = ((S + A) >> shift) & 0xFFFF;
-        *inst32 = (*inst32 & ~(0xFFFF << 6)) | (value << 6);
-      }
-      break;
-
-    case R_AARCH64_MOVW_SABS_G0:
-    case R_AARCH64_MOVW_SABS_G1:
-    case R_AARCH64_MOVW_SABS_G2:
-      {
-        int shift = 0;
-        switch (reltype) {
-        case R_AARCH64_MOVW_SABS_G0: shift = 0; break;
-        case R_AARCH64_MOVW_SABS_G1: shift = 16; break;
-        case R_AARCH64_MOVW_SABS_G2: shift = 32; break;
-        }
-
-        A = (*inst32 >> 5) & 0xFFFF;
-        int32_t value = ((S + A) >> shift) & 0xFFFF;
-
-        *inst32 = (*inst32 & ~(0xFFFF << 6)) | (value << 6);
-
-        // This relocation type must also set the instruction bit 30 to 0 or 1
-        // depending on the sign of the value.  The bit corresponds to the
-        // movz or movn encoding.  A value of 0 means movn.
-        if (value >= 0) {
-          // Set the instruction to movz (set bit 30 to 1)
-          *inst32 |= 0x40000000;
-        } else {
-          // Set the instruction to movn (set bit 30 to 0)
-          *inst32 &= ~0x40000000;
-        }
-      }
-      break;
-    }
-    //llvm::errs() << "S:     " << (void *)S << '\n';
-    //llvm::errs() << "A:     " << (void *)A << '\n';
-    //llvm::errs() << "P:     " << (void *)P << '\n';
-    //llvm::errs() << "S+A:   " << (void *)(S+A) << '\n';
-    //llvm::errs() << "S+A-P: " << (void *)(S+A-P) << '\n';
-  }
-}
-
-template <unsigned Bitwidth>
-inline void ELFObject<Bitwidth>::
-relocateX86_64(void *(*find_sym)(void *context, char const *name),
-               void *context,
-               ELFSectionRelTableTy *reltab,
-               ELFSectionProgBitsTy *text) {
-  rsl_assert(Bitwidth == 64 && "Only support X86_64.");
-
-  ELFSectionSymTabTy *symtab =
-    static_cast<ELFSectionSymTabTy *>(getSectionByName(".symtab"));
-  rsl_assert(symtab && "Symtab is required.");
-
-  for (size_t i = 0; i < reltab->size(); ++i) {
-    // FIXME: Can not implement here, use Fixup!
-    ELFRelocTy *rel = (*reltab)[i];
-    ELFSymbolTy *sym = (*symtab)[rel->getSymTabIndex()];
-
-    typedef intptr_t Inst_t;
-    Inst_t *inst = (Inst_t*)&(*text)[rel->getOffset()];
-    Inst_t P = (Inst_t)inst;
-    Inst_t A = (Inst_t)rel->getAddend();
-    Inst_t S = (Inst_t)sym->getAddress(EM_X86_64);
-
-    if (S == 0) {
-      S = (Inst_t)find_sym(context, sym->getName());
-      if (!S) {
-        missingSymbols = true;
-      }
-      sym->setAddress((void *)S);
-    }
-
-    switch (rel->getType()) {
-    default:
-      rsl_assert(0 && "Not implemented relocation type.");
-      break;
-
-    // FIXME, consider other relocation types if RS support dynamic reolcations in future.
-    case R_X86_64_64: {//Direct 64-bit.
-      int64_t *paddr = (int64_t*)&(*text)[rel->getOffset()];
-      int64_t vAddr = S + A;
-      *paddr = vAddr;
-      break;
-    }
-    case R_X86_64_PC32: {//PC relative 32-bit signed.
-      int32_t *paddr = (int32_t*)&(*text)[rel->getOffset()];
-      int64_t vOffset = S + A - P;
-
-      if (vOffset > INT32_MAX || vOffset < INT32_MIN) {
-        // Not in range, need a stub.
-        StubLayout *stub_layout = text->getStubLayout();
-        if (!stub_layout) {
-          __android_log_print(ANDROID_LOG_ERROR, "rs", "unable to get stub layout\n");
-          llvm::errs() << "unable to get stub layout." << "\n";
-          abort();
-        }
-
-        void *stub = stub_layout->allocateStub((void *)S);
-
-        if (!stub) {
-          __android_log_print(ANDROID_LOG_ERROR, "rs", "unable to allocate stub\n");
-          llvm::errs() << "unable to allocate stub." << "\n";
-          abort();
-        }
-
-        S = (Inst_t)stub;
-        vOffset = S + A - P;
-
-        if (vOffset > INT32_MAX || vOffset < INT32_MIN) {
-          __android_log_print(ANDROID_LOG_ERROR, "rs", "stub is still too far\n");
-          rsl_assert(0 && "Stub is still too far");
-          abort();
-        }
-      }
-
-      rsl_assert(vOffset <= INT32_MAX && vOffset >= INT32_MIN);
-      *paddr = (int32_t)(vOffset & 0xFFFFFFFF);
-      break;
-    }
-    case R_X86_64_32: {//Direct 32-bit zero-extended.
-      uint32_t *paddr = (uint32_t*)&(*text)[rel->getOffset()];
-      int64_t vAddr = S + A;
-      rsl_assert(vAddr <= UINT32_MAX);
-      *paddr = (uint32_t)(vAddr & 0xFFFFFFFF);
-      break;
-    }
-    case R_X86_64_32S: {//Direct 32-bit sign-extended.
-      int32_t *paddr = (int32_t*)&(*text)[rel->getOffset()];
-      int64_t vAddr = S + A;
-      rsl_assert(vAddr <= INT32_MAX && vAddr >= INT32_MIN);
-      *paddr = (uint32_t)(vAddr & 0xFFFFFFFF);
-      break;
-    }
-    case R_X86_64_16: {//Direct 16-bit zero-extended.
-      uint16_t *paddr = (uint16_t*)&(*text)[rel->getOffset()];
-      int64_t vAddr = S + A;
-      rsl_assert(vAddr <= UINT16_MAX);
-      *paddr = (uint16_t)(vAddr & 0xFFFF);
-      break;
-    }
-    case R_X86_64_PC16: {//16-bit sign-extended PC relative.
-      int16_t *paddr = (int16_t*)&(*text)[rel->getOffset()];
-      int64_t vOffset = S + A - P;
-      rsl_assert(vOffset <= INT16_MAX && vOffset >= INT16_MIN);
-      *paddr = (int16_t)(vOffset & 0xFFFF);
-      break;
-    }
-    case R_X86_64_8: {//Direct 8-bit sign-extended.
-      int8_t *paddr = (int8_t*)&(*text)[rel->getOffset()];
-      int64_t vAddr = S + A;
-      rsl_assert(vAddr <= INT8_MAX && vAddr >= INT8_MIN);
-      *paddr = (uint8_t)(vAddr & 0xFF);
-      break;
-    }
-    case R_X86_64_PC8: {//8-bit sign-extended PC relative.
-      int8_t *paddr = (int8_t*)&(*text)[rel->getOffset()];
-      int64_t vOffset = S + A - P;
-      rsl_assert(vOffset <= INT8_MAX && vOffset >= INT8_MIN);
-      *paddr = (int8_t)(vOffset & 0xFF);
-      break;
-    }
-    case R_X86_64_PC64: {//PC relative 64-bit.
-      int64_t *paddr = (int64_t*)&(*text)[rel->getOffset()];
-      *paddr = (int64_t)(S + A - P);
-      break;
-    }
-    }
-  }
-}
-
-template <unsigned Bitwidth>
-inline void ELFObject<Bitwidth>::
-relocateX86_32(void *(*find_sym)(void *context, char const *name),
-               void *context,
-               ELFSectionRelTableTy *reltab,
-               ELFSectionProgBitsTy *text) {
-  rsl_assert(Bitwidth == 32 && "Only support X86.");
-
-  ELFSectionSymTabTy *symtab =
-    static_cast<ELFSectionSymTabTy *>(getSectionByName(".symtab"));
-  rsl_assert(symtab && "Symtab is required.");
-
-  for (size_t i = 0; i < reltab->size(); ++i) {
-    // FIXME: Can not implement here, use Fixup!
-    ELFRelocTy *rel = (*reltab)[i];
-    ELFSymbolTy *sym = (*symtab)[rel->getSymTabIndex()];
-
-    typedef intptr_t Inst_t;
-    Inst_t *inst = (Inst_t *)&(*text)[rel->getOffset()];
-    Inst_t P = (Inst_t)inst;
-    Inst_t A = (Inst_t)*inst;
-    Inst_t S = (Inst_t)sym->getAddress(EM_386);
-
-    if (S == 0) {
-      S = (Inst_t)find_sym(context, sym->getName());
-      if (!S) {
-        missingSymbols = true;
-      }
-      sym->setAddress((void *)S);
-    }
-
-    switch (rel->getType()) {
-    default:
-      rsl_assert(0 && "Not implemented relocation type.");
-      break;
-
-    case R_386_PC32: {//Add PC-relative symbol value.
-      int32_t *paddr = (int32_t*)&(*text)[rel->getOffset()];
-      *paddr = (int32_t)(S + A - P);
-      break;
-    }
-    case R_386_32: {//Add symbol value.
-      uint32_t *paddr = (uint32_t*)&(*text)[rel->getOffset()];
-      *paddr = (uint32_t)(S + A);
-      break;
-    }
-    }
-  }
-}
-
-template <unsigned Bitwidth>
-inline void ELFObject<Bitwidth>::
-relocateMIPS(void *(*find_sym)(void *context, char const *name),
-             void *context,
-             ELFSectionRelTableTy *reltab,
-             ELFSectionProgBitsTy *text) {
-  rsl_assert(Bitwidth == 32 && "Only support 32-bit MIPS.");
-
-  ELFSectionSymTabTy *symtab =
-    static_cast<ELFSectionSymTabTy *>(getSectionByName(".symtab"));
-  rsl_assert(symtab && "Symtab is required.");
-
-  for (size_t i = 0; i < reltab->size(); ++i) {
-    // FIXME: Can not implement here, use Fixup!
-    ELFRelocTy *rel = (*reltab)[i];
-    ELFSymbolTy *sym = (*symtab)[rel->getSymTabIndex()];
-
-    typedef int32_t Inst_t;
-    Inst_t *inst = (Inst_t *)&(*text)[rel->getOffset()];
-    Inst_t P = (Inst_t)(uintptr_t)inst;
-    Inst_t A = (Inst_t)(uintptr_t)*inst;
-    Inst_t S = (Inst_t)(uintptr_t)sym->getAddress(EM_MIPS);
-
-    bool need_stub = false;
-
-    if (S == 0 && strcmp (sym->getName(), "_gp_disp") != 0) {
-      need_stub = true;
-      S = (Inst_t)(uintptr_t)find_sym(context, sym->getName());
-      if (!S) {
-        missingSymbols = true;
-      }
-#if defined(__LP64__) || defined(__x86_64__)
-      llvm::errs() << "Code temporarily disabled for 64bit build";
-      abort();
-#else
-      sym->setAddress((void *)S);
-#endif
-    }
-
-    switch (rel->getType()) {
-    default:
-      rsl_assert(0 && "Not implemented relocation type.");
-      break;
-
-    case R_MIPS_NONE:
-    case R_MIPS_JALR: // ignore this
-      break;
-
-    case R_MIPS_16:
-      *inst &= 0xFFFF0000;
-      A = A & 0xFFFF;
-      A = S + (short)A;
-      rsl_assert(A >= -32768 && A <= 32767 && "R_MIPS_16 overflow.");
-      *inst |= (A & 0xFFFF);
-      break;
-
-    case R_MIPS_32:
-      *inst = S + A;
-      break;
-
-    case R_MIPS_26:
-      *inst &= 0xFC000000;
-      if (need_stub == false) {
-        A = (A & 0x3FFFFFF) << 2;
-        if (sym->getBindingAttribute() == STB_LOCAL) { // local binding
-          A |= ((P + 4) & 0xF0000000);
-          A += S;
-          *inst |= ((A >> 2) & 0x3FFFFFF);
-        } else { // external binding
-          if (A & 0x08000000) // Sign extend from bit 27
-            A |= 0xF0000000;
-          A += S;
-          *inst |= ((A >> 2) & 0x3FFFFFF);
-          if (((P + 4) >> 28) != (A >> 28)) { // far local call
-#if defined(__LP64__) || defined(__x86_64__)
-            llvm::errs() << "Code temporarily disabled for 64bit build";
-            abort();
-            void* stub = NULL;
-#else
-            void *stub = text->getStubLayout()->allocateStub((void *)A);
-#endif
-            rsl_assert(stub && "cannot allocate stub.");
-            sym->setAddress(stub);
-            S = (int32_t)(intptr_t)stub;
-            *inst |= ((S >> 2) & 0x3FFFFFF);
-            rsl_assert(((P + 4) >> 28) == (S >> 28) && "stub is too far.");
-          }
-        }
-      } else { // shared-library call
-        A = (A & 0x3FFFFFF) << 2;
-        rsl_assert(A == 0 && "R_MIPS_26 addend is not zero.");
-#if defined(__LP64__) || defined(__x86_64__)
-        llvm::errs() << "Code temporarily disabled for 64bit build";
-        abort();
-        void* stub = NULL;
-#else
-        void *stub = text->getStubLayout()->allocateStub((void *)S);
-#endif
-        rsl_assert(stub && "cannot allocate stub.");
-        sym->setAddress(stub);
-        S = (int32_t)(intptr_t)stub;
-        *inst |= ((S >> 2) & 0x3FFFFFF);
-        rsl_assert(((P + 4) >> 28) == (S >> 28) && "stub is too far.");
-      }
-      break;
-
-    case R_MIPS_HI16:
-      *inst &= 0xFFFF0000;
-      A = (A & 0xFFFF) << 16;
-      // Find the nearest LO16 relocation type after this entry
-      for (size_t j = i + 1; j < reltab->size(); j++) {
-        ELFRelocTy *this_rel = (*reltab)[j];
-        ELFSymbolTy *this_sym = (*symtab)[this_rel->getSymTabIndex()];
-        if (this_rel->getType() == R_MIPS_LO16 && this_sym == sym) {
-          Inst_t *this_inst = (Inst_t *)&(*text)[this_rel->getOffset()];
-          Inst_t this_A = (Inst_t)(uintptr_t)*this_inst;
-          this_A = this_A & 0xFFFF;
-          A += (short)this_A;
-          break;
-        }
-      }
-      if (strcmp (sym->getName(), "_gp_disp") == 0) {
-          S = (int)(intptr_t)got_address() + GP_OFFSET - (int)P;
-#if defined(__LP64__) || defined(__x86_64__)
-          llvm::errs() << "Code temporarily disabled for 64bit build";
-          abort();
-#else
-          sym->setAddress((void *)S);
-#endif
-      }
-      *inst |= (((S + A + (int)0x8000) >> 16) & 0xFFFF);
-      break;
-
-    case R_MIPS_LO16:
-      *inst &= 0xFFFF0000;
-      A = A & 0xFFFF;
-      if (strcmp (sym->getName(), "_gp_disp") == 0) {
-          S = (Inst_t)(intptr_t)sym->getAddress(EM_MIPS);
-      }
-      *inst |= ((S + A) & 0xFFFF);
-      break;
-
-    case R_MIPS_GOT16:
-    case R_MIPS_CALL16:
-      {
-        *inst &= 0xFFFF0000;
-        A = A & 0xFFFF;
-        if (rel->getType() == R_MIPS_GOT16) {
-          if (sym->getBindingAttribute() == STB_LOCAL) {
-            A <<= 16;
-
-            // Find the nearest LO16 relocation type after this entry
-            for (size_t j = i + 1; j < reltab->size(); j++) {
-              ELFRelocTy *this_rel = (*reltab)[j];
-              ELFSymbolTy *this_sym = (*symtab)[this_rel->getSymTabIndex()];
-              if (this_rel->getType() == R_MIPS_LO16 && this_sym == sym) {
-                Inst_t *this_inst = (Inst_t *)&(*text)[this_rel->getOffset()];
-                Inst_t this_A = (Inst_t)(uintptr_t)*this_inst;
-                this_A = this_A & 0xFFFF;
-                A += (short)this_A;
-                break;
-              }
-            }
-          } else {
-            rsl_assert(A == 0 && "R_MIPS_GOT16 addend is not 0.");
-          }
-        } else { // R_MIPS_CALL16
-          rsl_assert(A == 0 && "R_MIPS_CALL16 addend is not 0.");
-        }
-#if defined(__LP64__) || defined(__x86_64__)
-        llvm::errs() << "Code temporarily disabled for 64bit build";
-        abort();
-        int got_index = 0;
-#else
-        int got_index = search_got((int)rel->getSymTabIndex(), (void *)(S + A),
-                                   sym->getBindingAttribute());
-#endif
-        int got_offset = (got_index << 2) - GP_OFFSET;
-        *inst |= (got_offset & 0xFFFF);
-      }
-      break;
-
-    case R_MIPS_GPREL32:
-      *inst = A + S - ((int)(intptr_t)got_address() + GP_OFFSET);
-      break;
-    }
-  }
-}
-
-template <unsigned Bitwidth>
-inline void ELFObject<Bitwidth>::
-relocateMIPS64(void *(*find_sym)(void *context, char const *name),
-               void *context,
-               ELFSectionRelTableTy *reltab,
-               ELFSectionProgBitsTy *text) {
-  ELFSectionSymTabTy *symtab =
-    static_cast<ELFSectionSymTabTy *>(getSectionByName(".symtab"));
-  rsl_assert(symtab && "Symtab is required.");
-
-  int64_t calculatedValue = 0;
-  bool applyRelocation = true;
-  bool useCalculatedValue;
-
-  for (size_t i = 0; i < reltab->size(); ++i) {
-    ELFRelocTy *rel = (*reltab)[i];
-    ELFSymbolTy *sym = (*symtab)[rel->getSymTabIndex()];
-
-    typedef int64_t Inst_t;
-    Inst_t *inst = (Inst_t *)&(*text)[rel->getOffset()];
-    Inst_t P = (Inst_t)(uintptr_t)inst;
-    Inst_t A = (Inst_t)rel->getAddend();
-    Inst_t S = (Inst_t)(uintptr_t)sym->getAddress(EM_MIPS);
-
-    if (S == 0) {
-      S = (Inst_t)(uintptr_t)find_sym(context, sym->getName());
-      if (!S) {
-        missingSymbols = true;
-      }
-      sym->setAddress((void *)S);
-    }
-
-    uint8_t rtype[3];
-    rtype[0] = (rel->getType() >> 24) & 0xFF;
-    rtype[1] = (rel->getType() >> 16) & 0xFF;
-    rtype[2] = (rel->getType() >> 8) & 0xFF;
-
-    for (size_t j = 0; j < 3; ++j) {
-      useCalculatedValue = !applyRelocation;
-      if (j < 2) {
-        applyRelocation = (rtype[j+1] == R_MIPS_NONE);
-      } else if ((i + 1) < reltab->size()) {
-        // Enter here if there are more relocations left in the table
-        // and check if the next one affects the same instruction.
-        ELFRelocTy *next_rel = (*reltab)[i + 1];
-        Inst_t *next_inst = (Inst_t *)&(*text)[next_rel->getOffset()];
-        applyRelocation = (inst != next_inst);
-      }
-
-      if (useCalculatedValue) {
-        S = 0;
-        A = calculatedValue;
-      }
-
-      switch (rtype[j]) {
-      default:
-        rsl_assert(0 && "Not implemented relocation type.");
-        break;
-
-      case R_MIPS_NONE:
-        break;
-
-      case R_MIPS_32:
-        calculatedValue = S + A;
-        if (applyRelocation) {
-          *inst |= (calculatedValue & 0xFFFFFFFF);
-        }
-        break;
-
-      case R_MIPS_64:
-        calculatedValue = S + A;
-        if (applyRelocation) {
-          *inst = calculatedValue;
-        }
-        break;
-
-      case R_MIPS_26:
-        if (sym->getBindingAttribute() == STB_LOCAL) {
-          // Local binding.
-          A |= ((P + 4) & 0xF0000000);
-          A += S;
-          calculatedValue = (A >> 2);
-          if (applyRelocation) {
-            *inst |= (calculatedValue & 0x3FFFFFF);
-          }
-        } else {
-          // External binding.
-          A += S;
-          calculatedValue = (A >> 2);
-          if (applyRelocation) {
-            *inst |= (calculatedValue & 0x3FFFFFF);
-          }
-        }
-        break;
-
-      case R_MIPS_CALL16:
-      case R_MIPS_GOT_PAGE:
-      case R_MIPS_GOT_DISP: {
-        int got_index = search_got((int)rel->getSymTabIndex(),
-                                   (void *)(S + A),
-                                   sym->getBindingAttribute());
-        calculatedValue = (got_index << 3) - 0x7FF0;
-        if (applyRelocation) {
-          *inst |= (calculatedValue & 0xFFFF);
-        }
-        break;
-      }
-
-      case R_MIPS_GPREL32:
-        calculatedValue = A + S - ((int64_t)got_address() + 0x7FF0);
-        if (applyRelocation) {
-          *inst |= calculatedValue;
-        }
-        break;
-
-      case R_MIPS_GOT_OFST:
-        calculatedValue = (S + A) & 0xFFFF;
-        if (applyRelocation) {
-          *inst |= calculatedValue;
-        }
-        break;
-
-      case R_MIPS_GPREL16:
-        calculatedValue = A + S - ((int64_t)got_address() + 0x7FF0);
-        if (applyRelocation) {
-          *inst |= (calculatedValue & 0xFFFF);
-        }
-        break;
-
-      case R_MIPS_SUB:
-        calculatedValue = S - A;
-        if (applyRelocation) {
-          *inst = calculatedValue;
-        }
-        break;
-
-      case R_MIPS_HI16:
-        calculatedValue = ((S + A + 0x8000) >> 16) & 0xFFFF;
-        if (applyRelocation) {
-          *inst |= calculatedValue;
-        }
-        break;
-
-      case R_MIPS_LO16:
-        calculatedValue = (S + A) & 0xFFFF;
-        if (applyRelocation) {
-          *inst |= calculatedValue;
-        }
-        break;
-
-      case R_MIPS_HIGHER:
-        calculatedValue = ((S + A + 0x80008000) >> 32) & 0xFFFF;
-        if (applyRelocation) {
-          *inst |= calculatedValue;
-        }
-        break;
-
-      case R_MIPS_HIGHEST:
-        calculatedValue = ((S + A + 0x800080008000) >> 48) & 0xFFFF;
-        if (applyRelocation) {
-          *inst |= calculatedValue;
-        }
-        break;
-
-      case R_MIPS_PC16:
-        calculatedValue = S + A - P;
-        if (applyRelocation) {
-          *inst |= (calculatedValue  >> 2) & 0xFFFF;
-        }
-        break;
-
-      case R_MIPS_PC18_S3:
-        rsl_assert(!((S + A) & 7) && "R_MIPS_PC18_S3 relocation out of range");
-        calculatedValue = S + A - ((P | 7) ^ 7);
-        if (applyRelocation) {
-          *inst |= (calculatedValue  >> 3) & 0x3FFFF;
-        }
-        break;
-
-      case R_MIPS_PC19_S2:
-        rsl_assert(!((S + A) & 3) && "R_MIPS_PC19_S2 relocation out of range");
-        calculatedValue = S + A - P;
-        if (applyRelocation) {
-          *inst |= (calculatedValue  >> 2) & 0x7FFFF;
-        }
-        break;
-
-      case R_MIPS_PC21_S2:
-        calculatedValue = S + A - P;
-        if (applyRelocation) {
-          *inst |= (calculatedValue  >> 2) & 0x1FFFFF;
-        }
-        break;
-
-      case R_MIPS_PC26_S2:
-        calculatedValue = S + A - P;
-        if (applyRelocation) {
-          *inst |= (calculatedValue  >> 2) & 0x3FFFFFF;
-        }
-        break;
-
-      case R_MIPS_PCHI16:
-        calculatedValue = ((S + A - P + 0x8000) >> 16) & 0xFFFF;
-        if (applyRelocation) {
-          *inst |= calculatedValue;
-        }
-        break;
-
-      case R_MIPS_PCLO16:
-        calculatedValue = (S + A - P) & 0xFFFF;
-        if (applyRelocation) {
-          *inst |= calculatedValue;
-        }
-        break;
-      }
-    }
-  }
-}
-
-// TODO: Refactor all relocations.
-template <unsigned Bitwidth>
-inline void ELFObject<Bitwidth>::
-relocate(void *(*find_sym)(void *context, char const *name), void *context) {
-  // Init SHNCommonDataSize.
-  // Need refactoring
-  size_t SHNCommonDataSize = 0;
-
-  ELFSectionSymTabTy *symtab =
-    static_cast<ELFSectionSymTabTy *>(getSectionByName(".symtab"));
-  rsl_assert(symtab && "Symtab is required.");
-
-  for (size_t i = 0; i < symtab->size(); ++i) {
-    ELFSymbolTy *sym = (*symtab)[i];
-
-    if (sym->getType() != STT_OBJECT) {
-      continue;
-    }
-
-    size_t idx = (size_t)sym->getSectionIndex();
-    switch (idx) {
-    default:
-      if ((*shtab)[idx]->getType() == SHT_NOBITS) {
-        // FIXME(logan): This is a workaround for .lcomm directives
-        // bug of LLVM ARM MC code generator.  Remove this when the
-        // LLVM bug is fixed.
-
-        size_t align = 16;
-        SHNCommonDataSize += (size_t)sym->getSize() + align;
-      }
-      break;
-
-    case SHN_COMMON:
-      {
-        size_t align = (size_t)sym->getValue();
-        SHNCommonDataSize += (size_t)sym->getSize() + align;
-      }
-      break;
-
-    case SHN_ABS:
-    case SHN_UNDEF:
-    case SHN_XINDEX:
-      break;
-    }
-  }
-  if (!initSHNCommonDataSize(SHNCommonDataSize)) {
-    rsl_assert("Allocate memory for common variable fail!");
-    // TODO: Refactor object loading to use proper status/error returns.
-    // We mark the object as having missing symbols and return early in this
-    // case to signal a loading error (usually due to running out of
-    // available memory to allocate).
-    missingSymbols = true;
-    return;
-  }
-
-  for (size_t i = 0; i < stab.size(); ++i) {
-    ELFSectionHeaderTy *sh = (*shtab)[i];
-    if (sh->getType() != SHT_REL && sh->getType() != SHT_RELA) {
-      continue;
-    }
-    ELFSectionRelTableTy *reltab =
-      static_cast<ELFSectionRelTableTy *>(stab[i]);
-    rsl_assert(reltab && "Relocation section can't be NULL.");
-
-    const char *reltab_name = sh->getName();
-    const char *need_rel_name;
-    if (sh->getType() == SHT_REL) {
-      need_rel_name = reltab_name + 4;
-      // ".rel.xxxx"
-      //      ^ start from here.
-    } else {
-      need_rel_name = reltab_name + 5;
-    }
-
-    // TODO: We currently skip relocations of ARM unwind information, because
-    // it is unused.
-    if (!strcmp(".ARM.exidx", need_rel_name)) {
-      continue;
-    }
-
-    ELFSectionProgBitsTy *need_rel =
-      static_cast<ELFSectionProgBitsTy *>(getSectionByName(need_rel_name));
-    rsl_assert(need_rel && "Need be relocated section can't be NULL.");
-
-    switch (getHeader()->getMachine()) {
-      case EM_ARM:
-        relocateARM(find_sym, context, reltab, need_rel);
-        break;
-      case EM_AARCH64:
-        relocateAARCH64(find_sym, context, reltab, need_rel);
-        break;
-      case EM_386:
-        relocateX86_32(find_sym, context, reltab, need_rel);
-        break;
-      case EM_X86_64:
-        relocateX86_64(find_sym, context, reltab, need_rel);
-        break;
-      case EM_MIPS:
-        if (getHeader()->getClass() == ELFCLASS64) {
-          relocateMIPS64(find_sym, context, reltab, need_rel);
-        } else {
-          relocateMIPS(find_sym, context, reltab, need_rel);
-        }
-        break;
-
-      default:
-        rsl_assert(0 && "Only support ARM, MIPS, X86, and X86_64 relocation.");
-        break;
-    }
-  }
-
-  for (size_t i = 0; i < stab.size(); ++i) {
-    ELFSectionHeaderTy *sh = (*shtab)[i];
-    if (sh->getType() == SHT_PROGBITS || sh->getType() == SHT_NOBITS) {
-      if (stab[i]) {
-        static_cast<ELFSectionBitsTy *>(stab[i])->protect();
-      }
-    }
-  }
-}
-
-template <unsigned Bitwidth>
-inline void ELFObject<Bitwidth>::print() const {
-  header->print();
-  shtab->print();
-
-  for (size_t i = 0; i < stab.size(); ++i) {
-    ELFSectionTy *sec = stab[i];
-    if (sec) {
-      sec->print();
-    }
-  }
-}
-
-#endif // ELF_OBJECT_HXX
diff --git a/cpu_ref/linkloader/include/impl/ELFReloc.hxx b/cpu_ref/linkloader/include/impl/ELFReloc.hxx
deleted file mode 100644
index e60b66e..0000000
--- a/cpu_ref/linkloader/include/impl/ELFReloc.hxx
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_RELOC_HXX
-#define ELF_RELOC_HXX
-
-#include "utils/raw_ostream.h"
-
-#include <llvm/Support/Format.h>
-#include <llvm/Support/raw_ostream.h>
-
-template <unsigned Bitwidth>
-template <typename Archiver>
-inline ELFReloc<Bitwidth> *
-ELFReloc_CRTP<Bitwidth>::readRela(Archiver &AR, size_t index) {
-  if (!AR) {
-    // Archiver is in bad state before calling read function.
-    // Return NULL and do nothing.
-    return 0;
-  }
-
-  std::unique_ptr<ELFRelocTy> sh(new ELFRelocTy());
-
-  if (!sh->serializeRela(AR)) {
-    // Unable to read the structure.  Return NULL.
-    return 0;
-  }
-
-  if (!sh->isValid()) {
-    // Rel read from archiver is not valid.  Return NULL.
-    return 0;
-  }
-
-  // Set the section header index
-  sh->index = index;
-
-  return sh.release();
-}
-
-template <unsigned Bitwidth>
-template <typename Archiver>
-inline ELFReloc<Bitwidth> *
-ELFReloc_CRTP<Bitwidth>::readRel(Archiver &AR, size_t index) {
-  if (!AR) {
-    // Archiver is in bad state before calling read function.
-    // Return NULL and do nothing.
-    return 0;
-  }
-
-  std::unique_ptr<ELFRelocTy> sh(new ELFRelocTy());
-
-  sh->r_addend = 0;
-  if (!sh->serializeRel(AR)) {
-    return 0;
-  }
-
-  if (!sh->isValid()) {
-    // Rel read from archiver is not valid.  Return NULL.
-    return 0;
-  }
-
-  // Set the section header index
-  sh->index = index;
-
-  return sh.release();
-}
-
-template <unsigned Bitwidth>
-inline void ELFReloc_CRTP<Bitwidth>::print(bool shouldPrintHeader) const {
-  using namespace llvm;
-  if (shouldPrintHeader) {
-    out() << '\n' << fillformat('=', 79) << '\n';
-    out().changeColor(raw_ostream::WHITE, true);
-    out() << "ELF Relaocation Table Entry "
-          << this->getIndex() << '\n';
-    out().resetColor();
-    out() << fillformat('-', 79) << '\n';
-  } else {
-    out() << fillformat('-', 79) << '\n';
-    out().changeColor(raw_ostream::YELLOW, true);
-    out() << "ELF Relaocation Table Entry "
-          << this->getIndex() << " : " << '\n';
-    out().resetColor();
-  }
-
-#define PRINT_LINT(title, value) \
-  out() << format("  %-13s : ", (char const *)(title)) << (value) << '\n'
-  PRINT_LINT("Offset",       concrete()->getOffset()       );
-  PRINT_LINT("SymTab Index", concrete()->getSymTabIndex()  );
-  PRINT_LINT("Type",         concrete()->getType()         );
-  PRINT_LINT("Addend",       concrete()->getAddend()       );
-#undef PRINT_LINT
-}
-
-#endif // ELF_RELOC_HXX
diff --git a/cpu_ref/linkloader/include/impl/ELFSection.hxx b/cpu_ref/linkloader/include/impl/ELFSection.hxx
deleted file mode 100644
index fb0e6f6..0000000
--- a/cpu_ref/linkloader/include/impl/ELFSection.hxx
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_HXX
-#define ELF_SECTION_HXX
-
-#include "utils/raw_ostream.h"
-
-#include <llvm/Support/raw_ostream.h>
-
-#include "ELFSectionHeader.h"
-#include "ELFSectionStrTab.h"
-#include "ELFSectionSymTab.h"
-#include "ELFSectionProgBits.h"
-#include "ELFSectionNoBits.h"
-#include "ELFSectionRelTable.h"
-
-template <unsigned Bitwidth>
-template <typename Archiver>
-inline ELFSection<Bitwidth> *
-ELFSection<Bitwidth>::read(Archiver &AR,
-                           ELFObjectTy *owner,
-                           ELFSectionHeaderTy const *sh) {
-  using namespace std;
-
-  switch (sh->getType()) {
-    default:
-      // Uknown type of ELF section.  Return NULL.
-      //llvm::errs() << "WARNING: Unknown section type.\n";
-      return 0;
-
-    case SHT_STRTAB:
-      return ELFSectionStrTabTy::read(AR, sh);
-
-    case SHT_SYMTAB:
-      return ELFSectionSymTabTy::read(AR, owner, sh);
-
-    case SHT_PROGBITS:
-      return ELFSectionProgBitsTy::read(AR, owner, sh);
-
-    case SHT_NOBITS:
-      return ELFSectionNoBitsTy::read(AR, sh);
-
-    case SHT_REL:
-    case SHT_RELA:
-      return ELFSectionRelTableTy::read(AR, sh);
-
-    case SHT_NULL:
-      // TODO: Not Yet Implemented
-      return 0;
-  };
-}
-
-#endif // ELF_SECTION_HXX
diff --git a/cpu_ref/linkloader/include/impl/ELFSectionBits.hxx b/cpu_ref/linkloader/include/impl/ELFSectionBits.hxx
deleted file mode 100644
index c99254b..0000000
--- a/cpu_ref/linkloader/include/impl/ELFSectionBits.hxx
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_BITS_HXX
-#define ELF_SECTION_BITS_HXX
-
-#include "utils/flush_cpu_cache.h"
-#include "utils/helper.h"
-
-#include <llvm/Support/raw_ostream.h>
-
-#ifndef USE_MINGW       /* TODO create a proper HAVE_MMAN_H */
-#include <sys/mman.h>
-#else
-#include "mmanWindows.h"
-#endif
-
-template <unsigned Bitwidth>
-inline void ELFSectionBits<Bitwidth>::print() const {
-  using namespace llvm;
-
-  char const *section_type_str =
-    (sh->getType() == SHT_NOBITS) ? "NOBITS" : "PROGBITS";
-
-  out() << '\n' << fillformat('=', 79) << '\n';
-  out().changeColor(raw_ostream::WHITE, true);
-  out() << "ELF " << section_type_str << ": " << sh->getName() << '\n';
-  out().resetColor();
-  out() << fillformat('-', 79) << '\n';
-
-  out() << "  Size         : " << sh->getSize() << '\n';
-  out() << "  Start Address: " << (void *)chunk.getBuffer() << '\n';
-  out() << fillformat('-', 79) << '\n';
-
-  chunk.print();
-
-  out() << fillformat('=', 79) << '\n';
-}
-
-template <unsigned Bitwidth>
-inline bool ELFSectionBits<Bitwidth>::protect() {
-  int prot = PROT_READ;
-
-  if (sh->getFlags() & SHF_WRITE) {
-    prot |= PROT_WRITE;
-  }
-
-  if (sh->getFlags() & SHF_EXECINSTR) {
-    prot |= PROT_EXEC;
-  }
-
-  return chunk.protect(prot);
-}
-
-#endif // ELF_SECTION_BITS_HXX
diff --git a/cpu_ref/linkloader/include/impl/ELFSectionHeader.hxx b/cpu_ref/linkloader/include/impl/ELFSectionHeader.hxx
deleted file mode 100644
index 0c9568d..0000000
--- a/cpu_ref/linkloader/include/impl/ELFSectionHeader.hxx
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_HEADER_HXX
-#define ELF_SECTION_HEADER_HXX
-
-#include "utils/raw_ostream.h"
-#include <llvm/Support/Format.h>
-#include <llvm/Support/raw_ostream.h>
-
-#include "ELFObject.h"
-
-template <unsigned Bitwidth>
-char const *ELFSectionHeader_CRTP<Bitwidth>::getName() const {
-  return owner->getSectionName(getNameIndex());
-}
-
-template <unsigned Bitwidth>
-template <typename Archiver>
-typename ELFSectionHeader_CRTP<Bitwidth>::ELFSectionHeaderTy *
-ELFSectionHeader_CRTP<Bitwidth>::read(Archiver &AR,
-                                      ELFObjectTy const *owner,
-                                      size_t index) {
-
-  if (!AR) {
-    // Archiver is in bad state before calling read function.
-    // Return NULL and do nothing.
-    return 0;
-  }
-
-  std::unique_ptr<ELFSectionHeaderTy> sh(new ELFSectionHeaderTy());
-
-  if (!sh->serialize(AR)) {
-    // Unable to read the structure.  Return NULL.
-    return 0;
-  }
-
-  if (!sh->isValid()) {
-    // Header read from archiver is not valid.  Return NULL.
-    return 0;
-  }
-
-  // Set the section header index
-  sh->index = index;
-
-  // Set the owner elf object
-  sh->owner = owner;
-
-  return sh.release();
-}
-
-template <unsigned Bitwidth>
-void ELFSectionHeader_CRTP<Bitwidth>::print(bool shouldPrintHeader) const {
-  using namespace llvm;
-
-  if (shouldPrintHeader) {
-    out() << '\n' << fillformat('=', 79) << '\n';
-    out().changeColor(raw_ostream::WHITE, true);
-    out() << "ELF Section Header "
-      << this->getIndex() << '\n';
-    out().resetColor();
-    out() << fillformat('-', 79) << '\n';
-  } else {
-    out() << fillformat('-', 79) << '\n';
-    out().changeColor(raw_ostream::YELLOW, true);
-    out() << "ELF Section Header "
-      << this->getIndex() << " : " << '\n';
-    out().resetColor();
-  }
-
-#define PRINT_LINT(title, value) \
-  out() << format("  %-13s : ", (char const *)(title)) << (value) << '\n'
-  PRINT_LINT("Name",          getName() );
-  PRINT_LINT("Type",          getSectionTypeStr(getType()));
-  PRINT_LINT("Flags",         concrete()->getFlags());
-  PRINT_LINT("Address",       getAddress());
-  PRINT_LINT("Offset",        getOffset());
-  PRINT_LINT("Size",          concrete()->getSize());
-  PRINT_LINT("Link",          getLink());
-  PRINT_LINT("Extra Info",    getExtraInfo());
-  PRINT_LINT("Address Align", concrete()->getAddressAlign());
-  PRINT_LINT("Entry Size",    concrete()->getEntrySize());
-#undef PRINT_LINT
-
-  if (shouldPrintHeader) {
-    out() << fillformat('=', 79) << '\n';
-  }
-}
-
-#endif // ELF_SECTION_HEADER_HXX
diff --git a/cpu_ref/linkloader/include/impl/ELFSectionHeaderTable.hxx b/cpu_ref/linkloader/include/impl/ELFSectionHeaderTable.hxx
deleted file mode 100644
index 570cae5..0000000
--- a/cpu_ref/linkloader/include/impl/ELFSectionHeaderTable.hxx
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_HEADER_TABLE_HXX
-#define ELF_SECTION_HEADER_TABLE_HXX
-
-#include "ELFHeader.h"
-#include "ELFObject.h"
-#include "ELFSectionHeader.h"
-
-#include "utils/rsl_assert.h"
-
-template <unsigned Bitwidth>
-ELFSectionHeaderTable<Bitwidth>::~ELFSectionHeaderTable() {
-  for (size_t i = 0; i < table.size(); ++i) {
-    delete table[i];
-  }
-}
-
-template <unsigned Bitwidth>
-template <typename Archiver>
-inline ELFSectionHeaderTable<Bitwidth> *
-ELFSectionHeaderTable<Bitwidth>::read(Archiver &AR, ELFObjectTy *owner) {
-  if (!AR) {
-    // Archiver is in bad state before calling read function.
-    // Return NULL and do nothing.
-    return 0;
-  }
-
-  // Allocate a new section header table and assign the owner.
-  std::unique_ptr<ELFSectionHeaderTable> tab(new ELFSectionHeaderTable());
-
-  // Get ELF header
-  ELFHeaderTy const *header = owner->getHeader();
-
-  rsl_assert(header->getSectionHeaderEntrySize() ==
-         TypeTraits<ELFSectionHeaderTy>::size);
-
-  // Seek to the address of section header
-  AR.seek(header->getSectionHeaderTableOffset(), true);
-
-  for (size_t i = 0; i < header->getSectionHeaderNum(); ++i) {
-    std::unique_ptr<ELFSectionHeaderTy> sh(
-      ELFSectionHeaderTy::read(AR, owner, i));
-
-    if (!sh) {
-      // Something wrong while reading the section header.
-      return 0;
-    }
-
-    tab->table.push_back(sh.release());
-  }
-
-  return tab.release();
-}
-
-template <unsigned Bitwidth>
-inline void ELFSectionHeaderTable<Bitwidth>::print() const {
-  using namespace llvm;
-
-  out() << '\n' << fillformat('=', 79) << '\n';
-  out().changeColor(raw_ostream::WHITE, true);
-  out() << "ELF Section Header Table" << '\n';
-  out().resetColor();
-
-  for (size_t i = 0; i < table.size(); ++i) {
-    (*this)[i]->print();
-  }
-
-  out() << fillformat('=', 79) << '\n';
-}
-
-template <unsigned Bitwidth>
-inline void ELFSectionHeaderTable<Bitwidth>::buildNameMap() {
-  for (size_t i = 0; i < table.size(); ++i) {
-    ELFSectionHeaderTy *sh = table[i];
-    if ( sh ) {
-      name_map[sh->getName()] = sh;
-    }
-  }
-}
-
-template <unsigned Bitwidth>
-inline ELFSectionHeader<Bitwidth> const *
-ELFSectionHeaderTable<Bitwidth>::getByName(const std::string &name) const {
-  typename llvm::StringMap<ELFSectionHeaderTy *>::const_iterator sh =
-    name_map.find(name);
-  if (sh == name_map.end()) {
-    // Return SHN_UNDEF section header;
-    return table[0];
-  }
-  return sh->getValue();
-}
-
-template <unsigned Bitwidth>
-inline ELFSectionHeader<Bitwidth> *
-ELFSectionHeaderTable<Bitwidth>::getByName(const std::string &name) {
-  ELFSectionHeaderTableTy const *const_this = this;
-  ELFSectionHeaderTy const *shptr = const_this->getByName(name);
-  // Const cast for the same API's const and non-const versions.
-  return const_cast<ELFSectionHeaderTy *>(shptr);
-}
-
-#endif // ELF_SECTION_HEADER_TABLE_HXX
diff --git a/cpu_ref/linkloader/include/impl/ELFSectionNoBits.hxx b/cpu_ref/linkloader/include/impl/ELFSectionNoBits.hxx
deleted file mode 100644
index d77398d..0000000
--- a/cpu_ref/linkloader/include/impl/ELFSectionNoBits.hxx
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_NOBITS_HXX
-#define ELF_SECTION_NOBITS_HXX
-
-#include "ELFTypes.h"
-
-#include "utils/raw_ostream.h"
-
-#include <llvm/Support/Format.h>
-#include <llvm/Support/raw_ostream.h>
-
-template <unsigned Bitwidth>
-template <typename Archiver>
-inline ELFSectionNoBits<Bitwidth> *
-ELFSectionNoBits<Bitwidth>::read(Archiver &AR, ELFSectionHeaderTy const *sh) {
-  std::unique_ptr<ELFSectionNoBits> result(new ELFSectionNoBits());
-
-  if (!result->chunk.allocate(sh->getSize())) {
-    return NULL;
-  }
-
-  result->sh = sh;
-
-  return result.release();
-}
-
-#endif // ELF_SECTION_NOBITS_HXX
diff --git a/cpu_ref/linkloader/include/impl/ELFSectionProgBits.hxx b/cpu_ref/linkloader/include/impl/ELFSectionProgBits.hxx
deleted file mode 100644
index e18c9c3..0000000
--- a/cpu_ref/linkloader/include/impl/ELFSectionProgBits.hxx
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_PROGBITS_HXX
-#define ELF_SECTION_PROGBITS_HXX
-
-#include "ELFTypes.h"
-#include "GOT.h"
-#include "StubLayout.h"
-
-#include <llvm/Support/Format.h>
-#include <llvm/Support/raw_ostream.h>
-
-#include "utils/raw_ostream.h"
-
-#include <string.h>
-
-template <unsigned Bitwidth>
-template <typename Archiver>
-ELFSectionProgBits<Bitwidth> *
-ELFSectionProgBits<Bitwidth>::read(Archiver &AR,
-                                   ELFObjectTy *owner,
-                                   ELFSectionHeaderTy const *sh) {
-  int machine = owner->getHeader()->getMachine();
-  ELFSectionProgBits *secp = new ELFSectionProgBits(machine);
-  std::unique_ptr<ELFSectionProgBits> result(secp);
-  size_t max_num_stubs = 0;
-  // Align section boundary to 4 bytes.
-  size_t section_size = (sh->getSize() + 3) / 4 * 4;
-  size_t alloc_size = section_size;
-  StubLayout *stubs = result->getStubLayout();
-  if (stubs) {
-    // Compute the maximal possible numbers of stubs
-    max_num_stubs = 0;
-    for (const char* prefix : {".rel", ".rela"}) {
-      std::string reltab_name(prefix + std::string(sh->getName()));
-
-      ELFSectionRelTableTy const *reltab =
-        static_cast<ELFSectionRelTableTy *>(
-          owner->getSectionByName(reltab_name.c_str()));
-
-      if (reltab) {
-        // If we have relocation table, then get the approximation of
-        // maximum numbers of stubs.
-        max_num_stubs += reltab->getMaxNumStubs(owner);
-      }
-    }
-
-    // Compute the stub table size
-    size_t stub_table_size = stubs->calcStubTableSize(max_num_stubs);
-
-    // Allocate PROGBITS section with stubs table
-    alloc_size += stub_table_size;
-  }
-
-#if defined(__mips__)
-  // Add GOT section after the text section.
-  if (strcmp(sh->getName(), ".text") == 0) {
-    alloc_size += GOT_SIZE;
-  }
-#endif
-
-  // Allocate text section
-  if (!result->chunk.allocate(alloc_size)) {
-    return NULL;
-  }
-
-  if (stubs) {
-    stubs->initStubTable(result->chunk.getBuffer() + section_size,
-                         max_num_stubs);
-  }
-
-#if defined(__mips__)
-  if (strcmp(sh->getName(), ".text") == 0) {
-    set_got_address(result->chunk.getBuffer() + alloc_size - GOT_SIZE);
-  }
-#endif
-
-  result->sh = sh;
-
-  if (!result->serialize(AR)) {
-    // Unable to read the progbits section.
-    return NULL;
-  }
-
-  return result.release();
-}
-
-#endif // ELF_SECTION_PROGBITS_HXX
diff --git a/cpu_ref/linkloader/include/impl/ELFSectionRelTable.hxx b/cpu_ref/linkloader/include/impl/ELFSectionRelTable.hxx
deleted file mode 100644
index 43c4980..0000000
--- a/cpu_ref/linkloader/include/impl/ELFSectionRelTable.hxx
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_REL_TABLE_HXX
-#define ELF_SECTION_REL_TABLE_HXX
-
-#include "ELF.h"
-#include "ELFHeader.h"
-#include "ELFObject.h"
-#include "ELFReloc.h"
-#include "ELFTypes.h"
-
-#include <set>
-
-template <unsigned Bitwidth>
-ELFSectionRelTable<Bitwidth>::~ELFSectionRelTable() {
-  using namespace std;
-  for (size_t i = 0; i < table.size(); ++i) {
-    delete table[i];
-  }
-}
-
-template <unsigned Bitwidth>
-void ELFSectionRelTable<Bitwidth>::print() const {
-  using namespace llvm;
-
-  out() << '\n' << fillformat('=', 79) << '\n';
-  out().changeColor(raw_ostream::WHITE, true);
-  out() << "Relocation Table" << '\n';
-  out().resetColor();
-
-  for (size_t i = 0; i < this->size(); ++i) {
-    (*this)[i]->print();
-  }
-
-  out() << fillformat('=', 79) << '\n';
-}
-
-template <unsigned Bitwidth>
-template <typename Archiver>
-ELFSectionRelTable<Bitwidth> *
-ELFSectionRelTable<Bitwidth>::read(Archiver &AR,
-                                   ELFSectionHeaderTy const *sh) {
-
-  rsl_assert(sh->getType() == SHT_REL || sh->getType() == SHT_RELA);
-
-  std::unique_ptr<ELFSectionRelTable> rt(new ELFSectionRelTable());
-
-  // Seek to the start of the table
-  AR.seek(sh->getOffset(), true);
-
-  // Count the relocation entries
-  size_t size = sh->getSize() / sh->getEntrySize();
-
-  // Read every relocation entries
-  if (sh->getType() == SHT_REL) {
-    rsl_assert(sh->getEntrySize() == TypeTraits<ELFRelocRelTy>::size);
-    for (size_t i = 0; i < size; ++i) {
-      rt->table.push_back(ELFRelocTy::readRel(AR, i));
-    }
-
-  } else {
-    rsl_assert(sh->getEntrySize() == TypeTraits<ELFRelocRelaTy>::size);
-    for (size_t i = 0; i < size; ++i) {
-      rt->table.push_back(ELFRelocTy::readRela(AR, i));
-    }
-  }
-
-  if (!AR) {
-    // Unable to read the table.
-    return 0;
-  }
-
-  return rt.release();
-}
-
-template <unsigned Bitwidth>
-size_t ELFSectionRelTable<Bitwidth>::
-getMaxNumStubs(ELFObjectTy const *obj) const {
-  std::set<uint32_t> sym_index_set;
-  switch (obj->getHeader()->getMachine()) {
-  case EM_ARM:
-    {
-      for (size_t i = 0; i < size(); ++i) {
-        ELFRelocTy *rel = table[i];
-
-        switch (rel->getType()) {
-        case R_ARM_CALL:
-        case R_ARM_THM_CALL:
-        case R_ARM_JUMP24:
-        case R_ARM_THM_JUMP24:
-          sym_index_set.insert(rel->getSymTabIndex());
-          break;
-        }
-      }
-
-      return sym_index_set.size();
-    }
-
-  case EM_AARCH64:
-    {
-      for (size_t i = 0; i < size(); ++i) {
-        ELFRelocTy *rel = table[i];
-
-        switch (rel->getType()) {
-        case R_AARCH64_CALL26:
-        case R_AARCH64_JUMP26:
-          sym_index_set.insert(rel->getSymTabIndex());
-          break;
-        }
-      }
-
-      return sym_index_set.size();
-    }
-
-  case EM_MIPS:
-    {
-      for (size_t i = 0; i < size(); ++i) {
-        ELFRelocTy *rel = table[i];
-
-        if (rel->getType() == R_MIPS_26) {
-          sym_index_set.insert(rel->getSymTabIndex());
-        }
-      }
-
-      return sym_index_set.size();
-    }
-
-  case EM_386:
-    {
-      for (size_t i = 0; i < size(); ++i) {
-        ELFRelocTy *rel = table[i];
-
-        switch (rel->getType()) {
-        case R_386_PC32:
-          sym_index_set.insert(rel->getSymTabIndex());
-          break;
-        }
-      }
-
-      return sym_index_set.size();
-    }
-
-  case EM_X86_64:
-    {
-      for (size_t i = 0; i < size(); ++i) {
-        ELFRelocTy *rel = table[i];
-
-        switch (rel->getType()) {
-        case R_X86_64_PC32:
-          sym_index_set.insert(rel->getSymTabIndex());
-          break;
-        }
-      }
-
-      return sym_index_set.size();
-    }
-
-  default:
-    rsl_assert(0 && "Only support ARM, MIPS, X86, and X86_64 relocation.");
-    return 0;
-  }
-}
-
-#endif // ELF_SECTION_REL_TABLE_HXX
diff --git a/cpu_ref/linkloader/include/impl/ELFSectionStrTab.hxx b/cpu_ref/linkloader/include/impl/ELFSectionStrTab.hxx
deleted file mode 100644
index f8944ca..0000000
--- a/cpu_ref/linkloader/include/impl/ELFSectionStrTab.hxx
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_STR_TAB_HXX
-#define ELF_SECTION_STR_TAB_HXX
-
-#include "utils/helper.h"
-#include "utils/raw_ostream.h"
-
-#include <llvm/Support/Format.h>
-#include <llvm/Support/raw_ostream.h>
-
-template <unsigned Bitwidth>
-template <typename Archiver>
-ELFSectionStrTab<Bitwidth> *
-ELFSectionStrTab<Bitwidth>::read(Archiver &AR,
-                                 ELFSectionHeaderTy const *sh) {
-
-  std::unique_ptr<ELFSectionStrTab> st(new ELFSectionStrTab());
-  st->buf.resize(sh->getSize());
-
-  // Save section_header
-  st->section_header = sh;
-
-  AR.seek(sh->getOffset(), true);
-  AR.prologue(sh->getSize());
-  AR.readBytes(&*st->buf.begin(), sh->getSize());
-  AR.epilogue(sh->getSize());
-
-  if (!AR) {
-    // Unable to read the string table.
-    return 0;
-  }
-
-  return st.release();
-}
-
-template <unsigned Bitwidth>
-void ELFSectionStrTab<Bitwidth>::print() const {
-  using namespace llvm;
-
-  out() << '\n' << fillformat('=', 79) << '\n';
-  out().changeColor(raw_ostream::WHITE, true);
-  out() << "ELF String Table: " << this->section_header->getName() << '\n';
-  out().resetColor();
-  out() << fillformat('-', 79) << '\n';
-
-  dump_hex((unsigned char const *)&*buf.begin(), buf.size(), 0, buf.size());
-
-  out() << fillformat('=', 79) << '\n';
-}
-
-#endif // ELF_SECTION_STR_TAB_HXX
diff --git a/cpu_ref/linkloader/include/impl/ELFSectionSymTab.hxx b/cpu_ref/linkloader/include/impl/ELFSectionSymTab.hxx
deleted file mode 100644
index 2b796e3..0000000
--- a/cpu_ref/linkloader/include/impl/ELFSectionSymTab.hxx
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SECTION_SYM_TAB_HXX
-#define ELF_SECTION_SYM_TAB_HXX
-
-#include "ELFSectionHeader.h"
-#include "ELFSymbol.h"
-#include "utils/rsl_assert.h"
-
-template <unsigned Bitwidth>
-ELFSectionSymTab<Bitwidth>::~ELFSectionSymTab() {
-  for (size_t i = 0; i < table.size(); ++i) {
-    delete table[i];
-  }
-}
-
-template <unsigned Bitwidth>
-size_t ELFSectionSymTab<Bitwidth>::getFuncCount() const {
-  size_t result = 0;
-  for (size_t i = 0; i < table.size(); ++i) {
-    if (table[i] && table[i]->isConcreteFunc()) {
-      result++;
-    }
-  }
-  return result;
-}
-
-template <unsigned Bitwidth>
-inline size_t ELFSectionSymTab<Bitwidth>::getExternFuncCount() const {
-  size_t result = 0;
-  for (size_t i = 0; i < table.size(); ++i) {
-    if (table[i] && table[i]->isExternFunc()) {
-      result++;
-    }
-  }
-  return result;
-}
-
-template <unsigned Bitwidth>
-inline void ELFSectionSymTab<Bitwidth>::buildNameMap() {
-  for (size_t i = 0; i < table.size(); ++i) {
-    ELFSymbolTy *symbol = table[i];
-    if ( symbol ) {
-      name_map[symbol->getName()] = symbol;
-    }
-  }
-}
-
-template <unsigned Bitwidth>
-inline ELFSymbol<Bitwidth> const *
-ELFSectionSymTab<Bitwidth>::getByName(std::string const &name) const {
-  typename llvm::StringMap<ELFSymbolTy *>::const_iterator symbol =
-    name_map.find(name);
-  if (symbol == name_map.end()) {
-    return NULL;
-  }
-  return symbol->getValue();
-}
-
-template <unsigned Bitwidth>
-inline void
-ELFSectionSymTab<Bitwidth>::getFuncNameList(size_t size,
-                                            char const **list) const {
-  for (size_t i = 0, j = 0; i < table.size() && j < size; ++i) {
-    if (table[i] && table[i]->isConcreteFunc()) {
-      list[j++] = table[i]->getName();
-    }
-  }
-}
-
-template <unsigned Bitwidth>
-template <typename Archiver>
-ELFSectionSymTab<Bitwidth> *
-ELFSectionSymTab<Bitwidth>::read(Archiver &AR,
-                                 ELFObjectTy *owner,
-                                 ELFSectionHeaderTy const *sh) {
-
-  std::unique_ptr<ELFSectionSymTabTy> st(new ELFSectionSymTabTy());
-
-  // Assert that entry size will be the same as standard.
-  rsl_assert(sh->getEntrySize() == TypeTraits<ELFSymbolTy>::size);
-
-  // Seek to the start of symbol table
-  AR.seek(sh->getOffset(), true);
-
-  // Read all symbol table entry
-  size_t size = sh->getSize() / sh->getEntrySize();
-  for (size_t i = 0; i < size; ++i) {
-    st->table.push_back(ELFSymbolTy::read(AR, owner, i));
-  }
-
-  if (!AR) {
-    // Unable to read the table.
-    return 0;
-  }
-
-  return st.release();
-}
-
-template <unsigned Bitwidth>
-void ELFSectionSymTab<Bitwidth>::print() const {
-  using namespace llvm;
-
-  out() << '\n' << fillformat('=', 79) << '\n';
-  out().changeColor(raw_ostream::WHITE, true);
-  out() << "Symbol Table" << '\n';
-  out().resetColor();
-
-  for (size_t i = 0; i < table.size(); ++i) {
-    table[i]->print();
-  }
-
-  out() << fillformat('=', 79) << '\n';
-}
-
-#endif // ELF_SECTION_SYM_TAB_HXX
diff --git a/cpu_ref/linkloader/include/impl/ELFSymbol.hxx b/cpu_ref/linkloader/include/impl/ELFSymbol.hxx
deleted file mode 100644
index d4579ed..0000000
--- a/cpu_ref/linkloader/include/impl/ELFSymbol.hxx
+++ /dev/null
@@ -1,316 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ELF_SYMBOL_HXX
-#define ELF_SYMBOL_HXX
-
-#include "ELFSectionHeaderTable.h"
-#include "ELFSection.h"
-#include "ELFSectionStrTab.h"
-
-#include "ELFObject.h"
-#include "ELFSectionHeaderTable.h"
-#include "ELFSectionProgBits.h"
-#include "ELFSectionNoBits.h"
-
-#include "utils/rsl_assert.h"
-#include "ELF.h"
-
-template <unsigned Bitwidth>
-inline char const *ELFSymbol_CRTP<Bitwidth>::getName() const {
-  ELFSectionHeaderTableTy const &shtab = *owner->getSectionHeaderTable();
-  size_t const index = shtab.getByName(std::string(".strtab"))->getIndex();
-  ELFSectionTy const *section = owner->getSectionByIndex(index);
-  ELFSectionStrTabTy const &strtab =
-    *static_cast<ELFSectionStrTabTy const *>(section);
-  return strtab[getNameIndex()];
-}
-
-template <unsigned Bitwidth>
-template <typename Archiver>
-inline ELFSymbol<Bitwidth> *
-ELFSymbol_CRTP<Bitwidth>::read(Archiver &AR,
-                               ELFObjectTy const *owner,
-                               size_t index) {
-  if (!AR) {
-    // Archiver is in bad state before calling read function.
-    // Return NULL and do nothing.
-    return 0;
-  }
-
-  std::unique_ptr<ELFSymbolTy> sh(new ELFSymbolTy());
-
-  if (!sh->serialize(AR)) {
-    // Unable to read the structure.  Return NULL.
-    return 0;
-  }
-
-  if (!sh->isValid()) {
-    // SymTabEntry read from archiver is not valid.  Return NULL.
-    return 0;
-  }
-
-  // Set the section header index
-  sh->index = index;
-
-  // Set the owner elf object
-  sh->owner = owner;
-
-  return sh.release();
-}
-
-template <unsigned Bitwidth>
-inline void ELFSymbol_CRTP<Bitwidth>::print(bool shouldPrintHeader) const {
-  using namespace llvm;
-
-  if (shouldPrintHeader) {
-    out() << '\n' << fillformat('=', 79) << '\n';
-    out().changeColor(raw_ostream::WHITE, true);
-    out() << "ELF Symbol Table Entry "
-          << this->getIndex() << '\n';
-    out().resetColor();
-    out() << fillformat('-', 79) << '\n';
-  } else {
-    out() << fillformat('-', 79) << '\n';
-    out().changeColor(raw_ostream::YELLOW, true);
-    out() << "ELF Symbol Table Entry "
-          << this->getIndex() << " : " << '\n';
-    out().resetColor();
-  }
-
-#define PRINT_LINT(title, value) \
-  out() << format("  %-11s : ", (char const *)(title)) << (value) << '\n'
-  PRINT_LINT("Name",        getName()                                    );
-  PRINT_LINT("Type",        getTypeStr(getType())                        );
-  PRINT_LINT("Bind",        getBindingAttributeStr(getBindingAttribute()));
-  PRINT_LINT("Visibility",  getVisibilityStr(getVisibility())            );
-  PRINT_LINT("Shtab Index", getSectionIndex()                            );
-  PRINT_LINT("Value",       getValue()                                   );
-  PRINT_LINT("Size",        getSize()                                    );
-#undef PRINT_LINT
-
-// TODO: Horizontal type or vertical type can use option to decide.
-#if 0
-  using namespace term::color;
-  using namespace std;
-
-  cout << setw(20) << getName() <<
-          setw(10) << getTypeStr(getType()) <<
-          setw(10) << getBindingAttributeStr(getBindingAttribute()) <<
-          setw(15) << getVisibilityStr(getVisibility()) <<
-          setw(10) << getSectionIndex() <<
-          setw(7) << getValue() <<
-          setw(7) << getSize() <<
-          endl;
-#endif
-}
-
-template <unsigned Bitwidth>
-void *ELFSymbol_CRTP<Bitwidth>::getAddress(int machine, bool autoAlloc) const {
-  if (my_addr != 0) {
-    return my_addr;
-  }
-  size_t idx = (size_t)getSectionIndex();
-  switch (getType()) {
-    default:
-      break;
-
-    case STT_OBJECT:
-      switch (idx) {
-        default:
-          {
-            ELFSectionHeaderTableTy const *header =
-              owner->getSectionHeaderTable();
-
-            unsigned section_type = (*header)[idx]->getType();
-
-            rsl_assert((section_type == SHT_PROGBITS ||
-                        section_type == SHT_NOBITS) &&
-                       "STT_OBJECT with not BITS section.");
-
-            if (section_type == SHT_NOBITS) {
-              // FIXME(logan): This is a workaround for .lcomm directives
-              // bug of LLVM ARM MC code generator.  Remove this when the
-              // LLVM bug is fixed.
-
-              size_t align = 16;
-
-              my_addr = const_cast<ELFObjectTy *>(owner)->
-                allocateSHNCommonData((size_t)getSize(), align);
-
-              if (!my_addr) {
-                rsl_assert(0 && "Unable to allocate memory for SHN_COMMON.");
-                abort();
-              }
-            } else {
-              ELFSectionTy const *sec = owner->getSectionByIndex(idx);
-              rsl_assert(sec != 0 && "STT_OBJECT with null section.");
-
-              ELFSectionBitsTy const &st =
-                static_cast<ELFSectionBitsTy const &>(*sec);
-              my_addr =const_cast<unsigned char *>(&st[0] + (off_t)getValue());
-            }
-          }
-          break;
-
-        case SHN_COMMON:
-          {
-            if (!autoAlloc) {
-              return NULL;
-            }
-#if 0
-#if _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600
-            if (posix_memalign(&my_addr,
-                               std::max((size_t)getValue(), sizeof(void*)),
-                               (size_t)getSize()) != 0) {
-              rsl_assert(0 && "posix_memalign failed.");
-            }
-#else
-            my_addr = memalign(std::max((size_t)getValue(), sizeof(void *)),
-                               (size_t)getSize());
-
-            rsl_assert(my_addr != NULL && "memalign failed.");
-#endif
-            if (my_addr) {
-              memset(my_addr, '\0', getSize());
-            }
-#else
-            size_t align = (size_t)getValue();
-            my_addr = const_cast<ELFObjectTy *>(owner)->
-                          allocateSHNCommonData((size_t)getSize(), align);
-            if (!my_addr) {
-              rsl_assert(0 && "Unable to allocate memory for SHN_COMMON.");
-              abort();
-            }
-#endif
-          }
-          break;
-
-        case SHN_UNDEF:
-          if (machine == EM_MIPS && strcmp(getName(), "_gp_disp") == 0) // OK for MIPS
-            break;
-
-        case SHN_ABS:
-        case SHN_XINDEX:
-          rsl_assert(0 && "STT_OBJECT with special st_shndx.");
-          break;
-      }
-      break;
-
-
-    case STT_FUNC:
-      switch (idx) {
-        default:
-          {
-#ifndef NDEBUG
-            ELFSectionHeaderTableTy const *header =
-              owner->getSectionHeaderTable();
-            rsl_assert((*header)[idx]->getType() == SHT_PROGBITS &&
-                   "STT_FUNC with not PROGBITS section.");
-#endif
-            ELFSectionTy const *sec = owner->getSectionByIndex(idx);
-            rsl_assert(sec != 0 && "STT_FUNC with null section.");
-
-            ELFSectionProgBitsTy const &st =
-              static_cast<ELFSectionProgBitsTy const &>(*sec);
-            my_addr = const_cast<unsigned char *>(&st[0] + (off_t)getValue());
-          }
-          break;
-
-        case SHN_ABS:
-        case SHN_COMMON:
-        case SHN_UNDEF:
-        case SHN_XINDEX:
-          rsl_assert(0 && "STT_FUNC with special st_shndx.");
-          break;
-      }
-      break;
-
-
-    case STT_SECTION:
-      switch (idx) {
-        default:
-          {
-#ifndef NDEBUG
-            ELFSectionHeaderTableTy const *header =
-              owner->getSectionHeaderTable();
-            rsl_assert(((*header)[idx]->getType() == SHT_PROGBITS ||
-                    (*header)[idx]->getType() == SHT_NOBITS) &&
-                   "STT_SECTION with not BITS section.");
-#endif
-            ELFSectionTy const *sec = owner->getSectionByIndex(idx);
-            rsl_assert(sec != 0 && "STT_SECTION with null section.");
-
-            ELFSectionBitsTy const &st =
-              static_cast<ELFSectionBitsTy const &>(*sec);
-            my_addr = const_cast<unsigned char *>(&st[0] + (off_t)getValue());
-          }
-          break;
-
-        case SHN_ABS:
-        case SHN_COMMON:
-        case SHN_UNDEF:
-        case SHN_XINDEX:
-          rsl_assert(0 && "STT_SECTION with special st_shndx.");
-          break;
-      }
-      break;
-
-    case STT_NOTYPE:
-      switch (idx) {
-        default:
-          {
-#ifndef NDEBUG
-            ELFSectionHeaderTableTy const *header =
-              owner->getSectionHeaderTable();
-            rsl_assert(((*header)[idx]->getType() == SHT_PROGBITS ||
-                    (*header)[idx]->getType() == SHT_NOBITS) &&
-                   "STT_SECTION with not BITS section.");
-#endif
-            ELFSectionTy const *sec = owner->getSectionByIndex(idx);
-            rsl_assert(sec != 0 && "STT_SECTION with null section.");
-
-            ELFSectionBitsTy const &st =
-              static_cast<ELFSectionBitsTy const &>(*sec);
-            my_addr = const_cast<unsigned char *>(&st[0] + (off_t)getValue());
-          }
-          break;
-
-        case SHN_ABS:
-        case SHN_COMMON:
-        case SHN_XINDEX:
-          rsl_assert(0 && "STT_SECTION with special st_shndx.");
-          break;
-        case SHN_UNDEF:
-          return 0;
-      }
-      break;
-      return 0;
-
-    case STT_COMMON:
-    case STT_FILE:
-    case STT_TLS:
-    case STT_LOOS:
-    case STT_HIOS:
-    case STT_LOPROC:
-    case STT_HIPROC:
-      rsl_assert(0 && "Not implement.");
-      return 0;
-  }
-  return my_addr;
-}
-
-#endif // ELF_SYMBOL_HXX
diff --git a/cpu_ref/linkloader/include/mmanWindows.h b/cpu_ref/linkloader/include/mmanWindows.h
deleted file mode 100644
index f9c68ff..0000000
--- a/cpu_ref/linkloader/include/mmanWindows.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2013, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef MMANWINDOWS_H
-#define MMANWINDOWS_H
-
-#ifdef _WIN32
-
-#include <stdlib.h>
-#include <sys/types.h>
-
-// From bionic/libc/include/sys/mman.h
-#ifndef MAP_ANON
-#define MAP_ANON  MAP_ANONYMOUS
-#endif
-
-#define MAP_FAILED ((void *)-1)
-
-#define MREMAP_MAYMOVE  1
-#define MREMAP_FIXED    2
-
-extern void*  mmap(void *, size_t, int, int, int, off_t);
-extern int    munmap(void *, size_t);
-extern int    msync(const void *, size_t, int);
-extern int    mprotect(const void *, size_t, int);
-extern void*  mremap(void *, size_t, size_t, unsigned long);
-
-extern int    mlockall(int);
-extern int    munlockall(void);
-extern int    mlock(const void *, size_t);
-extern int    munlock(const void *, size_t);
-extern int    madvise(const void *, size_t, int);
-
-extern int    mlock(const void *addr, size_t len);
-extern int    munlock(const void *addr, size_t len);
-
-extern int    mincore(void*  start, size_t  length, unsigned char*  vec);
-
-// From bionic/libc/kernel/common/asm-generic/mman-common.h
-#define PROT_READ 0x1
-#define PROT_WRITE 0x2
-#define PROT_EXEC 0x4
-#define PROT_SEM 0x8
-#define PROT_NONE 0x0
-
-#define MAP_PRIVATE 0x02
-#define MAP_ANONYMOUS 0x20
-
-#endif  // _WIN32
-
-#endif  // MMANWINDOWS_H
diff --git a/cpu_ref/linkloader/lib/ELFHeader.cpp b/cpu_ref/linkloader/lib/ELFHeader.cpp
deleted file mode 100644
index 0b2d4ae..0000000
--- a/cpu_ref/linkloader/lib/ELFHeader.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "ELFHeader.h"
-#include "ELF.h"
-
-char const *ELFHeaderHelperMixin::getClassStr(int clazz) {
-  switch (clazz) {
-  default:
-#define CASE_PAIR(A, B) case A: return B;
-  CASE_PAIR(ELFCLASSNONE, "Invalid class")
-  CASE_PAIR(ELFCLASS32, "32bit")
-  CASE_PAIR(ELFCLASS64, "64bit")
-#undef CASE_PAIR
-  }
-}
-
-char const *ELFHeaderHelperMixin::getEndiannessStr(int endianness) {
-  switch (endianness) {
-  default:
-#define CASE_PAIR(A, B) case A: return B;
-  CASE_PAIR(ELFDATANONE, "Invalid endianness")
-  CASE_PAIR(ELFDATA2LSB, "Little endian")
-  CASE_PAIR(ELFDATA2MSB, "Big endian")
-#undef CASE_PAIR
-  }
-}
-
-char const *ELFHeaderHelperMixin::getOSABIStr(int abi) {
-  if (abi >= 64 && abi <= 255) {
-    return "Architecture specific";
-  }
-
-  switch (abi) {
-  default: return "Unknown OS ABI";
-#define CASE_PAIR(A, B) case A: return B;
-  CASE_PAIR(ELFOSABI_NONE, "No extensions or not specified")
-  CASE_PAIR(ELFOSABI_HPUX, "HP-UX")
-  CASE_PAIR(ELFOSABI_NETBSD, "NetBSD")
-  CASE_PAIR(ELFOSABI_LINUX, "Linux")
-  CASE_PAIR(ELFOSABI_SOLARIS, "Solaris")
-  CASE_PAIR(ELFOSABI_AIX, "AIX")
-  CASE_PAIR(ELFOSABI_FREEBSD, "FreeBSD")
-  CASE_PAIR(ELFOSABI_TRU64, "Tru64")
-  CASE_PAIR(ELFOSABI_MODESTO, "Modesto")
-  CASE_PAIR(ELFOSABI_OPENBSD, "OpenBSD")
-#undef CASE_PAIR
-  }
-}
-
-char const *ELFHeaderHelperMixin::getObjectTypeStr(uint16_t type) {
-  switch (type) {
-  default: return "No file type";
-
-  case ET_REL:  return "Relocatable file";
-  case ET_EXEC: return "Executable file";
-  case ET_DYN:  return "Shared object file";
-  case ET_CORE: return "Core file";
-
-  case ET_LOOS: case ET_HIOS:
-    return "Operating system-specific";
-
-  case ET_LOPROC: case ET_HIPROC:
-    return "Processor-specific";
-  }
-}
-
-char const *ELFHeaderHelperMixin::getMachineStr(uint16_t machine) {
-  switch (machine) {
-    default: return "No machine or unknown";
-    case EM_386: return "Intel 80386 (X86)";
-    case EM_X86_64: return "AMD x86-64 architecture";
-    case EM_ARM: return "Advanced RISC Machine (ARM)";
-    case EM_AARCH64: return "Advanced RISC Machine (ARM) V8";
-    case EM_MIPS: return "MIPS";
-  }
-}
-
-char const *ELFHeaderHelperMixin::getVersionStr(uint32_t version) {
-  switch (version) {
-    default: return "Invalid version";
-    case EV_CURRENT: return "Current version";
-  }
-}
diff --git a/cpu_ref/linkloader/lib/ELFSectionHeader.cpp b/cpu_ref/linkloader/lib/ELFSectionHeader.cpp
deleted file mode 100644
index 03930d6..0000000
--- a/cpu_ref/linkloader/lib/ELFSectionHeader.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "ELFSectionHeader.h"
-#include "ELF.h"
-
-// ARM Section Header Type Definitions
-
-// TODO: These definitions are not defined in external/elfutils/libelf/
-// elf.h.  So we to this by ourself.  Maybe we should update elf.h
-// instead.
-
-#ifndef SHT_ARM_EXIDX
-#define SHT_ARM_EXIDX (SHT_LOPROC + 1)
-#endif
-
-#ifndef SHT_ARM_PREEMPTMAP
-#define SHT_ARM_PREEMPTMAP (SHT_LOPROC + 2)
-#endif
-
-#ifndef SHT_ARM_ATTRIBUTES
-#define SHT_ARM_ATTRIBUTES (SHT_LOPROC + 3)
-#endif
-
-char const *ELFSectionHeaderHelperMixin::getSectionTypeStr(uint32_t type) {
-  switch (type) {
-    default: return "(UNKNOWN)";
-
-#define CASE(TYPE) \
-    case SHT_##TYPE: return #TYPE;
-
-    // General section header type
-    CASE(NULL) CASE(PROGBITS) CASE(SYMTAB) CASE(STRTAB) CASE(RELA) CASE(HASH)
-    CASE(DYNAMIC) CASE(NOTE) CASE(NOBITS) CASE(REL) CASE(SHLIB)
-    CASE(DYNSYM) CASE(INIT_ARRAY) CASE(FINI_ARRAY) CASE(PREINIT_ARRAY)
-    CASE(GROUP) CASE(SYMTAB_SHNDX) CASE(LOOS) CASE(HIOS) CASE(LOPROC)
-    CASE(HIPROC) CASE(LOUSER) CASE(HIUSER)
-
-    // ARM-specific section header type
-    CASE(ARM_EXIDX) CASE(ARM_PREEMPTMAP) CASE(ARM_ATTRIBUTES)
-
-#undef CASE
-  }
-}
diff --git a/cpu_ref/linkloader/lib/ELFSymbol.cpp b/cpu_ref/linkloader/lib/ELFSymbol.cpp
deleted file mode 100644
index cfdab1c..0000000
--- a/cpu_ref/linkloader/lib/ELFSymbol.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "ELFSymbol.h"
-#include "ELF.h"
-
-char const *
-ELFSymbolHelperMixin::getTypeStr(uint8_t type) {
-  switch (type) {
-    default: return "(UNKNOWN)";
-
-#define CASE(TYPE) \
-    case STT_##TYPE: return #TYPE;
-
-    CASE(NOTYPE)
-    CASE(OBJECT)
-    CASE(FUNC)
-    CASE(SECTION)
-    CASE(FILE)
-    CASE(COMMON)
-    CASE(TLS)
-    CASE(LOOS)
-    CASE(HIOS)
-    CASE(LOPROC)
-    CASE(HIPROC)
-
-#undef CASE
-  }
-}
-
-char const *
-ELFSymbolHelperMixin::getBindingAttributeStr(uint8_t type) {
-  switch (type) {
-    default: return "(UNKNOWN)";
-
-#define CASE(TYPE) \
-    case STB_##TYPE: return #TYPE;
-
-    CASE(LOCAL)
-    CASE(GLOBAL)
-    CASE(WEAK)
-    CASE(LOOS)
-    CASE(HIOS)
-    CASE(LOPROC)
-    CASE(HIPROC)
-
-#undef CASE
-  }
-}
-char const *
-ELFSymbolHelperMixin::getVisibilityStr(uint8_t type) {
-  switch (type) {
-    default: return "(UNKNOWN)";
-
-#define CASE(TYPE) \
-    case STV_##TYPE: return #TYPE;
-
-    CASE(DEFAULT)
-    CASE(INTERNAL)
-    CASE(HIDDEN)
-    CASE(PROTECTED)
-
-#undef CASE
-  }
-}
diff --git a/cpu_ref/linkloader/lib/ELFTypes.cpp b/cpu_ref/linkloader/lib/ELFTypes.cpp
deleted file mode 100644
index 7c82eab..0000000
--- a/cpu_ref/linkloader/lib/ELFTypes.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "ELFTypes.h"
-#include <llvm/Support/raw_ostream.h>
-#include <llvm/Support/Format.h>
-
-namespace detail {
-
-#define ELF_TYPE_PRINT_OPERATOR(TYPE, FORMAT_WIDTH)                         \
-  llvm::raw_ostream &operator<<(llvm::raw_ostream &os, TYPE const &val) {   \
-    os << llvm::format("%0*x", FORMAT_WIDTH, val.value);                    \
-    return os;                                                              \
-  }
-
-  ELF_TYPE_PRINT_OPERATOR(ELF32Address, 8)
-  ELF_TYPE_PRINT_OPERATOR(ELF32Offset,  8)
-  ELF_TYPE_PRINT_OPERATOR(ELF64Address, 16)
-  ELF_TYPE_PRINT_OPERATOR(ELF64Offset,  16)
-
-#undef ELF_TYPE_PRINT_OPERATOR
-
-} // end namespace detail
diff --git a/cpu_ref/linkloader/lib/GOT.cpp b/cpu_ref/linkloader/lib/GOT.cpp
deleted file mode 100644
index 3372cfa..0000000
--- a/cpu_ref/linkloader/lib/GOT.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include "GOT.h"
-
-static void **got_symbol_addresses = NULL;
-static int got_symbol_indexes[NUM_OF_GOT_ENTRY];
-static size_t got_symbol_count = 0;
-
-void *got_address()
-{
-  return &got_symbol_addresses[0];
-}
-
-void set_got_address(void *addr)
-{
-  got_symbol_addresses = (void **) addr;
-  got_symbol_count = 0;
-}
-
-int search_got(int symbol_index, void *addr, uint8_t bind_type)
-{
-  size_t i;
-
-  // For local symbols (R_MIPS_GOT16), we only store the high 16-bit value
-  // after adding 0x8000.
-  if (bind_type == STB_LOCAL)
-#ifdef __LP64__
-    addr = (void *)(((intptr_t)addr + 0x8000) & 0xFFFFFFFFFFFF0000);
-#else
-    addr = (void *)(((intptr_t)addr + 0x8000) & 0xFFFF0000);
-#endif
-
-
-  for (i = 0; i < got_symbol_count; i++) {
-    if (got_symbol_indexes[i] == symbol_index) {
-      if (bind_type == STB_LOCAL) {
-        // Check if the value is the same for local symbols.
-        // If yes, we can reuse this entry.
-        // If not, we continue searching.
-        if (got_symbol_addresses[i] == addr) {
-          return i;
-        }
-      }
-      else {
-        // The value must be the same for global symbols .
-        rsl_assert (got_symbol_addresses[i] == addr
-                    && "MIPS GOT address error.");
-        return i;
-      }
-    }
-  }
-
-  // Cannot find this symbol with correct value, so we need to create one
-  rsl_assert (got_symbol_count < NUM_OF_GOT_ENTRY && "MIPS GOT is full.");
-  got_symbol_indexes[got_symbol_count] = symbol_index;
-  got_symbol_addresses[got_symbol_count] = addr;
-  got_symbol_count++;
-  return (got_symbol_count - 1);
-}
diff --git a/cpu_ref/linkloader/lib/MemChunk.cpp b/cpu_ref/linkloader/lib/MemChunk.cpp
deleted file mode 100644
index 8a9b548..0000000
--- a/cpu_ref/linkloader/lib/MemChunk.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "MemChunk.h"
-
-#include "utils/flush_cpu_cache.h"
-#include "utils/helper.h"
-
-#include <llvm/Support/raw_ostream.h>
-
-#ifndef USE_MINGW       /* TODO create a proper HAVE_MMAN_H */
-#include <sys/mman.h>
-#else
-#include "mmanWindows.h"
-#endif
-
-#include <stdlib.h>
-
-#ifndef MAP_32BIT
-#define MAP_32BIT 0
-// Note: If the <sys/mman.h> does not come with MAP_32BIT, then we
-// define it as zero, so that it won't manipulate the flags.
-#endif
-
-//#define USE_FIXED_ADDR_MEM_CHUNK 1
-
-#if USE_FIXED_ADDR_MEM_CHUNK
-static uintptr_t StartAddr = 0x7e000000UL;
-#endif
-
-AllocFunc MemChunk::VendorAlloc = nullptr;
-FreeFunc MemChunk::VendorFree = nullptr;
-
-MemChunk::MemChunk() : buf(nullptr), buf_size(0), bVendorBuf(true) {
-}
-
-MemChunk::~MemChunk() {
-  if (!invalidBuf() && bVendorBuf && VendorFree) {
-    (*VendorFree)(buf);
-    return;
-  }
-  if (!invalidBuf()) {
-    munmap(buf, buf_size);
-  }
-}
-
-bool MemChunk::invalidBuf() const {
-  return (buf == 0 || buf == (unsigned char *)MAP_FAILED);
-}
-
-bool MemChunk::allocate(size_t size) {
-  if (size == 0) {
-    return true;
-  }
-  if (VendorAlloc) {
-    buf = (unsigned char*)(*VendorAlloc)(size, 0);
-  }
-  if (invalidBuf()) {
-    bVendorBuf = false;
-#if USE_FIXED_ADDR_MEM_CHUNK
-    buf = (unsigned char *)mmap((void *)StartAddr, size,
-                                PROT_READ | PROT_WRITE,
-                                MAP_PRIVATE | MAP_ANON | MAP_32BIT,
-                                -1, 0);
-#else
-    buf = (unsigned char *)mmap(0, size,
-                                PROT_READ | PROT_WRITE,
-                                MAP_PRIVATE | MAP_ANON | MAP_32BIT,
-                                -1, 0);
-#endif
-  }
-
-  if (invalidBuf()) {
-    return false;
-  }
-
-#if USE_FIXED_ADDR_MEM_CHUNK
-  StartAddr += (size + 4095) / 4096 * 4096;
-#endif
-
-  buf_size = size;
-  return true;
-}
-
-void MemChunk::print() const {
-  if (!invalidBuf()) {
-    dump_hex(buf, buf_size, 0, buf_size);
-  }
-}
-
-bool MemChunk::protect(int prot) {
-  if (buf_size > 0) {
-    int ret = mprotect((void *)buf, buf_size, prot);
-    if (ret == -1) {
-      llvm::errs() << "Error: Can't mprotect.\n";
-      return false;
-    }
-
-    if (prot & PROT_EXEC) {
-      FLUSH_CPU_CACHE(buf, buf + buf_size);
-    }
-  }
-
-  return true;
-}
diff --git a/cpu_ref/linkloader/lib/StubLayout.cpp b/cpu_ref/linkloader/lib/StubLayout.cpp
deleted file mode 100644
index 1ff9e16..0000000
--- a/cpu_ref/linkloader/lib/StubLayout.cpp
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "StubLayout.h"
-
-#include "utils/flush_cpu_cache.h"
-#include "utils/raw_ostream.h"
-#include "utils/rsl_assert.h"
-
-#include <stdint.h>
-#include <stdlib.h>
-
-StubLayout::StubLayout() : table(nullptr), count(0) {
-}
-
-void StubLayout::initStubTable(unsigned char *table_, size_t count_) {
-  table = table_;
-  count = count_;
-}
-
-void *StubLayout::allocateStub(void *addr) {
-  // Check if we have created this stub or not.
-  std::map<void *, void *>::iterator index_iter = stub_index.find(addr);
-
-  if (index_iter != stub_index.end()) {
-    return index_iter->second;
-  }
-
-  // We have to create a new stub
-  if (count == 0) {
-    // No free stub slot is available
-    return nullptr;
-  }
-
-  // Initialize the stub
-  unsigned char *stub = table;
-  setStubAddress(stub, addr);
-  stub_index.insert(std::make_pair(addr, stub));
-
-  // Increase the free stub slot pointer
-  table += getUnitStubSize();
-  count--;
-
-  return stub;
-}
-
-size_t StubLayout::calcStubTableSize(size_t count) const {
-  return count * getUnitStubSize();
-}
-
-size_t StubLayoutAARCH64::getUnitStubSize() const {
-  return 16;
-}
-
-void StubLayoutAARCH64::setStubAddress(void *stub_, void *addr) {
-  uint8_t *stub = (uint8_t *)stub_;
-
-  // First instruction:
-  // ldr x16,[pc,#8]        LDR literal (pc relative)
-  // +--+---+-+--+-------------------+-----+
-  // |01|011|0|00| (#8 >> 2) = 10    |10000|
-  // +--+---+-+--+-------------------+-----+
-  // 0x58000050
-  // Little endian.
-  stub[0] = 0x50;
-  stub[1] = 0x00;
-  stub[2] = 0x00;
-  stub[3] = 0x58;
-
-  // Next Instruction:
-  // br x16
-  // +-------+--+--+-----+------+-----+-----+
-  // |1101011|00|00|11111|000000|10000|00000|
-  // +-------+--+--+-----+------+-----+-----+
-  // 0xd61f0200
-
-  stub += 4;
-  stub[0] = 0x00;
-  stub[1] = 0x02;
-  stub[2] = 0x1f;
-  stub[3] = 0xd6;
-
-  // Now the absolute address (64 bits).
-  uint64_t *target = reinterpret_cast<uint64_t*>(stub + 4);
-  *target = reinterpret_cast<uint64_t>(addr);
-}
-
-size_t StubLayoutARM::getUnitStubSize() const {
-  return 8;
-}
-
-void StubLayoutARM::setStubAddress(void *stub_, void *addr) {
-  uint8_t *stub = (uint8_t *)stub_;
-  stub[0] = 0x04; // ldr pc, [pc, #-4]
-  stub[1] = 0xf0; // ldr pc, [pc, #-4]
-  stub[2] = 0x1f; // ldr pc, [pc, #-4]
-  stub[3] = 0xe5; // ldr pc, [pc, #-4]
-
-  void **target = (void **)(stub + 4);
-  *target = addr;
-}
-
-size_t StubLayoutMIPS::getUnitStubSize() const {
-  return 16;
-}
-
-void StubLayoutMIPS::setStubAddress(void *stub_, void *addr) {
-  uint32_t addr32 = (uint32_t)(uintptr_t)addr;
-  uint16_t addr_hi16 = (addr32 >> 16) &  0xffff;
-  uint16_t addr_lo16 = addr32 & 0xffff;
-
-  uint32_t *stub = (uint32_t *)stub_;
-  stub[0] = 0x3c190000ul | addr_hi16; // lui
-  stub[1] = 0x37390000ul | addr_lo16; // ori
-  stub[2] = 0x03200008ul; // jr (jump register)
-  stub[3] = 0x00000000ul; // nop
-}
-
-size_t StubLayoutX86::getUnitStubSize() const {
-  return 8;
-}
-
-void StubLayoutX86::setStubAddress(void *stub_, void *addr) {
-  uint8_t *stub = (uint8_t *)stub_;
-  stub[0] = 0xE9; // 32-bit pc-relative jump.
-  void **target = (void **)(stub + 1);
-  *target = addr;
-}
-
-size_t StubLayoutX86_64::getUnitStubSize() const {
-  return 16;
-}
-
-void StubLayoutX86_64::setStubAddress(void *stub_, void *addr) {
-  // x86 doesn't have proper register/mem to store the jump destination
-  // use below instructions to jump to the specified address
-
-  // jmp *0x0(%rip);       jump to the location which is stored in next instruction
-  // addr;                 this is not a real instruction, just an address
-  uint8_t *stub = (uint8_t*)stub_;
-  stub[0] = 0xff;
-  stub[1] = 0x25;
-  stub[2] = 0x0;
-  stub[3] = 0x0;
-  stub[4] = 0x0;
-  stub[5] = 0x0;
-  uint64_t *target = reinterpret_cast<uint64_t*>(stub + 6);
-  *target = reinterpret_cast<uint64_t>(addr);
-}
-
diff --git a/cpu_ref/linkloader/lib/mmanWindows.cpp b/cpu_ref/linkloader/lib/mmanWindows.cpp
deleted file mode 100644
index 1b4d608..0000000
--- a/cpu_ref/linkloader/lib/mmanWindows.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2013, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifdef USE_MINGW
-
-#include "mmanWindows.h"
-
-void* mmap(void *, size_t, int, int, int, off_t) {
-  return MAP_FAILED;
-}
-
-int munmap(void *, size_t) {
-  return -1;
-}
-
-int mprotect(const void *, size_t, int) {
-  return -1;
-}
-
-#endif  // USE_MINGW
diff --git a/cpu_ref/linkloader/main.cpp b/cpu_ref/linkloader/main.cpp
deleted file mode 100644
index 011e1d7..0000000
--- a/cpu_ref/linkloader/main.cpp
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "ELFObject.h"
-
-#include "utils/serialize.h"
-#include "ELF.h"
-
-#include <fcntl.h>
-#include <stdlib.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <map>
-#include <stdio.h>
-#include <stdarg.h>
-
-using namespace std;
-
-bool open_mmap_file(char const *filename,
-                    int &fd,
-                    unsigned char const *&image,
-                    size_t &size);
-
-void close_mmap_file(int fd,
-                     unsigned char const *image,
-                     size_t size);
-
-void dump_and_run_file(unsigned char const *image, size_t size,
-                       int argc, char **argv);
-
-int main(int argc, char **argv) {
-  // Check arguments
-  if (argc < 2) {
-    llvm::errs() << "USAGE: " << argv[0] << " [ELFObjectFile] [ARGS]\n";
-    exit(EXIT_FAILURE);
-  }
-
-  // Filename from argument
-  char const *filename = argv[1];
-
-  // Open the file
-  int fd = -1;
-  unsigned char const *image = nullptr;
-  size_t image_size = 0;
-
-  if (!open_mmap_file(filename, fd, image, image_size)) {
-    exit(EXIT_FAILURE);
-  }
-
-  // Dump and run the file
-  dump_and_run_file(image, image_size, argc - 1, argv + 1);
-
-  // Close the file
-  close_mmap_file(fd, image, image_size);
-
-  return EXIT_SUCCESS;
-}
-
-// FIXME: I don't like these stub as well.  However, before we implement
-// x86 64bit far jump stub, we have to ensure find_sym only returns
-// near address.
-
-int stub_printf(char const *fmt, ...) {
-  va_list ap;
-  va_start(ap, fmt);
-  int result = vprintf(fmt, ap);
-  va_end(ap);
-  return result;
-}
-
-int stub_scanf(char const *fmt, ...) {
-  va_list ap;
-  va_start(ap, fmt);
-  int result = vscanf(fmt, ap);
-  va_end(ap);
-  return result;
-}
-
-void stub_srand(unsigned int seed) {
-  srand(seed);
-}
-
-int stub_rand() {
-  return rand();
-}
-
-time_t stub_time(time_t *output) {
-  return time(output);
-}
-
-void *find_sym(void *context, char const *name) {
-  struct func_entry_t {
-    char const *name;
-    size_t name_len;
-    void *addr;
-  };
-
-  static func_entry_t const tab[] = {
-#define DEF(NAME, ADDR) \
-    { NAME, sizeof(NAME) - 1, (void *)(ADDR) },
-
-    DEF("printf", stub_printf)
-    DEF("scanf", stub_scanf)
-    DEF("__isoc99_scanf", stub_scanf)
-    DEF("rand", stub_rand)
-    DEF("time", stub_time)
-    DEF("srand", stub_srand)
-#undef DEF
-  };
-
-  static size_t const tab_size = sizeof(tab) / sizeof(func_entry_t);
-
-  // Note: Since our table is small, we are using trivial O(n) searching
-  // function.  For bigger table, it will be better to use binary
-  // search or hash function.
-  size_t name_len = strlen(name);
-  for (size_t i = 0; i < tab_size; ++i) {
-    if (name_len == tab[i].name_len && strcmp(name, tab[i].name) == 0) {
-      return tab[i].addr;
-    }
-  }
-
-  assert(0 && "Can't find symbol.");
-  return nullptr;
-}
-
-template <unsigned Bitwidth, typename Archiver>
-void dump_and_run_object(Archiver &AR, int argc, char **argv) {
-  std::unique_ptr<ELFObject<Bitwidth> > object(ELFObject<Bitwidth>::read(AR));
-
-  if (!object) {
-    llvm::errs() << "ERROR: Unable to load object\n";
-  }
-
-  object->print();
-  out().flush();
-
-  ELFSectionSymTab<Bitwidth> *symtab =
-    static_cast<ELFSectionSymTab<Bitwidth> *>(
-        object->getSectionByName(".symtab"));
-
-  object->relocate(find_sym, 0);
-  out() << "relocate finished!\n";
-  out().flush();
-
-  int machine = object->getHeader()->getMachine();
-
-  void *main_addr = symtab->getByName("main")->getAddress(machine);
-  out() << "main address: " << main_addr << "\n";
-  out().flush();
-
-  ((int (*)(int, char **))main_addr)(argc, argv);
-  fflush(stdout);
-}
-
-template <typename Archiver>
-void dump_and_run_file_from_archive(bool is32bit, Archiver &AR,
-                                    int argc, char **argv) {
-  if (is32bit) {
-    dump_and_run_object<32>(AR, argc, argv);
-  } else {
-    dump_and_run_object<64>(AR, argc, argv);
-  }
-}
-
-void dump_and_run_file(unsigned char const *image, size_t size,
-                       int argc, char **argv) {
-  if (size < EI_NIDENT) {
-    llvm::errs() << "ERROR: ELF identification corrupted.\n";
-    return;
-  }
-
-  if (image[EI_DATA] != ELFDATA2LSB && image[EI_DATA] != ELFDATA2MSB) {
-    llvm::errs() << "ERROR: Unknown endianness.\n";
-    return;
-  }
-
-  if (image[EI_CLASS] != ELFCLASS32 && image[EI_CLASS] != ELFCLASS64) {
-    llvm::errs() << "ERROR: Unknown machine class.\n";
-    return;
-  }
-
-  bool isLittleEndian = (image[EI_DATA] == ELFDATA2LSB);
-  bool is32bit = (image[EI_CLASS] == ELFCLASS32);
-
-  if (isLittleEndian) {
-    ArchiveReaderLE AR(image, size);
-    dump_and_run_file_from_archive(is32bit, AR, argc, argv);
-  } else {
-    ArchiveReaderBE AR(image, size);
-    dump_and_run_file_from_archive(is32bit, AR, argc, argv);
-  }
-}
-
-bool open_mmap_file(char const *filename,
-                    int &fd,
-                    unsigned char const *&image,
-                    size_t &size) {
-  // Query the file status
-  struct stat sb;
-  if (stat(filename, &sb) != 0) {
-    llvm::errs() << "ERROR: " << filename << " not found.\n";
-    return false;
-  }
-
-  if (!S_ISREG(sb.st_mode)) {
-    llvm::errs() << "ERROR: " << filename << " is not a regular file.\n";
-    return false;
-  }
-
-  size = (size_t)sb.st_size;
-
-  // Open the file in readonly mode
-  fd = open(filename, O_RDONLY);
-  if (fd < 0) {
-    llvm::errs() << "ERROR: Unable to open " << filename << "\n";
-    return false;
-  }
-
-  // Map the file image
-  image = static_cast<unsigned char const *>(
-    mmap(0, size, PROT_READ, MAP_PRIVATE, fd, 0));
-
-  if (image == MAP_FAILED) {
-    llvm::errs() << "ERROR: Unable to map " << filename << " to memory.\n";
-    close(fd);
-    return false;
-  }
-
-  return true;
-}
-
-void close_mmap_file(int fd,
-                     unsigned char const *image,
-                     size_t size) {
-  if (image) {
-    munmap((void *)image, size);
-  }
-
-  if (fd >= 0) {
-    close(fd);
-  }
-}
diff --git a/cpu_ref/linkloader/utils/flush_cpu_cache.h b/cpu_ref/linkloader/utils/flush_cpu_cache.h
deleted file mode 100644
index e0bc20c..0000000
--- a/cpu_ref/linkloader/utils/flush_cpu_cache.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef FLUSH_CPU_CACHE_H
-#define FLUSH_CPU_CACHE_H
-
-#if defined(__arm__) || defined(__aarch64__) || defined(__mips__)
-#define FLUSH_CPU_CACHE(BEGIN, END) __builtin___clear_cache((char *)(BEGIN), (char *)(END))
-#else
-#define FLUSH_CPU_CACHE(BEGIN, END) do { } while (0)
-#endif
-
-#endif // FLUSH_CPU_CACHE_H
diff --git a/cpu_ref/linkloader/utils/helper.cpp b/cpu_ref/linkloader/utils/helper.cpp
deleted file mode 100644
index 2dce54f..0000000
--- a/cpu_ref/linkloader/utils/helper.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "helper.h"
-#include "raw_ostream.h"
-
-#include <stdlib.h>
-#include <ctype.h>
-
-using namespace llvm;
-
-void dump_hex(unsigned char const *data,
-              size_t size, size_t begin, size_t end) {
-  if (end <= begin) {
-    // Nothing to print now.  Return directly.
-    return;
-  }
-
-  size_t lower = begin & (~0xfUL);
-  size_t upper = (end & (~0xfUL)) ? end : ((end + 16UL) & (~0xfUL));
-
-  for (size_t i = lower; i < upper; i += 16) {
-    out() << format("%08x", i) << ':';
-
-    if (i < begin) {
-      out().changeColor(raw_ostream::MAGENTA);
-    }
-
-    for (size_t j = i, k = i + 16; j < k; ++j) {
-      if (j == begin) {
-        out().resetColor();
-      }
-
-      if (j == end) {
-        out().changeColor(raw_ostream::MAGENTA);
-      }
-
-      if (j < size) {
-        out() << ' ' << format("%02x", (unsigned)data[j]);
-      }
-    }
-
-    out().resetColor();
-    out() << "  ";
-
-    for (size_t j = i, k = i + 16; j < k; ++j) {
-      if (data[j] > 0x20 && data[j] < 0x7f) {
-        out() << (char)data[j];
-      } else {
-        out() << '.';
-      }
-    }
-
-    out() << '\n';
-  }
-}
diff --git a/cpu_ref/linkloader/utils/helper.h b/cpu_ref/linkloader/utils/helper.h
deleted file mode 100644
index 000666a..0000000
--- a/cpu_ref/linkloader/utils/helper.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef HELPER_H
-#define HELPER_H
-
-#include <stdlib.h>
-
-extern void dump_hex(unsigned char const *data,
-                     size_t size, size_t begin, size_t end);
-
-#endif // HELPER_H
diff --git a/cpu_ref/linkloader/utils/raw_ostream.cpp b/cpu_ref/linkloader/utils/raw_ostream.cpp
deleted file mode 100644
index 7efd10e..0000000
--- a/cpu_ref/linkloader/utils/raw_ostream.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "raw_ostream.h"
-
-#include <llvm/Support/raw_ostream.h>
-#include <llvm/Support/Format.h>
-#include <cstdarg>
-#include <cstring>
-
-llvm::raw_ostream &out() {
-  static llvm::raw_ostream &singleton = llvm::outs();
-  return singleton;
-}
-
-MyFormat const fillformat(char const fill_char, // Fill character.
-                          int const length,     // Fill Width.
-                          char const *format_s, // Format string.
-                          ...) {                // Format variable.
-  using namespace std;
-  struct MyFormat t_format;
-  va_list valist;
-  va_start(valist, format_s);
-  t_format.ptr = new char[length+1];
-  t_format.ptr[length] = '\0';
-  vsnprintf(t_format.ptr, length, format_s, valist);
-  int real_len = strlen(t_format.ptr);
-  int fill_len = length;
-  memmove(t_format.ptr + fill_len, t_format.ptr, real_len);
-  memset(t_format.ptr, fill_char, fill_len);
-  return t_format;
-}
-
-llvm::raw_ostream &operator<<(llvm::raw_ostream &os, MyFormat const &mf) {
-  os << mf.ptr;
-  delete mf.ptr;
-  return os;
-}
diff --git a/cpu_ref/linkloader/utils/raw_ostream.h b/cpu_ref/linkloader/utils/raw_ostream.h
deleted file mode 100644
index 0f7a5be..0000000
--- a/cpu_ref/linkloader/utils/raw_ostream.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef RAW_OSTREAM_H
-#define RAW_OSTREAM_H
-
-#include <llvm/Support/raw_ostream.h>
-#include <llvm/Support/Format.h>
-
-extern llvm::raw_ostream &out();
-struct MyFormat {
-  char *ptr;
-};
-extern MyFormat const fillformat(char const,        // Fill character.
-                                 int const,         // Fill Width.
-                                 char const * = "", // Format string.
-                                 ...);              // Format variable.
-extern llvm::raw_ostream &operator<<(llvm::raw_ostream &, MyFormat const &);
-
-#endif // RAW_OSTREAM_H
diff --git a/cpu_ref/linkloader/utils/rsl_assert.cpp b/cpu_ref/linkloader/utils/rsl_assert.cpp
deleted file mode 100644
index cdd3207..0000000
--- a/cpu_ref/linkloader/utils/rsl_assert.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "rsl_assert.h"
-
-#include <llvm/Support/raw_ostream.h>
-
-#include <stdlib.h>
-
-#if !defined(__HOST__)
-#define LOG_TAG "bcc"
-#include <cutils/log.h>
-#endif
-
-extern "C" void ASSERT_FAILED(char const *file,
-                              unsigned line,
-                              char const *expr) {
-#if defined(__HOST__)
-  llvm::errs() << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
-  llvm::errs() << "rslAssert [" << file << ":" << line << "] " << expr << "\n";
-  llvm::errs() << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
-#else
-  ALOGE("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
-  ALOGE("rslAssert [%s:%d] %s\n", file, line, expr);
-  ALOGE("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
-#endif
-
-  abort();
-}
diff --git a/cpu_ref/linkloader/utils/rsl_assert.h b/cpu_ref/linkloader/utils/rsl_assert.h
deleted file mode 100644
index cd20b83..0000000
--- a/cpu_ref/linkloader/utils/rsl_assert.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef RSL_ASSERT_H
-#define RSL_ASSERT_H
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-extern void ASSERT_FAILED(char const *file,
-                          unsigned line,
-                          char const *expr);
-
-#if defined(__cplusplus)
-} // extern "C"
-#endif
-
-#ifdef RSL_NDEBUG
-
-#define rsl_assert(EXPR) \
-  do { } while (0)
-
-#else
-
-#define rsl_assert(EXPR)                                      \
-  do {                                                        \
-    if (!(EXPR)) {                                            \
-      ASSERT_FAILED(__FILE__, __LINE__, #EXPR);               \
-    }                                                         \
-  } while (0)
-
-#endif
-
-#endif // RSL_ASSERT_H
diff --git a/cpu_ref/linkloader/utils/serialize.h b/cpu_ref/linkloader/utils/serialize.h
deleted file mode 100644
index 49ba400..0000000
--- a/cpu_ref/linkloader/utils/serialize.h
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#if !defined(SERIALIZE_H)
-#define SERIALIZE_H
-
-#include "traits.h"
-
-#include <algorithm>
-#include <vector>
-
-#include "utils/rsl_assert.h"
-#include <string.h>
-#include <stdint.h>
-#include <stddef.h>
-
-namespace detail {
-  inline bool is_host_little_endian() {
-    unsigned long one = 0x1UL;
-    return *reinterpret_cast<unsigned char *>(&one);
-  }
-
-  inline void swap_byte_order(unsigned char (&array)[1]) {
-    // Nothing to do
-  }
-
-  inline void swap_byte_order(unsigned char (&array)[2]) {
-    std::swap(array[0], array[1]);
-  }
-
-  inline void swap_byte_order(unsigned char (&array)[4]) {
-    std::swap(array[0], array[3]);
-    std::swap(array[1], array[2]);
-  }
-
-  inline void swap_byte_order(unsigned char (&array)[8]) {
-    std::swap(array[0], array[7]);
-    std::swap(array[1], array[6]);
-    std::swap(array[2], array[5]);
-    std::swap(array[3], array[4]);
-  }
-}
-
-
-template <bool isArchiveLittleEndian>
-class ArchiveReader {
-private:
-  unsigned char const *buf_begin;
-  unsigned char const *buf_end;
-  unsigned char const *cursor;
-  unsigned char const *cursor_base;
-
-  bool good;
-
-public:
-  ArchiveReader(unsigned char const *buf = nullptr, size_t size = 0)
-  : buf_begin(buf), buf_end(buf + size),
-    cursor(buf), cursor_base(nullptr), good(buf != nullptr) {
-  }
-
-  void prologue(size_t size) {
-    rsl_assert(cursor_base == nullptr);
-    cursor_base = cursor;
-  }
-
-  void epilogue(size_t size) {
-    rsl_assert(cursor_base != nullptr);
-    rsl_assert(cursor_base + size >= cursor);
-    cursor = cursor_base + size;
-    cursor_base = nullptr;
-  }
-
-  void seek(off_t off, bool from_begin = false) {
-    if (from_begin) {
-      cursor = buf_begin + off;
-    } else {
-      cursor += off;
-    }
-  }
-
-  void readBytes(void *array, size_t size) {
-    if (!good || cursor + size > buf_end) {
-      good = false;
-    } else {
-      memcpy(array, cursor, size);
-    }
-  }
-
-  template <size_t size>
-  void operator&(char (&array)[size]) {
-    readBytes(array, size);
-    seek(size);
-  }
-
-  template <size_t size>
-  void operator&(unsigned char (&array)[size]) {
-    readBytes(array, size);
-    seek(size);
-  }
-
-  template <typename T>
-  void operator&(T &v) {
-    seekAlignment<T>();
-    readBytes(&v, TypeTraits<T>::size);
-    seek(TypeTraits<T>::size);
-
-    if (isArchiveLittleEndian != detail::is_host_little_endian()) {
-      detail::swap_byte_order(
-        reinterpret_cast<unsigned char (&)[TypeTraits<T>::size]>(v));
-    }
-  }
-
-  operator void const *() const {
-    return good ? this : 0;
-  }
-
-  bool operator!() const {
-    return !good;
-  }
-
-private:
-  template <typename T>
-  void seekAlignment() {
-    size_t align = TypeTraits<T>::align;
-    size_t delta = static_cast<size_t>(cursor - buf_begin) % align;
-
-    if (delta > 0) {
-      seek(align - delta);
-    }
-  }
-
-};
-
-typedef ArchiveReader<true>  ArchiveReaderLE;
-typedef ArchiveReader<false> ArchiveReaderBE;
-
-#endif // SERIALIZE_H
diff --git a/cpu_ref/linkloader/utils/traits.h b/cpu_ref/linkloader/utils/traits.h
deleted file mode 100644
index df7e7f7..0000000
--- a/cpu_ref/linkloader/utils/traits.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2011, 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef TRAITS_H
-#define TRAITS_H
-
-#include <stddef.h>
-
-template <typename Type>
-struct TypeTraits {
-private:
-  struct AlignmentTest {
-    char pending;
-    Type element;
-  };
-
-public:
-  enum { size = sizeof(Type) };
-  enum { align = offsetof(AlignmentTest, element) };
-};
-
-#define TYPE_TRAITS_SPECIALIZE(TYPE, SIZE, ALIGN) \
-template <> \
-struct TypeTraits<TYPE> { \
-  enum { size = SIZE }; \
-  enum { align = ALIGN }; \
-};
-
-#endif // TRAITS_H
diff --git a/cpu_ref/rsCpuIntrinsicColorMatrix.cpp b/cpu_ref/rsCpuIntrinsicColorMatrix.cpp
index 467cc27..e629dea 100644
--- a/cpu_ref/rsCpuIntrinsicColorMatrix.cpp
+++ b/cpu_ref/rsCpuIntrinsicColorMatrix.cpp
@@ -19,8 +19,6 @@
 
 #include "rsCpuIntrinsic.h"
 #include "rsCpuIntrinsicInlines.h"
-#include "linkloader/include/MemChunk.h"
-#include "linkloader/utils/flush_cpu_cache.h"
 
 #include <sys/mman.h>
 #include <stddef.h>
@@ -735,7 +733,7 @@
         return false;
     }
 
-    FLUSH_CPU_CACHE(mBuf, (char*) mBuf + mBufSize);
+    __builtin___clear_cache((char *) mBuf, (char*) mBuf + mBufSize);
     return true;
 #else
     return false;
diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp
index f312866..f341b4e 100644
--- a/cpu_ref/rsCpuScript.cpp
+++ b/cpu_ref/rsCpuScript.cpp
@@ -25,7 +25,6 @@
     #include <bcc/BCCContext.h>
     #include <bcc/Config/Config.h>
     #include <bcc/Renderscript/RSCompilerDriver.h>
-    #include <bcc/Renderscript/RSExecutable.h>
     #include <bcc/Renderscript/RSInfo.h>
     #include <bcinfo/MetadataExtractor.h>
     #include <cutils/properties.h>
@@ -245,10 +244,6 @@
 
 #ifndef RS_COMPATIBILITY_LIB
 
-static inline bool is_skip_linkloader() {
-  return true;
-}
-
 static bool is_force_recompile() {
 #ifdef RS_SERVER
   return false;
@@ -308,10 +303,8 @@
         }
     }
 
-    if (is_skip_linkloader()) {
-        args->push_back("-fPIC");
-        args->push_back("-embedRSInfo");
-    }
+    args->push_back("-fPIC");
+    args->push_back("-embedRSInfo");
 
     args->push_back(bcFileName.c_str());
     args->push_back(nullptr);
@@ -482,7 +475,6 @@
 
 #ifndef RS_COMPATIBILITY_LIB
     mCompilerDriver = nullptr;
-    mExecutable = nullptr;
 #endif
 
 
@@ -703,37 +695,6 @@
     return false;
 }
 
-#ifndef RS_COMPATIBILITY_LIB
-bool RsdCpuScriptImpl::storeRSInfoFromObj(bcinfo::MetadataExtractor &bitcodeMetadata) {
-
-    mExecutable->setThreadable(mIsThreadable);
-    if (!mExecutable->syncInfo()) {
-        ALOGW("bcc: FAILS to synchronize the RS info file to the disk");
-    }
-
-    mRoot = reinterpret_cast<int (*)()>(mExecutable->getSymbolAddress("root"));
-    mRootExpand =
-        reinterpret_cast<int (*)()>(mExecutable->getSymbolAddress("root.expand"));
-    mInit = reinterpret_cast<void (*)()>(mExecutable->getSymbolAddress("init"));
-    mFreeChildren =
-        reinterpret_cast<void (*)()>(mExecutable->getSymbolAddress(".rs.dtor"));
-
-
-    if (bitcodeMetadata.getExportVarCount()) {
-        mBoundAllocs = new Allocation *[bitcodeMetadata.getExportVarCount()];
-        memset(mBoundAllocs, 0, sizeof(void *) * bitcodeMetadata.getExportVarCount());
-    }
-
-    for (size_t i = 0; i < bitcodeMetadata.getExportForEachSignatureCount(); i++) {
-        char* name = new char[strlen(bitcodeMetadata.getExportForEachNameList()[i]) + 1];
-        mExportedForEachFuncList.push_back(
-                    std::make_pair(name, bitcodeMetadata.getExportForEachSignatureList()[i]));
-    }
-
-    return true;
-}
-#endif
-
 bool RsdCpuScriptImpl::init(char const *resName, char const *cacheDir,
                             uint8_t const *bitcode, size_t bitcodeSize,
                             uint32_t flags, char const *bccPluginName) {
@@ -745,7 +706,6 @@
     bool useRSDebugContext = false;
 
     mCompilerDriver = nullptr;
-    mExecutable = nullptr;
 
     mCompilerDriver = new bcc::RSCompilerDriver();
     if (mCompilerDriver == nullptr) {
@@ -754,12 +714,6 @@
         return false;
     }
 
-    // Configure symbol resolvers (via compiler-rt and the RS runtime).
-    mRSRuntime.setLookupFunction(lookupRuntimeStub);
-    mRSRuntime.setContext(this);
-    mResolver.chainResolver(mCompilerRuntime);
-    mResolver.chainResolver(mRSRuntime);
-
     // Run any compiler setup functions we have been provided with.
     RSSetupCompilerCallback setupCompilerCallback =
             mCtx->getSetupCompilerCallback();
@@ -793,74 +747,42 @@
     std::string compileCommandLine =
                 bcc::getCommandLine(compileArguments.size() - 1, compileArguments.data());
 
-    if (is_skip_linkloader()) {
-        if (!is_force_recompile()) {
-            mScriptSO = loadSharedLibrary(cacheDir, resName);
-        }
-    }
-    else if (!is_force_recompile()) {
-        // Load the compiled script that's in the cache, if any.
-        mExecutable = bcc::RSCompilerDriver::loadScript(cacheDir, resName, (const char*)bitcode,
-                                                        bitcodeSize, compileCommandLine.c_str(),
-                                                        mResolver);
+    if (!is_force_recompile()) {
+        mScriptSO = loadSharedLibrary(cacheDir, resName);
     }
 
     // If we can't, it's either not there or out of date.  We compile the bit code and try loading
     // again.
-    if (is_skip_linkloader()) {
-        if (mScriptSO == nullptr) {
-            if (!compileBitcode(bcFileName, (const char*)bitcode, bitcodeSize,
-                                compileArguments.data(), compileCommandLine))
-            {
-                ALOGE("bcc: FAILS to compile '%s'", resName);
-                mCtx->unlockMutex();
-                return false;
-            }
-
-            if (!createSharedLib(cacheDir, resName)) {
-                ALOGE("Linker: Failed to link object file '%s'", resName);
-                mCtx->unlockMutex();
-                return false;
-            }
-
-            mScriptSO = loadSharedLibrary(cacheDir, resName);
-            if (mScriptSO == nullptr) {
-                ALOGE("Unable to load '%s'", resName);
-                mCtx->unlockMutex();
-                return false;
-            }
-        }
-    }
-    else if (mExecutable == nullptr) {
-        if (!compileBitcode(bcFileName, (const char*)bitcode, bitcodeSize, compileArguments.data(),
-                            compileCommandLine)) {
+    if (mScriptSO == nullptr) {
+        if (!compileBitcode(bcFileName, (const char*)bitcode, bitcodeSize,
+                            compileArguments.data(), compileCommandLine))
+        {
             ALOGE("bcc: FAILS to compile '%s'", resName);
             mCtx->unlockMutex();
             return false;
         }
-        mExecutable = bcc::RSCompilerDriver::loadScript(cacheDir, resName, (const char*)bitcode,
-                                                        bitcodeSize, compileCommandLine.c_str(),
-                                                        mResolver);
-        if (mExecutable == nullptr) {
-            ALOGE("bcc: FAILS to load freshly compiled executable for '%s'", resName);
+
+        if (!createSharedLib(cacheDir, resName)) {
+            ALOGE("Linker: Failed to link object file '%s'", resName);
+            mCtx->unlockMutex();
+            return false;
+        }
+
+        mScriptSO = loadSharedLibrary(cacheDir, resName);
+        if (mScriptSO == nullptr) {
+            ALOGE("Unable to load '%s'", resName);
             mCtx->unlockMutex();
             return false;
         }
     }
 
-    // if using the shared object path, read RS symbol information
-    // from the .so.  Otherwise, read from the object files
-    if (!is_skip_linkloader()) {
-        storeRSInfoFromObj(bitcodeMetadata);
+    // Read RS symbol information from the .so.
+    if ( !mScriptSO) {
+        goto error;
     }
-    else {
-        if ( !mScriptSO) {
-            goto error;
-        }
 
-        if ( !storeRSInfoFromSO()) {
-          goto error;
-        }
+    if ( !storeRSInfoFromSO()) {
+      goto error;
     }
 #else  // RS_COMPATIBILITY_LIB is defined
 
@@ -926,40 +848,6 @@
 #endif
 
 void RsdCpuScriptImpl::populateScript(Script *script) {
-#ifndef RS_COMPATIBILITY_LIB
-    // Copy info over to runtime
-    if (!is_skip_linkloader()) {
-        script->mHal.info.exportedFunctionCount = mExecutable->getExportFuncAddrs().size();
-        script->mHal.info.exportedVariableCount = mExecutable->getExportVarAddrs().size();
-        script->mHal.info.exportedForeachFuncList = &mExportedForEachFuncList[0];
-        script->mHal.info.exportedPragmaCount = mExecutable->getPragmaKeys().size();
-        script->mHal.info.exportedPragmaKeyList =
-            const_cast<const char**>(&mExecutable->getPragmaKeys().front());
-        script->mHal.info.exportedPragmaValueList =
-            const_cast<const char**>(&mExecutable->getPragmaValues().front());
-
-        if (mRootExpand) {
-            script->mHal.info.root = mRootExpand;
-        } else {
-            script->mHal.info.root = mRoot;
-        }
-    }
-    else {
-        // Copy info over to runtime
-        script->mHal.info.exportedFunctionCount = mExportedFunctionCount;
-        script->mHal.info.exportedVariableCount = mExportedVariableCount;
-        script->mHal.info.exportedPragmaCount = 0;
-        script->mHal.info.exportedPragmaKeyList = 0;
-        script->mHal.info.exportedPragmaValueList = 0;
-
-        // Bug, need to stash in metadata
-        if (mRootExpand) {
-            script->mHal.info.root = mRootExpand;
-        } else {
-            script->mHal.info.root = mRoot;
-        }
-    }
-#else
     // Copy info over to runtime
     script->mHal.info.exportedFunctionCount = mExportedFunctionCount;
     script->mHal.info.exportedVariableCount = mExportedVariableCount;
@@ -973,7 +861,6 @@
     } else {
         script->mHal.info.root = mRoot;
     }
-#endif
 }
 
 
@@ -1136,24 +1023,9 @@
 void RsdCpuScriptImpl::forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls) {
     mtls->script = this;
     mtls->fep.slot = slot;
-#ifndef RS_COMPATIBILITY_LIB
-    if (!is_skip_linkloader()) {
-        rsAssert(slot < mExecutable->getExportForeachFuncAddrs().size());
-        mtls->kernel = reinterpret_cast<ForEachFunc_t>(
-                          mExecutable->getExportForeachFuncAddrs()[slot]);
-        rsAssert(mtls->kernel != nullptr);
-        mtls->sig = mExecutable->getInfo().getExportForeachFuncs()[slot].second;
-    }
-    else {
-        mtls->kernel = reinterpret_cast<ForEachFunc_t>(mForEachFunctions[slot]);
-        rsAssert(mtls->kernel != nullptr);
-        mtls->sig = mForEachSignatures[slot];
-    }
-#else
     mtls->kernel = reinterpret_cast<ForEachFunc_t>(mForEachFunctions[slot]);
     rsAssert(mtls->kernel != nullptr);
     mtls->sig = mForEachSignatures[slot];
-#endif
 }
 
 int RsdCpuScriptImpl::invokeRoot() {
@@ -1195,20 +1067,8 @@
 #endif
 
     RsdCpuScriptImpl * oldTLS = mCtx->setTLS(this);
-#ifndef RS_COMPATIBILITY_LIB
-    if (! is_skip_linkloader()) {
-        reinterpret_cast<void (*)(const void *, uint32_t)>(
-            mExecutable->getExportFuncAddrs()[slot])(
-                ap? (const void *) ap : params, paramLength);
-    }
-    else {
-        reinterpret_cast<void (*)(const void *, uint32_t)>(
-            mInvokeFunctions[slot])(ap? (const void *) ap: params, paramLength);
-    }
-#else
     reinterpret_cast<void (*)(const void *, uint32_t)>(
         mInvokeFunctions[slot])(ap? (const void *) ap: params, paramLength);
-#endif
 
     mCtx->setTLS(oldTLS);
 }
@@ -1222,18 +1082,7 @@
         //return;
     //}
 
-#ifndef RS_COMPATIBILITY_LIB
-    int32_t *destPtr = nullptr;
-    if (!is_skip_linkloader()) {
-        destPtr = reinterpret_cast<int32_t *>(
-                               mExecutable->getExportVarAddrs()[slot]);
-    }
-    else {
-        destPtr = reinterpret_cast<int32_t *>(mFieldAddress[slot]);
-    }
-#else
     int32_t *destPtr = reinterpret_cast<int32_t *>(mFieldAddress[slot]);
-#endif
     if (!destPtr) {
         //ALOGV("Calling setVar on slot = %i which is null", slot);
         return;
@@ -1246,18 +1095,7 @@
     //rsAssert(!script->mFieldIsObject[slot]);
     //ALOGE("getGlobalVar %i %p %zu", slot, data, dataLength);
 
-#ifndef RS_COMPATIBILITY_LIB
-    int32_t *srcPtr = nullptr;
-    if (!is_skip_linkloader()) {
-        srcPtr = reinterpret_cast<int32_t *>(
-                              mExecutable->getExportVarAddrs()[slot]);
-    }
-    else {
-        srcPtr = reinterpret_cast<int32_t *>(mFieldAddress[slot]);
-    }
-#else
     int32_t *srcPtr = reinterpret_cast<int32_t *>(mFieldAddress[slot]);
-#endif
     if (!srcPtr) {
         //ALOGV("Calling setVar on slot = %i which is null", slot);
         return;
@@ -1269,19 +1107,7 @@
 void RsdCpuScriptImpl::setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
                                                 const Element *elem,
                                                 const uint32_t *dims, size_t dimLength) {
-
-#ifndef RS_COMPATIBILITY_LIB
-    int32_t *destPtr = nullptr;
-    if (!is_skip_linkloader()) {
-        destPtr = reinterpret_cast<int32_t *>(
-                               mExecutable->getExportVarAddrs()[slot]);
-    }
-    else {
-        destPtr = reinterpret_cast<int32_t *>(mFieldAddress[slot]);
-    }
-#else
     int32_t *destPtr = reinterpret_cast<int32_t *>(mFieldAddress[slot]);
-#endif
     if (!destPtr) {
         //ALOGV("Calling setVar on slot = %i which is null", slot);
         return;
@@ -1318,18 +1144,7 @@
     //rsAssert(!script->mFieldIsObject[slot]);
     //ALOGE("setGlobalBind %i %p", slot, data);
 
-#ifndef RS_COMPATIBILITY_LIB
-    int32_t *destPtr = nullptr;
-    if (!is_skip_linkloader()) {
-        destPtr = reinterpret_cast<int32_t *>(
-                               mExecutable->getExportVarAddrs()[slot]);
-    }
-    else {
-        destPtr = reinterpret_cast<int32_t *>(mFieldAddress[slot]);
-    }
-#else
     int32_t *destPtr = reinterpret_cast<int32_t *>(mFieldAddress[slot]);
-#endif
     if (!destPtr) {
         //ALOGV("Calling setVar on slot = %i which is null", slot);
         return;
@@ -1348,19 +1163,7 @@
     //rsAssert(script->mFieldIsObject[slot]);
     //ALOGE("setGlobalObj %i %p", slot, data);
 
-#ifndef RS_COMPATIBILITY_LIB
-    int32_t *destPtr = nullptr;
-    if (!is_skip_linkloader()) {
-        destPtr = reinterpret_cast<int32_t *>(
-                               mExecutable->getExportVarAddrs()[slot]);
-    }
-    else {
-        destPtr = reinterpret_cast<int32_t *>(mFieldAddress[slot]);
-    }
-#else
     int32_t *destPtr = reinterpret_cast<int32_t *>(mFieldAddress[slot]);
-#endif
-
     if (!destPtr) {
         //ALOGV("Calling setVar on slot = %i which is null", slot);
         return;
@@ -1371,46 +1174,12 @@
 
 RsdCpuScriptImpl::~RsdCpuScriptImpl() {
 #ifndef RS_COMPATIBILITY_LIB
-    if (mExecutable) {
-        std::vector<void *>::const_iterator var_addr_iter =
-            mExecutable->getExportVarAddrs().begin();
-        std::vector<void *>::const_iterator var_addr_end =
-            mExecutable->getExportVarAddrs().end();
-
-        bcc::RSInfo::ObjectSlotListTy::const_iterator is_object_iter =
-            mExecutable->getInfo().getObjectSlots().begin();
-        bcc::RSInfo::ObjectSlotListTy::const_iterator is_object_end =
-            mExecutable->getInfo().getObjectSlots().end();
-
-        while ((var_addr_iter != var_addr_end) &&
-               (is_object_iter != is_object_end)) {
-            // The field address can be nullptr if the script-side has optimized
-            // the corresponding global variable away.
-            rs_object_base *obj_addr =
-                reinterpret_cast<rs_object_base *>(*var_addr_iter);
-            if (*is_object_iter) {
-                if (*var_addr_iter != nullptr && mCtx->getContext() != nullptr) {
-                    rsrClearObject(mCtx->getContext(), obj_addr);
-                }
-            }
-            var_addr_iter++;
-            is_object_iter++;
-        }
-    }
 
     if (mCompilerDriver) {
         delete mCompilerDriver;
     }
-    if (mExecutable) {
-        delete mExecutable;
-    }
-    if (mBoundAllocs) {
-        delete[] mBoundAllocs;
-    }
 
-    for (size_t i = 0; i < mExportedForEachFuncList.size(); i++) {
-        delete[] mExportedForEachFuncList[i].first;
-    }
+#endif
 
     if (mFieldIsObject) {
         for (size_t i = 0; i < mExportedVariableCount; ++i) {
@@ -1424,27 +1193,6 @@
         }
     }
 
-    if (is_skip_linkloader()) {
-        if (mInvokeFunctions) delete[] mInvokeFunctions;
-        if (mForEachFunctions) delete[] mForEachFunctions;
-        if (mFieldAddress) delete[] mFieldAddress;
-        if (mFieldIsObject) delete[] mFieldIsObject;
-        if (mForEachSignatures) delete[] mForEachSignatures;
-    }
-
-#else
-    if (mFieldIsObject) {
-        for (size_t i = 0; i < mExportedVariableCount; ++i) {
-            if (mFieldIsObject[i]) {
-                if (mFieldAddress[i] != nullptr) {
-                    rs_object_base *obj_addr =
-                        reinterpret_cast<rs_object_base *>(mFieldAddress[i]);
-                    rsrClearObject(mCtx->getContext(), obj_addr);
-                }
-            }
-        }
-    }
-
     if (mInvokeFunctions) delete[] mInvokeFunctions;
     if (mForEachFunctions) delete[] mForEachFunctions;
     if (mFieldAddress) delete[] mFieldAddress;
@@ -1454,7 +1202,6 @@
     if (mScriptSO) {
         dlclose(mScriptSO);
     }
-#endif
 }
 
 Allocation * RsdCpuScriptImpl::getAllocationForPointer(const void *ptr) const {
diff --git a/cpu_ref/rsCpuScript.h b/cpu_ref/rsCpuScript.h
index 324ee14..7f7750f 100644
--- a/cpu_ref/rsCpuScript.h
+++ b/cpu_ref/rsCpuScript.h
@@ -21,8 +21,6 @@
 #include <rsRuntime.h>
 
 #ifndef RS_COMPATIBILITY_LIB
-#include <bcc/ExecutionEngine/CompilerRTSymbolResolver.h>
-#include <bcc/ExecutionEngine/SymbolResolverProxy.h>
 #include <vector>
 #include <utility>
 #endif
@@ -32,7 +30,6 @@
 namespace bcc {
     class BCCContext;
     class RSCompilerDriver;
-    class RSExecutable;
 }
 
 namespace bcinfo {
@@ -110,11 +107,6 @@
     virtual Allocation * getAllocationForPointer(const void *ptr) const;
     bool storeRSInfoFromSO();
 
-#ifndef RS_COMPATIBILITY_LIB
-    bool storeRSInfoFromObj(bcinfo::MetadataExtractor &bitcodeMetadata);
-    virtual  void * getRSExecutable() { return mExecutable; }
-#endif
-
 protected:
     RsdCpuReferenceImpl *mCtx;
     const Script *mScript;
@@ -124,27 +116,10 @@
     // Returns the path to the core library we'll use.
     const char* findCoreLib(const bcinfo::MetadataExtractor& bitCodeMetaData, const char* bitcode,
                             size_t bitcodeSize);
-    RootFunc_t mRoot;
-    RootFunc_t mRootExpand;
-    InvokeFunc_t mInit;
-    InvokeFunc_t mFreeChildren;
-
-    InvokeFunc_t *mInvokeFunctions;
-    ForEachFunc_t *mForEachFunctions;
-    void **mFieldAddress;
-    bool *mFieldIsObject;
-    uint32_t *mForEachSignatures;
-    size_t mExportedVariableCount;
-    size_t mExportedFunctionCount;
-
-    std::vector<std::pair<const char *, uint32_t> > mExportedForEachFuncList;
 
     bcc::RSCompilerDriver *mCompilerDriver;
-    bcc::CompilerRTSymbolResolver mCompilerRuntime;
-    bcc::LookupFunctionSymbolResolver<void *> mRSRuntime;
-    bcc::SymbolResolverProxy mResolver;
-    bcc::RSExecutable *mExecutable;
-#else
+#endif
+
     RootFunc_t mRoot;
     RootFunc_t mRootExpand;
     InvokeFunc_t mInit;
@@ -156,12 +131,8 @@
     bool *mFieldIsObject;
     uint32_t *mForEachSignatures;
 
-    // for populate script
-    //int mVersionMajor;
-    //int mVersionMinor;
     size_t mExportedVariableCount;
     size_t mExportedFunctionCount;
-#endif
 
     Allocation **mBoundAllocs;
     void * mIntrinsicData;
diff --git a/cpu_ref/rsd_cpu.h b/cpu_ref/rsd_cpu.h
index d00425c..c53e880 100644
--- a/cpu_ref/rsd_cpu.h
+++ b/cpu_ref/rsd_cpu.h
@@ -88,10 +88,6 @@
 
         virtual Allocation * getAllocationForPointer(const void *ptr) const = 0;
         virtual ~CpuScript() {}
-
-#ifndef RS_COMPATIBILITY_LIB
-        virtual  void * getRSExecutable()  = 0;
-#endif
     };
     typedef CpuScript * (* script_lookup_t)(Context *, const Script *s);
 
diff --git a/driver/rsdCore.cpp b/driver/rsdCore.cpp
index 9f1640b..0181282 100644
--- a/driver/rsdCore.cpp
+++ b/driver/rsdCore.cpp
@@ -22,7 +22,6 @@
 #include "rsdElement.h"
 #include "rsdType.h"
 #ifndef RS_COMPATIBILITY_LIB
-    #include "MemChunk.h"
     #include "rsdGL.h"
     #include "rsdPath.h"
     #include "rsdProgramStore.h"
@@ -260,16 +259,6 @@
     if (false) {
         dc->mCpuRef->setSetupCompilerCallback(nullptr);
     }
-
-    // Set a callback for switching MemChunk's allocator here.
-    // Note that the allocation function must return page-aligned memory, so
-    // that it can be mprotected properly (i.e. code should be written and
-    // later switched to read+execute only).
-    if (false) {
-        MemChunk::registerAllocFreeCallbacks(
-                rsc->mHal.funcs.allocRuntimeMem,
-                rsc->mHal.funcs.freeRuntimeMem);
-    }
 #endif
 
     return true;