#include <stdbool.h>
#include <stddef.h>
+#define LTO_API_VERSION 3
+
typedef enum {
LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of alignment */
LTO_SYMBOL_PERMISSIONS_MASK = 0x000000E0,
lto_codegen_set_gcc_path(lto_code_gen_t cg, const char* path);
+/**
+ * Sets the location of the assembler tool to run. If not set, libLTO
+ * will use gcc to invoke the assembler.
+ */
+extern void
+lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path);
+
+
/**
* Adds to a list of all global symbols that must exist in the final
* generated code. If a function is not listed, it might be
: _linker("LinkTimeOptimizer", "ld-temp.o"), _target(NULL),
_emitDwarfDebugInfo(false), _scopeRestrictionsDone(false),
_codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
- _nativeObjectFile(NULL), _gccPath(NULL)
+ _nativeObjectFile(NULL), _gccPath(NULL), _assemblerPath(NULL)
{
}
_gccPath = new sys::Path(path);
}
+void LTOCodeGenerator::setAssemblerPath(const char* path)
+{
+ if ( _assemblerPath )
+ delete _assemblerPath;
+ _assemblerPath = new sys::Path(path);
+}
+
void LTOCodeGenerator::addMustPreserveSymbol(const char* sym)
{
_mustPreserveSymbols[sym] = 1;
bool LTOCodeGenerator::assemble(const std::string& asmPath,
const std::string& objPath, std::string& errMsg)
{
- sys::Path gcc;
- if ( _gccPath ) {
- gcc = *_gccPath;
+ sys::Path tool;
+ bool needsCompilerOptions = true;
+ if ( _assemblerPath ) {
+ tool = *_assemblerPath;
+ needsCompilerOptions = false;
+ }
+ else if ( _gccPath ) {
+ tool = *_gccPath;
} else {
// find compiler driver
- gcc = sys::Program::FindProgramByName("gcc");
- if ( gcc.isEmpty() ) {
+ tool = sys::Program::FindProgramByName("gcc");
+ if ( tool.isEmpty() ) {
errMsg = "can't locate gcc";
return true;
}
// build argument list
std::vector<const char*> args;
std::string targetTriple = _linker.getModule()->getTargetTriple();
- args.push_back(gcc.c_str());
+ args.push_back(tool.c_str());
if ( targetTriple.find("darwin") != targetTriple.size() ) {
if (strncmp(targetTriple.c_str(), "i386-apple-", 11) == 0) {
args.push_back("-arch");
args.push_back("armv6");
}
}
- args.push_back("-c");
- args.push_back("-x");
- args.push_back("assembler");
+ if ( needsCompilerOptions ) {
+ args.push_back("-c");
+ args.push_back("-x");
+ args.push_back("assembler");
+ }
args.push_back("-o");
args.push_back(objPath.c_str());
args.push_back(asmPath.c_str());
args.push_back(0);
// invoke assembler
- if ( sys::Program::ExecuteAndWait(gcc, &args[0], 0, 0, 0, 0, &errMsg) ) {
+ if ( sys::Program::ExecuteAndWait(tool, &args[0], 0, 0, 0, 0, &errMsg) ) {
errMsg = "error in assembly";
return true;
}
bool setDebugInfo(lto_debug_model, std::string& errMsg);
bool setCodePICModel(lto_codegen_model, std::string& errMsg);
void setGccPath(const char* path);
+ void setAssemblerPath(const char* path);
void addMustPreserveSymbol(const char* sym);
bool writeMergedModules(const char* path,
std::string& errMsg);
llvm::MemoryBuffer* _nativeObjectFile;
std::vector<const char*> _codegenOptions;
llvm::sys::Path* _gccPath;
+ llvm::sys::Path* _assemblerPath;
};
#endif // LTO_CODE_GENERATOR_H