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