summaryrefslogtreecommitdiffstats
path: root/tools/llvm-lto/llvm-lto.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/llvm-lto/llvm-lto.cpp')
-rw-r--r--tools/llvm-lto/llvm-lto.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/tools/llvm-lto/llvm-lto.cpp b/tools/llvm-lto/llvm-lto.cpp
index ec3f0fa..8c2d1cd 100644
--- a/tools/llvm-lto/llvm-lto.cpp
+++ b/tools/llvm-lto/llvm-lto.cpp
@@ -17,6 +17,7 @@
#include "llvm/LTO/LTOCodeGenerator.h"
#include "llvm/LTO/LTOModule.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
@@ -83,7 +84,20 @@ int main(int argc, char **argv) {
LTOCodeGenerator CodeGen;
- CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC);
+ switch (RelocModel) {
+ case Reloc::Static:
+ CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_STATIC);
+ break;
+ case Reloc::PIC_:
+ CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC);
+ break;
+ case Reloc::DynamicNoPIC:
+ CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC);
+ break;
+ default:
+ CodeGen.setCodePICModel(LTO_CODEGEN_PIC_MODEL_DEFAULT);
+ }
+
CodeGen.setDebugInfo(LTO_DEBUG_MODEL_DWARF);
CodeGen.setTargetOptions(Options);
@@ -130,12 +144,22 @@ int main(int argc, char **argv) {
for (unsigned i = 0; i < KeptDSOSyms.size(); ++i)
CodeGen.addMustPreserveSymbol(KeptDSOSyms[i].c_str());
+ std::string attrs;
+ for (unsigned i = 0; i < MAttrs.size(); ++i) {
+ if (i > 0)
+ attrs.append(",");
+ attrs.append(MAttrs[i]);
+ }
+
+ if (!attrs.empty())
+ CodeGen.setAttr(attrs.c_str());
+
if (!OutputFilename.empty()) {
size_t len = 0;
std::string ErrorInfo;
const void *Code = CodeGen.compile(&len, DisableOpt, DisableInline,
DisableGVNLoadPRE, ErrorInfo);
- if (Code == NULL) {
+ if (!Code) {
errs() << argv[0]
<< ": error compiling the code: " << ErrorInfo << "\n";
return 1;
@@ -152,7 +176,7 @@ int main(int argc, char **argv) {
FileStream.write(reinterpret_cast<const char *>(Code), len);
} else {
std::string ErrorInfo;
- const char *OutputName = NULL;
+ const char *OutputName = nullptr;
if (!CodeGen.compile_to_file(&OutputName, DisableOpt, DisableInline,
DisableGVNLoadPRE, ErrorInfo)) {
errs() << argv[0]