Have separate prepareSharedObject and prepareObject.

Also, provide option for prepareObject to specify relocation model.

Change-Id: Ia9f51f1a463165d069dc918654e0f55189e7a274
diff --git a/lib/ExecutionEngine/Script.cpp b/lib/ExecutionEngine/Script.cpp
index aae0692..2751299 100644
--- a/lib/ExecutionEngine/Script.cpp
+++ b/lib/ExecutionEngine/Script.cpp
@@ -180,9 +180,10 @@
   return 0;
 }
 
-int Script::prepareSharedObject(char const *cacheDir,
-                                char const *cacheName,
-                                unsigned long flags) {
+int Script::prepareObject(char const *cacheDir,
+                          char const *cacheName,
+                          llvm::Reloc::Model RelocModel,
+                          unsigned long flags) {
 #if USE_CACHE
   if (cacheDir && cacheName) {
     // Set Cache Directory and File Name
@@ -201,6 +202,7 @@
 #endif
 
   CompilerOption option;
+  option.RelocModelOpt = RelocModel;
   option.LoadAfterCompile = false;
   int status = internalCompile(option);
   if (status != 0) {
diff --git a/lib/ExecutionEngine/Script.h b/lib/ExecutionEngine/Script.h
index 83cc948..9138db5 100644
--- a/lib/ExecutionEngine/Script.h
+++ b/lib/ExecutionEngine/Script.h
@@ -22,6 +22,8 @@
 
 #include "Compiler.h"
 
+#include <llvm/Support/CodeGen.h>
+
 #include <vector>
 #include <string>
 
@@ -118,9 +120,10 @@
                           char const *cacheName,
                           unsigned long flags);
 
-    int prepareSharedObject(char const *cacheDir,
-                          char const *cacheName,
-                          unsigned long flags);
+    int prepareObject(char const *cacheDir,
+                      char const *cacheName,
+                      llvm::Reloc::Model RelocModel,
+                      unsigned long flags);
 
     char const *getCompilerErrorMessage();
 
diff --git a/lib/ExecutionEngine/bcc.cpp b/lib/ExecutionEngine/bcc.cpp
index 60cefc4..075d6c1 100644
--- a/lib/ExecutionEngine/bcc.cpp
+++ b/lib/ExecutionEngine/bcc.cpp
@@ -29,6 +29,7 @@
 #include <string>
 
 #include <utils/StopWatch.h>
+#include <llvm/Support/CodeGen.h>
 
 using namespace bcc;
 
@@ -123,11 +124,26 @@
 }
 
 
-extern "C" int bccPrepareSharedObject(BCCScriptRef script,
-                                      char const *cacheDir,
-                                      char const *cacheName,
-                                      unsigned long flags) {
-  return unwrap(script)->prepareSharedObject(cacheDir, cacheName, flags);
+extern "C" int bccPrepareObject(BCCScriptRef script,
+                                char const *cacheDir,
+                                char const *cacheName,
+                                bccRelocModelEnum RelocModel,
+                                unsigned long flags) {
+  BCC_FUNC_LOGGER();
+  llvm::Reloc::Model RM;
+
+  switch (RelocModel) {
+    case bccRelocDefault:      RM = llvm::Reloc::Default;      break;
+    case bccRelocStatic:       RM = llvm::Reloc::Static;       break;
+    case bccRelocPIC:          RM = llvm::Reloc::PIC_;         break;
+    case bccRelocDynamicNoPIC: RM = llvm::Reloc::DynamicNoPIC; break;
+    default: {
+      ALOGE("Unrecognized relocation model for bccPrepareObject!");
+      return BCC_INVALID_VALUE;
+    }
+  }
+
+  return unwrap(script)->prepareObject(cacheDir, cacheName, RM, flags);
 }
 
 
@@ -202,4 +218,3 @@
 #endif
   }
 }
-