xref: /freebsd/contrib/llvm-project/llvm/include/llvm/Linker/Linker.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===- Linker.h - Module Linker Interface -----------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_LINKER_LINKER_H
10 #define LLVM_LINKER_LINKER_H
11 
12 #include "llvm/ADT/StringSet.h"
13 #include "llvm/Linker/IRMover.h"
14 #include "llvm/Support/Compiler.h"
15 
16 namespace llvm {
17 class Module;
18 
19 /// This class provides the core functionality of linking in LLVM. It keeps a
20 /// pointer to the merged module so far. It doesn't take ownership of the
21 /// module since it is assumed that the user of this class will want to do
22 /// something with it after the linking.
23 class Linker {
24   IRMover Mover;
25 
26 public:
27   enum Flags {
28     None = 0,
29     /// Have symbols from Src shadow those in the Dest.
30     OverrideFromSrc = (1 << 0),
31     LinkOnlyNeeded = (1 << 1),
32   };
33 
34   LLVM_ABI Linker(Module &M);
35 
36   /// Link \p Src into the composite.
37   ///
38   /// Passing InternalizeCallback will have the linker call the function with
39   /// the new module and a list of global value names to be internalized by the
40   /// callback.
41   ///
42   /// Returns true on error.
43   LLVM_ABI bool linkInModule(std::unique_ptr<Module> Src,
44                              unsigned Flags = Flags::None,
45                              std::function<void(Module &, const StringSet<> &)>
46                                  InternalizeCallback = {});
47 
48   LLVM_ABI static bool linkModules(
49       Module &Dest, std::unique_ptr<Module> Src, unsigned Flags = Flags::None,
50       std::function<void(Module &, const StringSet<> &)> InternalizeCallback =
51           {});
52 };
53 
54 } // End llvm namespace
55 
56 #endif
57