Merge "Turn on NEON support for Nexus S"
diff --git a/lib/ExecutionEngine/MCCacheReader.cpp b/lib/ExecutionEngine/MCCacheReader.cpp
index aac7be7..2034317 100644
--- a/lib/ExecutionEngine/MCCacheReader.cpp
+++ b/lib/ExecutionEngine/MCCacheReader.cpp
@@ -48,7 +48,6 @@
   if (mpHeader) { free(mpHeader); }
   if (mpCachedDependTable) { free(mpCachedDependTable); }
   if (mpPragmaList) { free(mpPragmaList); }
-  if (mpFuncTable) { free(mpFuncTable); }
 }
 
 ScriptCached *MCCacheReader::readCacheFile(FileHandle *objFile,
@@ -82,7 +81,6 @@
              && readExportVarList()
              && readExportFuncList()
              && readPragmaList()
-             && readFuncTable()
              && readObjectSlotList()
              && readObjFile()
              && relocate()
@@ -410,20 +408,6 @@
   return true;
 }
 
-bool MCCacheReader::readFuncTable() {
-  CACHE_READER_READ_SECTION(OBCC_FuncTable, mpFuncTable, func_table);
-
-  vector<char const *> &strPool = mpResult->mStringPool;
-  ScriptCached::FuncTable &table = mpResult->mFunctions;
-  for (size_t i = 0; i < func_table_raw->count; ++i) {
-    OBCC_FuncInfo *func = &func_table_raw->table[i];
-    table.insert(make_pair(strPool[func->name_strp_index],
-                           make_pair(func->cached_addr, func->size)));
-  }
-
-  return true;
-}
-
 #undef CACHE_READER_READ_SECTION
 
 bool MCCacheReader::readRelocationTable() {
@@ -437,6 +421,9 @@
   int mRootOffset = reinterpret_cast<char *>(rootPtr) -
                     reinterpret_cast<char *>(mpHeader->root_base_addr);
   for (size_t i = 0; i < mpResult->getExportVarCount(); ++i) {
+    // Variable is optimized out by libbcc. Don't relocate.
+    if (mpResult->mpExportVars->cached_addr_list[i] == 0x00) continue;
+
     mpResult->mpExportVars->cached_addr_list[i] =
     reinterpret_cast<void *>(
         reinterpret_cast<char *>(mpResult->mpExportVars->cached_addr_list[i])
diff --git a/lib/ExecutionEngine/MCCacheReader.h b/lib/ExecutionEngine/MCCacheReader.h
index d1f230e..e826b36 100644
--- a/lib/ExecutionEngine/MCCacheReader.h
+++ b/lib/ExecutionEngine/MCCacheReader.h
@@ -57,7 +57,7 @@
   public:
     MCCacheReader()
       : mObjFile(NULL), mInfoFile(NULL), mInfoFileSize(0), mpHeader(NULL),
-        mpCachedDependTable(NULL), mpPragmaList(NULL), mpFuncTable(NULL),
+        mpCachedDependTable(NULL), mpPragmaList(NULL),
         mIsContextSlotNotAvail(false) {
     }
 
@@ -88,7 +88,6 @@
     bool readExportVarList();
     bool readExportFuncList();
     bool readPragmaList();
-    bool readFuncTable();
     bool readObjectSlotList();
     bool readObjFile();
     bool readRelocationTable();
diff --git a/lib/ExecutionEngine/MCCacheWriter.cpp b/lib/ExecutionEngine/MCCacheWriter.cpp
index 499a82b..c2d0d04 100644
--- a/lib/ExecutionEngine/MCCacheWriter.cpp
+++ b/lib/ExecutionEngine/MCCacheWriter.cpp
@@ -44,7 +44,6 @@
   CHECK_AND_FREE(mpExportVarListSection);
   CHECK_AND_FREE(mpExportFuncListSection);
   CHECK_AND_FREE(mpPragmaListSection);
-  CHECK_AND_FREE(mpFuncTableSection);
   CHECK_AND_FREE(mpObjectSlotSection);
 
 #undef CHECK_AND_FREE
@@ -62,7 +61,6 @@
 
   bool result = prepareHeader(libRS_threadable)
              && prepareDependencyTable()
-             && prepareFuncTable()
              && preparePragmaList()
              && prepareStringPool()
              && prepareExportVarList()
@@ -142,42 +140,6 @@
   return true;
 }
 
-
-bool MCCacheWriter::prepareFuncTable() {
-  size_t funcCount = mpOwner->getFuncCount();
-
-  size_t tableSize = sizeof(OBCC_FuncTable) +
-                     sizeof(OBCC_FuncInfo) * funcCount;
-
-  OBCC_FuncTable *tab = (OBCC_FuncTable *)malloc(tableSize);
-
-  if (!tab) {
-    LOGE("Unable to allocate for function table section.\n");
-    return false;
-  }
-
-  mpFuncTableSection = tab;
-  mpHeaderSection->func_table_size = tableSize;
-
-  tab->count = static_cast<size_t>(funcCount);
-
-  // Get the function informations
-  vector<FuncInfo> funcInfoList(funcCount);
-  mpOwner->getFuncInfoList(funcCount, &*funcInfoList.begin());
-
-  for (size_t i = 0; i < funcCount; ++i) {
-    FuncInfo *info = &funcInfoList[i];
-    OBCC_FuncInfo *outputInfo = &tab->table[i];
-
-    outputInfo->name_strp_index = addString(info->name, strlen(info->name));
-    outputInfo->cached_addr = info->addr;
-    outputInfo->size = info->size;
-  }
-
-  return true;
-}
-
-
 bool MCCacheWriter::preparePragmaList() {
   size_t pragmaCount = mpOwner->getPragmaCount();
 
@@ -381,7 +343,6 @@
   WRITE_SECTION_SIMPLE(export_var_list, mpExportVarListSection);
   WRITE_SECTION_SIMPLE(export_func_list, mpExportFuncListSection);
   WRITE_SECTION_SIMPLE(pragma_list, mpPragmaListSection);
-  WRITE_SECTION_SIMPLE(func_table, mpFuncTableSection);
   WRITE_SECTION_SIMPLE(object_slot_list, mpObjectSlotSection);
 
 #undef WRITE_SECTION_SIMPLE
diff --git a/lib/ExecutionEngine/MCCacheWriter.h b/lib/ExecutionEngine/MCCacheWriter.h
index 9970dfb..962ef06 100644
--- a/lib/ExecutionEngine/MCCacheWriter.h
+++ b/lib/ExecutionEngine/MCCacheWriter.h
@@ -46,7 +46,6 @@
     OBCC_ExportVarList *mpExportVarListSection;
     OBCC_ExportFuncList *mpExportFuncListSection;
     OBCC_PragmaList *mpPragmaListSection;
-    OBCC_FuncTable *mpFuncTableSection;
     OBCC_ObjectSlotList *mpObjectSlotSection;
 
   public:
@@ -54,7 +53,7 @@
       : mpHeaderSection(NULL), mpStringPoolSection(NULL),
         mpDependencyTableSection(NULL), mpExportVarListSection(NULL),
         mpExportFuncListSection(NULL), mpPragmaListSection(NULL),
-        mpFuncTableSection(NULL), mpObjectSlotSection(NULL) {
+        mpObjectSlotSection(NULL) {
     }
 
     ~MCCacheWriter();
@@ -77,7 +76,6 @@
     bool prepareExportVarList();
     bool prepareExportFuncList();
     bool preparePragmaList();
-    bool prepareFuncTable();
     bool prepareObjectSlotList();
 
     bool writeAll();
diff --git a/lib/ExecutionEngine/Runtime.def b/lib/ExecutionEngine/Runtime.def
index d5ae62a..e15aa11 100644
--- a/lib/ExecutionEngine/Runtime.def
+++ b/lib/ExecutionEngine/Runtime.def
@@ -117,6 +117,7 @@
 #if !defined(__i386__)
     DEF_LLVM_RUNTIME(__divdi3)
 #endif
+DEF_LLVM_RUNTIME(__divsi3)
 
 #ifndef ANDROID // no complex extension
     DEF_LLVM_RUNTIME(__divsc3)
@@ -182,6 +183,7 @@
 #if !defined(__i386__)
     DEF_LLVM_RUNTIME(__moddi3)
 #endif
+DEF_LLVM_RUNTIME(__modsi3)
 
 #ifndef ANDROID // no complex extension
     DEF_LLVM_RUNTIME(__muldc3)
@@ -238,6 +240,7 @@
 #if !defined(__i386__)
     DEF_LLVM_RUNTIME(__umoddi3)
 #endif
+DEF_LLVM_RUNTIME(__umodsi3)
 
 DEF_GENERIC_OR_VFP_RUNTIME(__unorddf2)
 DEF_GENERIC_OR_VFP_RUNTIME(__unordsf2)
diff --git a/lib/ExecutionEngine/RuntimeStub.c b/lib/ExecutionEngine/RuntimeStub.c
index ee75e1b..d38f68d 100644
--- a/lib/ExecutionEngine/RuntimeStub.c
+++ b/lib/ExecutionEngine/RuntimeStub.c
@@ -23,6 +23,7 @@
 #if !defined(__i386__)
 #   include "runtime/lib/divdi3.c"
 #endif
+#include "runtime/lib/divsi3.c"
 #ifndef ANDROID // no complex.h
 #   include "runtime/lib/divsc3.c"
 #endif
@@ -40,6 +41,7 @@
 #   include "runtime/lib/floatundisf.c"
 #   include "runtime/lib/moddi3.c"
 #endif
+#include "runtime/lib/modsi3.c"
 #if !defined(__i386__) && !defined(__SSE2__)
 #   include "runtime/lib/lshrdi3.c"
 #endif
@@ -74,6 +76,7 @@
 #if !defined(__i386__)
 #   include "runtime/lib/umoddi3.c"
 #endif
+#include "runtime/lib/umodsi3.c"
 #include "runtime/lib/eprintf.c"
 
 #if defined(__arm__)
diff --git a/lib/ExecutionEngine/RuntimeStub.h b/lib/ExecutionEngine/RuntimeStub.h
index 01cb998..1ca678b 100644
--- a/lib/ExecutionEngine/RuntimeStub.h
+++ b/lib/ExecutionEngine/RuntimeStub.h
@@ -28,6 +28,7 @@
 #if !defined(__i386__)
 extern di_int __divdi3(di_int, di_int);
 #endif
+extern si_int __divsi3(si_int, si_int);
 #ifndef ANDROID /* no complex.h */
 extern float _Complex __divsc3(float, float, float, float);
 #endif
@@ -45,6 +46,7 @@
 extern float __floatundisf(du_int);
 extern di_int __moddi3(di_int, di_int);
 #endif
+extern si_int __modsi3(si_int, si_int);
 #if !defined(__i386__) && !defined(__SSE2__)
 extern di_int __lshrdi3(di_int, si_int);
 #endif
@@ -79,6 +81,7 @@
 #if !defined(__i386__)
 extern du_int __umoddi3(du_int, du_int);
 #endif
+extern su_int __umodsi3(su_int, su_int);
 extern void __eprintf(char const *, char const *, char const *, char const *)
   __attribute__((visibility("hidden")));