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