llvm.org GIT mirror llvm / 88fae0e
Fix LTO handling of module-level assembly (PR14152). Patch by Tom Roeder! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191042 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 7 years ago
12 changed file(s) with 167 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
2727 llvm-extract
2828 llvm-dwarfdump
2929 llvm-link
30 llvm-lto
3031 llvm-mc
3132 llvm-mcmarkup
3233 llvm-nm
115115 ENABLE_ASSERTIONS=1
116116 endif
117117
118 # Derive whether or not LTO is enabled by checking the extra options.
119 LTO_IS_ENABLED := 0
120 ifneq ($(findstring -flto,$(CompileCommonOpts)),)
121 LTO_IS_ENABLED := 1
122 else
123 ifneq ($(findstring -O4,$(CompileCommonOpts)),)
124 LTO_IS_ENABLED := 1
125 endif
126 endif
127
128118 lit.site.cfg: FORCE
129119 @echo "Making LLVM 'lit.site.cfg' file..."
130120 @$(ECHOPATH) s=@LLVM_HOST_TRIPLE@=$(HOST_TRIPLE)=g > lit.tmp
138128 @$(ECHOPATH) s=@OCAMLOPT@=$(OCAMLOPT) -cc $(subst *,'\\\"',*$(subst =,"\\=",$(CXX_FOR_OCAMLOPT))*) -I $(LibDir)/ocaml=g >> lit.tmp
139129 @$(ECHOPATH) s=@ENABLE_SHARED@=$(ENABLE_SHARED)=g >> lit.tmp
140130 @$(ECHOPATH) s=@ENABLE_ASSERTIONS@=$(ENABLE_ASSERTIONS)=g >> lit.tmp
141 @$(ECHOPATH) s=@LTO_IS_ENABLED@=$(LTO_IS_ENABLED)=g >> lit.tmp
142131 @$(ECHOPATH) s=@TARGETS_TO_BUILD@=$(TARGETS_TO_BUILD)=g >> lit.tmp
143132 @$(ECHOPATH) s=@LLVM_BINDINGS@=$(BINDINGS_TO_BUILD)=g >> lit.tmp
144133 @$(ECHOPATH) s=@HOST_OS@=$(HOST_OS)=g >> lit.tmp
220220 r"\bllvm-size\b",
221221 # Match llvmc but not -llvmc
222222 NOHYPHEN + r"\bllvmc\b",
223 r"\blto\b",
223 r"\bllvm-lto\b",
224 # Match lto but not -lto
225 NOHYPHEN + r"\blto\b",
224226 # Don't match '.opt', '-opt',
225227 # '^opt' or '/opt'.
226228 r"\bmacho-dump\b", r"(?
1313 config.ocamlopt_executable = "@OCAMLOPT@"
1414 config.enable_shared = @ENABLE_SHARED@
1515 config.enable_assertions = @ENABLE_ASSERTIONS@
16 config.lto_is_enabled = "@LTO_IS_ENABLED@"
1716 config.targets_to_build = "@TARGETS_TO_BUILD@"
1817 config.llvm_bindings = "@LLVM_BINDINGS@"
1918 config.host_os = "@HOST_OS@"
0 ; RUN: llvm-as < %s >%t1
1 ; RUN: llvm-lto -o %t2 %t1
2
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
4 target triple = "x86_64-unknown-linux-gnu"
5
6 module asm ".text"
7 module asm ".align 16, 0x90"
8 module asm ".type PR14512, @function"
9 module asm "PR14512:.cfi_startproc"
10 module asm "ret"
11 module asm ".cfi_endproc"
12
13 declare void @PR14512()
14
15 define i32 @main(i32 %argc, i8** %argv) {
16 call void @PR14512()
17 ret i32 0
18 }
19 ; XFAIL: win32
0 targets = set(config.root.targets_to_build.split())
1 if not 'X86' in targets:
2 config.unsupported = True
4444
4545 if( NOT WIN32 )
4646 add_llvm_tool_subdirectory(lto)
47 add_llvm_tool_subdirectory(llvm-lto)
4748 else()
4849 ignore_llvm_tool_subdirectory(lto)
50 ignore_llvm_tool_subdirectory(llvm-lto)
4951 endif()
5052
5153 if( LLVM_ENABLE_PIC )
5353 ifndef ONLY_TOOLS
5454 ifeq ($(ENABLE_PIC),1)
5555 # gold only builds if binutils is around. It requires "lto" to build before
56 # it so it is added to DIRS.
56 # it so it is added to DIRS. llvm-lto also requires lto
57 DIRS += lto llvm-lto
5758 ifdef BINUTILS_INCDIR
58 DIRS += lto gold
59 else
60 PARALLEL_DIRS += lto
59 DIRS += gold
6160 endif
6261
6362 PARALLEL_DIRS += bugpoint-passes
0 add_llvm_tool(llvm-lto
1 llvm-lto.cpp
2 )
3
4 target_link_libraries(llvm-lto LTO LLVMSupport)
5
6 add_dependencies(llvm-lto lto)
0 ##===- tools/llvm-lto/Makefile -----------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL := ../..
10 TOOLNAME := llvm-lto
11 LINK_COMPONENTS := support
12
13 # This tool has no plugins, optimize startup time.
14 TOOL_NO_EXPORTS := 1
15
16 NO_INSTALL := 1
17
18 include $(LEVEL)/Makefile.common
19
20 LDFLAGS += -L$(LibDir)
21 LIBS += -lLTO
0 //===-- llvm-lto: a simple command-line program to link modules with LTO --===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This program takes in a list of bitcode files, links them, performs link-time
10 // optimization, and outputs an object file.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm-c/lto.h"
15 #include "llvm/Support/CommandLine.h"
16 #include "llvm/Support/ManagedStatic.h"
17 #include "llvm/Support/PrettyStackTrace.h"
18 #include "llvm/Support/Signals.h"
19 #include "llvm/Support/raw_ostream.h"
20
21 using namespace llvm;
22
23 static cl::list InputFilenames(cl::Positional, cl::OneOrMore,
24 cl::desc(""));
25
26 static cl::opt OutputFilename("o",
27 cl::desc("Override output filename"),
28 cl::init(""),
29 cl::value_desc("filename"));
30
31 int main(int argc, char **argv) {
32 // Print a stack trace if we signal out.
33 sys::PrintStackTraceOnErrorSignal();
34 PrettyStackTraceProgram X(argc, argv);
35
36 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
37 cl::ParseCommandLineOptions(argc, argv, "llvm LTO linker\n");
38
39 unsigned BaseArg = 0;
40 std::string ErrorMessage;
41
42 lto_code_gen_t code_gen = lto_codegen_create();
43 if (code_gen == NULL)
44 errs() << argv[0] << ": error creating a code generation module: "
45 << lto_get_error_message() << "\n";
46
47 lto_codegen_set_pic_model(code_gen, LTO_CODEGEN_PIC_MODEL_DYNAMIC);
48 lto_codegen_set_debug_model(code_gen, LTO_DEBUG_MODEL_DWARF);
49
50 for (unsigned i = BaseArg; i < InputFilenames.size(); ++i) {
51 lto_module_t BitcodeModule = lto_module_create(InputFilenames[i].c_str());
52 if (BitcodeModule == NULL) {
53 errs() << argv[0] << ": error loading file '" << InputFilenames[i]
54 << "': " << lto_get_error_message() << "\n";
55 return 1;
56 }
57
58 if (lto_codegen_add_module(code_gen, BitcodeModule)) {
59 errs() << argv[0] << ": error adding file '" << InputFilenames[i]
60 << "': " << lto_get_error_message() << "\n";
61 lto_module_dispose(BitcodeModule);
62 return 1;
63 }
64
65 lto_module_dispose(BitcodeModule);
66 }
67
68 if (!OutputFilename.empty()) {
69 size_t len = 0;
70 const void *Code = lto_codegen_compile(code_gen, &len);
71 if (Code == NULL) {
72 errs() << argv[0]
73 << ": error compiling the code: " << lto_get_error_message()
74 << "\n";
75 return 1;
76 }
77
78 std::string ErrorInfo;
79 raw_fd_ostream FileStream(OutputFilename.c_str(), ErrorInfo);
80 if (!ErrorInfo.empty()) {
81 errs() << argv[0] << ": error opening the file '" << OutputFilename
82 << "': " << ErrorInfo << "\n";
83 return 1;
84 }
85
86 FileStream.write(reinterpret_cast(Code), len);
87 } else {
88 const char *OutputName = NULL;
89 if (lto_codegen_compile_to_file(code_gen, &OutputName)) {
90 errs() << argv[0]
91 << ": error compiling the code: " << lto_get_error_message()
92 << "\n";
93 return 1;
94 }
95
96 outs() << "Wrote native object file '" << OutputName << "'\n";
97 }
98
99 lto_codegen_dispose(code_gen);
100
101 return 0;
102 }
791791 const MCSymbol *Label,
792792 unsigned PointerSize) {}
793793 virtual void FinishImpl() {}
794 virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
795 RecordProcEnd(Frame);
796 }
794797
795798 static bool classof(const MCStreamer *S) {
796799 return S->getKind() == SK_RecordStreamer;