xref: /freebsd/contrib/llvm-project/lld/COFF/MinGW.h (revision fe6060f10f634930ff71b7c50291ddc610da2475)
1 //===- MinGW.h --------------------------------------------------*- 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 LLD_COFF_MINGW_H
10 #define LLD_COFF_MINGW_H
11 
12 #include "Config.h"
13 #include "Symbols.h"
14 #include "lld/Common/LLVM.h"
15 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/ADT/StringSet.h"
17 #include "llvm/Option/ArgList.h"
18 #include <vector>
19 
20 namespace lld {
21 namespace coff {
22 
23 // Logic for deciding what symbols to export, when exporting all
24 // symbols for MinGW.
25 class AutoExporter {
26 public:
27   AutoExporter();
28 
29   void addWholeArchive(StringRef path);
30 
31   llvm::StringSet<> excludeSymbols;
32   llvm::StringSet<> excludeSymbolPrefixes;
33   llvm::StringSet<> excludeSymbolSuffixes;
34   llvm::StringSet<> excludeLibs;
35   llvm::StringSet<> excludeObjects;
36 
37   bool shouldExport(Defined *sym) const;
38 };
39 
40 void writeDefFile(StringRef name);
41 
42 // The -wrap option is a feature to rename symbols so that you can write
43 // wrappers for existing functions. If you pass `-wrap:foo`, all
44 // occurrences of symbol `foo` are resolved to `__wrap_foo` (so, you are
45 // expected to write `__wrap_foo` function as a wrapper). The original
46 // symbol becomes accessible as `__real_foo`, so you can call that from your
47 // wrapper.
48 //
49 // This data structure is instantiated for each -wrap option.
50 struct WrappedSymbol {
51   Symbol *sym;
52   Symbol *real;
53   Symbol *wrap;
54 };
55 
56 std::vector<WrappedSymbol> addWrappedSymbols(llvm::opt::InputArgList &args);
57 
58 void wrapSymbols(ArrayRef<WrappedSymbol> wrapped);
59 
60 } // namespace coff
61 } // namespace lld
62 
63 #endif
64