Change the API of bccPrepareRelocatable().
Remove the caching from this function. It makes the API simpler
and intuitive. OBJPATH in the prototype is the path of the output
relocatable object file.
Change-Id: I03c423661a5ad306e8a18e30c838770a00a37f55
diff --git a/lib/ExecutionEngine/Script.cpp b/lib/ExecutionEngine/Script.cpp
index 4d882e1..74f1f01 100644
--- a/lib/ExecutionEngine/Script.cpp
+++ b/lib/ExecutionEngine/Script.cpp
@@ -180,17 +180,9 @@
return 0;
}
-int Script::prepareRelocatable(char const *cacheDir,
- char const *cacheName,
+int Script::prepareRelocatable(char const *objPath,
llvm::Reloc::Model RelocModel,
unsigned long flags) {
-#if USE_CACHE
- if (internalLoadCache(cacheDir, cacheName,
- ScriptObject::Relocatable, /* checkOnly */ true) == 0) {
- return 0;
- }
-#endif
-
CompilerOption option;
option.RelocModelOpt = RelocModel;
option.LoadAfterCompile = false;
@@ -199,11 +191,22 @@
ALOGE("LLVM error message: %s\n", getCompilerErrorMessage());
return status;
}
- status = writeCache();
- if (status != 0) {
- ALOGE("Failed to write the cache for %s\n", cacheName);
+
+ FileHandle objFile;
+ if (objFile.open(objPath, OpenMode::Write) < 0) {
+ ALOGE("Failed to open %s for write.\n", objPath);
+ return 1;
}
- return status;
+
+ if (static_cast<size_t>(objFile.write(getELF(),
+ getELFSize())) != getELFSize()) {
+ objFile.close();
+ ::unlink(objPath);
+ ALOGE("Unable to write ELF to file %s.\n", objPath);
+ return false;
+ }
+
+ return 0;
}
diff --git a/lib/ExecutionEngine/Script.h b/lib/ExecutionEngine/Script.h
index 73a2ce1..070b717 100644
--- a/lib/ExecutionEngine/Script.h
+++ b/lib/ExecutionEngine/Script.h
@@ -188,8 +188,7 @@
char const *dsoPath,
unsigned long flags);
- int prepareRelocatable(char const *cacheDir,
- char const *cacheName,
+ int prepareRelocatable(char const *objPath,
llvm::Reloc::Model RelocModel,
unsigned long flags);
diff --git a/lib/ExecutionEngine/bcc.cpp b/lib/ExecutionEngine/bcc.cpp
index 6a20105..057be50 100644
--- a/lib/ExecutionEngine/bcc.cpp
+++ b/lib/ExecutionEngine/bcc.cpp
@@ -126,8 +126,7 @@
extern "C" int bccPrepareRelocatable(BCCScriptRef script,
- char const *cacheDir,
- char const *cacheName,
+ char const *objPath,
bccRelocModelEnum RelocModel,
unsigned long flags) {
BCC_FUNC_LOGGER();
@@ -156,7 +155,7 @@
}
}
- return unwrap(script)->prepareRelocatable(cacheDir, cacheName, RM, flags);
+ return unwrap(script)->prepareRelocatable(objPath, RM, flags);
}