#include "LTOCodeGenerator.h"
-#include "llvm/Module.h"
-#include "llvm/PassManager.h"
-#include "llvm/Linker.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/Linker.h"
+#include "llvm/LLVMContext.h"
+#include "llvm/Module.h"
#include "llvm/ModuleProvider.h"
+#include "llvm/PassManager.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Analysis/Passes.h"
+#include "llvm/Analysis/LoopPass.h"
+#include "llvm/Analysis/Verifier.h"
#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/CodeGen/FileWriters.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Mangler.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Signals.h"
-#include "llvm/Analysis/Passes.h"
-#include "llvm/Analysis/LoopPass.h"
-#include "llvm/Analysis/Verifier.h"
-#include "llvm/CodeGen/FileWriters.h"
#include "llvm/Target/SubtargetFeature.h"
#include "llvm/Target/TargetOptions.h"
+#include "llvm/Target/TargetAsmInfo.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetMachineRegistry.h"
-#include "llvm/Target/TargetAsmInfo.h"
+#include "llvm/Target/TargetSelect.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Scalar.h"
-#include "llvm/ADT/StringExtras.h"
#include "llvm/Config/config.h"
+#include <cstdlib>
#include <fstream>
#include <unistd.h>
-#include <stdlib.h>
#include <fcntl.h>
LTOCodeGenerator::LTOCodeGenerator()
- : _linker("LinkTimeOptimizer", "ld-temp.o"), _target(NULL),
+ : _context(getGlobalContext()),
+ _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL),
_emitDwarfDebugInfo(false), _scopeRestrictionsDone(false),
_codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
_nativeObjectFile(NULL), _gccPath(NULL), _assemblerPath(NULL)
{
+ InitializeAllTargets();
+ InitializeAllAsmPrinters();
}
bool LTOCodeGenerator::setCodePICModel(lto_codegen_model model,
- std::string& errMsg)
+ std::string& errMsg)
{
switch (model) {
case LTO_CODEGEN_PIC_MODEL_STATIC:
std::vector<const char*> args;
std::string targetTriple = _linker.getModule()->getTargetTriple();
args.push_back(tool.c_str());
- if ( targetTriple.find("darwin") != targetTriple.size() ) {
+ if ( targetTriple.find("darwin") != std::string::npos ) {
+ // darwin specific command line options
if (strncmp(targetTriple.c_str(), "i386-apple-", 11) == 0) {
args.push_back("-arch");
args.push_back("i386");
args.push_back("-arch");
args.push_back("armv6");
}
+ else if ((strncmp(targetTriple.c_str(), "armv7-apple-", 12) == 0) ||
+ (strncmp(targetTriple.c_str(), "thumbv7-apple-", 14) == 0)) {
+ args.push_back("-arch");
+ args.push_back("armv7");
+ }
+ // add -static to assembler command line when code model requires
+ if ( (_assemblerPath != NULL) && (_codeModel == LTO_CODEGEN_PIC_MODEL_STATIC) )
+ args.push_back("-static");
}
if ( needsCompilerOptions ) {
args.push_back("-c");