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