| Rui Ueyama | 0ca149f | 2013-08-06 22:31:59 +0000 | [diff] [blame] | 1 | //===- lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp -------------------===// |
| Rui Ueyama | 9e56839 | 2013-05-28 18:13:31 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Linker |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| Rui Ueyama | fd50283 | 2013-07-24 22:53:23 +0000 | [diff] [blame] | 10 | #include "Atoms.h" |
| Rui Ueyama | c91c24e3 | 2013-12-13 06:58:27 +0000 | [diff] [blame] | 11 | #include "EdataPass.h" |
| Rui Ueyama | 991f42c | 2013-06-19 17:46:57 +0000 | [diff] [blame] | 12 | #include "GroupedSectionsPass.h" |
| Rui Ueyama | c8a5379 | 2013-07-11 08:46:21 +0000 | [diff] [blame] | 13 | #include "IdataPass.h" |
| Rui Ueyama | 908606d | 2013-08-09 04:44:15 +0000 | [diff] [blame] | 14 | #include "LinkerGeneratedSymbolFile.h" |
| Rui Ueyama | 2e09d93 | 2014-02-26 08:27:59 +0000 | [diff] [blame] | 15 | #include "LoadConfigPass.h" |
| Rui Ueyama | 1a11b3b | 2013-11-25 02:00:00 +0000 | [diff] [blame] | 16 | #include "SetSubsystemPass.h" |
| Rui Ueyama | 9e56839 | 2013-05-28 18:13:31 +0000 | [diff] [blame] | 17 | |
| Rui Ueyama | d95a155 | 2013-06-17 16:59:54 +0000 | [diff] [blame] | 18 | #include "lld/Core/PassManager.h" |
| 19 | #include "lld/Passes/LayoutPass.h" |
| Rui Ueyama | c9752fa | 2013-11-01 19:52:37 +0000 | [diff] [blame] | 20 | #include "lld/Passes/RoundTripNativePass.h" |
| 21 | #include "lld/Passes/RoundTripYAMLPass.h" |
| Rui Ueyama | 0ca149f | 2013-08-06 22:31:59 +0000 | [diff] [blame] | 22 | #include "lld/ReaderWriter/PECOFFLinkingContext.h" |
| Rui Ueyama | 9e56839 | 2013-05-28 18:13:31 +0000 | [diff] [blame] | 23 | #include "lld/ReaderWriter/Reader.h" |
| Rui Ueyama | fd50283 | 2013-07-24 22:53:23 +0000 | [diff] [blame] | 24 | #include "lld/ReaderWriter/Simple.h" |
| Rui Ueyama | 9e56839 | 2013-05-28 18:13:31 +0000 | [diff] [blame] | 25 | #include "lld/ReaderWriter/Writer.h" |
| Rui Ueyama | c9752fa | 2013-11-01 19:52:37 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/SmallString.h" |
| 27 | #include "llvm/Support/Allocator.h" |
| 28 | #include "llvm/Support/Path.h" |
| Rui Ueyama | 9e56839 | 2013-05-28 18:13:31 +0000 | [diff] [blame] | 29 | |
| Rui Ueyama | 9149181 | 2013-09-23 19:52:35 +0000 | [diff] [blame] | 30 | #include <bitset> |
| Rui Ueyama | 4af032d | 2013-12-20 10:02:59 +0000 | [diff] [blame] | 31 | #include <climits> |
| Rui Ueyama | 863931c | 2013-10-26 00:46:57 +0000 | [diff] [blame] | 32 | #include <set> |
| Rui Ueyama | 9149181 | 2013-09-23 19:52:35 +0000 | [diff] [blame] | 33 | |
| Rui Ueyama | 9e56839 | 2013-05-28 18:13:31 +0000 | [diff] [blame] | 34 | namespace lld { |
| 35 | |
| Rui Ueyama | 0ca149f | 2013-08-06 22:31:59 +0000 | [diff] [blame] | 36 | bool PECOFFLinkingContext::validateImpl(raw_ostream &diagnostics) { |
| Rui Ueyama | eb0cc96 | 2013-06-08 03:59:00 +0000 | [diff] [blame] | 37 | if (_stackReserve < _stackCommit) { |
| 38 | diagnostics << "Invalid stack size: reserve size must be equal to or " |
| Rui Ueyama | 0ca149f | 2013-08-06 22:31:59 +0000 | [diff] [blame] | 39 | << "greater than commit size, but got " << _stackCommit |
| 40 | << " and " << _stackReserve << ".\n"; |
| Rui Ueyama | 8db1edd | 2013-09-24 23:26:34 +0000 | [diff] [blame] | 41 | return false; |
| Rui Ueyama | eb0cc96 | 2013-06-08 03:59:00 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| Rui Ueyama | 9dd08d9 | 2013-06-08 22:59:10 +0000 | [diff] [blame] | 44 | if (_heapReserve < _heapCommit) { |
| 45 | diagnostics << "Invalid heap size: reserve size must be equal to or " |
| Rui Ueyama | 0ca149f | 2013-08-06 22:31:59 +0000 | [diff] [blame] | 46 | << "greater than commit size, but got " << _heapCommit |
| 47 | << " and " << _heapReserve << ".\n"; |
| Rui Ueyama | 8db1edd | 2013-09-24 23:26:34 +0000 | [diff] [blame] | 48 | return false; |
| Rui Ueyama | 9dd08d9 | 2013-06-08 22:59:10 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| Rui Ueyama | 530488c | 2013-09-03 22:57:00 +0000 | [diff] [blame] | 51 | // It's an error if the base address is not multiple of 64K. |
| Rui Ueyama | ea7e930 | 2014-01-31 04:49:13 +0000 | [diff] [blame] | 52 | if (getBaseAddress() & 0xffff) { |
| Rui Ueyama | 530488c | 2013-09-03 22:57:00 +0000 | [diff] [blame] | 53 | diagnostics << "Base address have to be multiple of 64K, but got " |
| Rui Ueyama | ea7e930 | 2014-01-31 04:49:13 +0000 | [diff] [blame] | 54 | << getBaseAddress() << "\n"; |
| Rui Ueyama | 8db1edd | 2013-09-24 23:26:34 +0000 | [diff] [blame] | 55 | return false; |
| Rui Ueyama | 530488c | 2013-09-03 22:57:00 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| Rui Ueyama | a6fddab | 2013-12-16 09:15:58 +0000 | [diff] [blame] | 58 | // Check for duplicate export ordinals. |
| 59 | std::set<int> exports; |
| 60 | for (const PECOFFLinkingContext::ExportDesc &desc : getDllExports()) { |
| 61 | if (desc.ordinal == -1) |
| 62 | continue; |
| 63 | if (exports.count(desc.ordinal) == 1) { |
| 64 | diagnostics << "Duplicate export ordinals: " << desc.ordinal << "\n"; |
| 65 | return false; |
| 66 | } |
| 67 | exports.insert(desc.ordinal); |
| 68 | } |
| 69 | |
| Rui Ueyama | 1710fe7d | 2014-02-27 00:05:43 +0000 | [diff] [blame] | 70 | // Check for /align. |
| Rui Ueyama | 41b99dc | 2013-11-06 19:30:14 +0000 | [diff] [blame] | 71 | std::bitset<64> alignment(_sectionDefaultAlignment); |
| Rui Ueyama | 9149181 | 2013-09-23 19:52:35 +0000 | [diff] [blame] | 72 | if (alignment.count() != 1) { |
| 73 | diagnostics << "Section alignment must be a power of 2, but got " |
| Rui Ueyama | 41b99dc | 2013-11-06 19:30:14 +0000 | [diff] [blame] | 74 | << _sectionDefaultAlignment << "\n"; |
| Rui Ueyama | 8db1edd | 2013-09-24 23:26:34 +0000 | [diff] [blame] | 75 | return false; |
| Rui Ueyama | 9149181 | 2013-09-23 19:52:35 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| Rui Ueyama | 1710fe7d | 2014-02-27 00:05:43 +0000 | [diff] [blame] | 78 | // /safeseh is only valid for x86. |
| 79 | if (getMachineType() != llvm::COFF::IMAGE_FILE_MACHINE_I386 && noSEH()) { |
| 80 | diagnostics << "/SAFESEH:NO is only valid for x86.\n"; |
| 81 | return false; |
| 82 | } |
| 83 | |
| Rui Ueyama | 49bfd50 | 2014-01-24 19:17:05 +0000 | [diff] [blame] | 84 | // Architectures other than x86/x64 is not supported yet. |
| 85 | if (_machineType != llvm::COFF::IMAGE_FILE_MACHINE_I386 && |
| 86 | _machineType != llvm::COFF::IMAGE_FILE_MACHINE_AMD64) { |
| 87 | diagnostics << "Machine type other than x86/x64 is not supported.\n"; |
| Rui Ueyama | 8db1edd | 2013-09-24 23:26:34 +0000 | [diff] [blame] | 88 | return false; |
| Rui Ueyama | 98896ed | 2013-09-12 19:46:53 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| Rui Ueyama | 9e56839 | 2013-05-28 18:13:31 +0000 | [diff] [blame] | 91 | _writer = createWriterPECOFF(*this); |
| Rui Ueyama | 8db1edd | 2013-09-24 23:26:34 +0000 | [diff] [blame] | 92 | return true; |
| Rui Ueyama | 9e56839 | 2013-05-28 18:13:31 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| Shankar Easwaran | a96f3a3 | 2013-10-07 02:47:09 +0000 | [diff] [blame] | 95 | std::unique_ptr<File> PECOFFLinkingContext::createEntrySymbolFile() const { |
| Rui Ueyama | 3907f2a | 2014-03-28 19:02:06 +0000 | [diff] [blame] | 96 | return LinkingContext::createEntrySymbolFile("<command line option /entry>"); |
| Shankar Easwaran | d26c8e3 | 2013-08-31 05:27:38 +0000 | [diff] [blame] | 97 | } |
| Rui Ueyama | 908606d | 2013-08-09 04:44:15 +0000 | [diff] [blame] | 98 | |
| Shankar Easwaran | a96f3a3 | 2013-10-07 02:47:09 +0000 | [diff] [blame] | 99 | std::unique_ptr<File> PECOFFLinkingContext::createUndefinedSymbolFile() const { |
| Rui Ueyama | 3907f2a | 2014-03-28 19:02:06 +0000 | [diff] [blame] | 100 | return LinkingContext::createUndefinedSymbolFile( |
| 101 | "<command line option /include>"); |
| Shankar Easwaran | d26c8e3 | 2013-08-31 05:27:38 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| Shankar Easwaran | a96f3a3 | 2013-10-07 02:47:09 +0000 | [diff] [blame] | 104 | bool PECOFFLinkingContext::createImplicitFiles( |
| 105 | std::vector<std::unique_ptr<File> > &) const { |
| 106 | std::unique_ptr<SimpleFileNode> fileNode( |
| 107 | new SimpleFileNode("Implicit Files")); |
| 108 | std::unique_ptr<File> linkerGeneratedSymFile( |
| Rui Ueyama | 091071f | 2013-12-13 02:58:27 +0000 | [diff] [blame] | 109 | new pecoff::LinkerGeneratedSymbolFile(*this)); |
| Shankar Easwaran | a96f3a3 | 2013-10-07 02:47:09 +0000 | [diff] [blame] | 110 | fileNode->appendInputFile(std::move(linkerGeneratedSymFile)); |
| Rui Ueyama | 8bd093b | 2014-04-04 00:14:04 +0000 | [diff] [blame] | 111 | getInputGraph().insertElementAt(std::move(fileNode), |
| 112 | InputGraph::Position::END); |
| Rui Ueyama | 72d57ab | 2014-04-29 00:32:00 +0000 | [diff] [blame] | 113 | |
| 114 | std::unique_ptr<SimpleFileNode> impFileNode(new SimpleFileNode("imp")); |
| 115 | impFileNode->appendInputFile( |
| 116 | std::unique_ptr<File>(new pecoff::LocallyImportedSymbolFile(*this))); |
| Rui Ueyama | 680210f | 2014-04-30 03:31:46 +0000 | [diff] [blame^] | 117 | getInputGraph().insertElementAt(std::move(impFileNode), |
| 118 | InputGraph::Position::END); |
| Shankar Easwaran | a96f3a3 | 2013-10-07 02:47:09 +0000 | [diff] [blame] | 119 | return true; |
| Rui Ueyama | fd50283 | 2013-07-24 22:53:23 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| Rui Ueyama | 863931c | 2013-10-26 00:46:57 +0000 | [diff] [blame] | 122 | /// Returns the section name in the resulting executable. |
| 123 | /// |
| 124 | /// Sections in object files are usually output to the executable with the same |
| 125 | /// name, but you can rename by command line option. /merge:from=to makes the |
| 126 | /// linker to combine "from" section contents to "to" section in the |
| 127 | /// executable. We have a mapping for the renaming. This method looks up the |
| 128 | /// table and returns a new section name if renamed. |
| 129 | StringRef |
| Rui Ueyama | 951dd1d | 2013-11-27 18:03:31 +0000 | [diff] [blame] | 130 | PECOFFLinkingContext::getOutputSectionName(StringRef sectionName) const { |
| Rui Ueyama | 863931c | 2013-10-26 00:46:57 +0000 | [diff] [blame] | 131 | auto it = _renamedSections.find(sectionName); |
| 132 | if (it == _renamedSections.end()) |
| 133 | return sectionName; |
| Rui Ueyama | 951dd1d | 2013-11-27 18:03:31 +0000 | [diff] [blame] | 134 | return getOutputSectionName(it->second); |
| Rui Ueyama | 863931c | 2013-10-26 00:46:57 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /// Adds a mapping to the section renaming table. This method will be used for |
| 138 | /// /merge command line option. |
| 139 | bool PECOFFLinkingContext::addSectionRenaming(raw_ostream &diagnostics, |
| 140 | StringRef from, StringRef to) { |
| 141 | auto it = _renamedSections.find(from); |
| 142 | if (it != _renamedSections.end()) { |
| 143 | if (it->second == to) |
| 144 | // There's already the same mapping. |
| 145 | return true; |
| 146 | diagnostics << "Section \"" << from << "\" is already mapped to \"" |
| 147 | << it->second << ", so it cannot be mapped to \"" << to << "\"."; |
| 148 | return true; |
| 149 | } |
| 150 | |
| 151 | // Add a mapping, and check if there's no cycle in the renaming mapping. The |
| 152 | // cycle detection algorithm we use here is naive, but that's OK because the |
| 153 | // number of mapping is usually less than 10. |
| 154 | _renamedSections[from] = to; |
| 155 | for (auto elem : _renamedSections) { |
| 156 | StringRef sectionName = elem.first; |
| 157 | std::set<StringRef> visited; |
| 158 | visited.insert(sectionName); |
| 159 | for (;;) { |
| Nick Kledzik | 3df8104 | 2013-11-06 21:30:15 +0000 | [diff] [blame] | 160 | auto pos = _renamedSections.find(sectionName); |
| 161 | if (pos == _renamedSections.end()) |
| Rui Ueyama | 863931c | 2013-10-26 00:46:57 +0000 | [diff] [blame] | 162 | break; |
| Nick Kledzik | 3df8104 | 2013-11-06 21:30:15 +0000 | [diff] [blame] | 163 | if (visited.count(pos->second)) { |
| Rui Ueyama | 863931c | 2013-10-26 00:46:57 +0000 | [diff] [blame] | 164 | diagnostics << "/merge:" << from << "=" << to << " makes a cycle"; |
| 165 | return false; |
| 166 | } |
| Nick Kledzik | 3df8104 | 2013-11-06 21:30:15 +0000 | [diff] [blame] | 167 | sectionName = pos->second; |
| Rui Ueyama | 863931c | 2013-10-26 00:46:57 +0000 | [diff] [blame] | 168 | visited.insert(sectionName); |
| 169 | } |
| 170 | } |
| 171 | return true; |
| 172 | } |
| 173 | |
| Rui Ueyama | 34d6e9b | 2013-12-09 01:47:32 +0000 | [diff] [blame] | 174 | StringRef PECOFFLinkingContext::getAlternateName(StringRef def) const { |
| 175 | auto it = _alternateNames.find(def); |
| 176 | if (it == _alternateNames.end()) |
| 177 | return ""; |
| 178 | return it->second; |
| 179 | } |
| 180 | |
| 181 | void PECOFFLinkingContext::setAlternateName(StringRef weak, StringRef def) { |
| 182 | _alternateNames[def] = weak; |
| 183 | } |
| 184 | |
| Rui Ueyama | 2897feb | 2013-07-19 02:18:25 +0000 | [diff] [blame] | 185 | /// Try to find the input library file from the search paths and append it to |
| 186 | /// the input file list. Returns true if the library file is found. |
| Shankar Easwaran | e44104b | 2013-08-21 22:57:10 +0000 | [diff] [blame] | 187 | StringRef PECOFFLinkingContext::searchLibraryFile(StringRef filename) const { |
| Rui Ueyama | 2897feb | 2013-07-19 02:18:25 +0000 | [diff] [blame] | 188 | // Current directory always takes precedence over the search paths. |
| Shankar Easwaran | e44104b | 2013-08-21 22:57:10 +0000 | [diff] [blame] | 189 | if (llvm::sys::path::is_absolute(filename) || llvm::sys::fs::exists(filename)) |
| 190 | return filename; |
| Rui Ueyama | 2897feb | 2013-07-19 02:18:25 +0000 | [diff] [blame] | 191 | // Iterate over the search paths. |
| 192 | for (StringRef dir : _inputSearchPaths) { |
| 193 | SmallString<128> path = dir; |
| 194 | llvm::sys::path::append(path, filename); |
| Shankar Easwaran | e44104b | 2013-08-21 22:57:10 +0000 | [diff] [blame] | 195 | if (llvm::sys::fs::exists(path.str())) |
| Rui Ueyama | 90bcd11 | 2013-11-21 00:17:31 +0000 | [diff] [blame] | 196 | return allocate(path.str()); |
| Rui Ueyama | 2897feb | 2013-07-19 02:18:25 +0000 | [diff] [blame] | 197 | } |
| Shankar Easwaran | e44104b | 2013-08-21 22:57:10 +0000 | [diff] [blame] | 198 | return filename; |
| Rui Ueyama | 2897feb | 2013-07-19 02:18:25 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| Rui Ueyama | abc227b | 2013-12-14 04:32:29 +0000 | [diff] [blame] | 201 | /// Returns the decorated name of the given symbol name. On 32-bit x86, it |
| 202 | /// adds "_" at the beginning of the string. On other architectures, the |
| 203 | /// return value is the same as the argument. |
| 204 | StringRef PECOFFLinkingContext::decorateSymbol(StringRef name) const { |
| 205 | if (_machineType != llvm::COFF::IMAGE_FILE_MACHINE_I386) |
| 206 | return name; |
| 207 | std::string str = "_"; |
| 208 | str.append(name); |
| 209 | return allocate(str); |
| 210 | } |
| 211 | |
| Rui Ueyama | 090a7cd | 2013-12-24 09:15:57 +0000 | [diff] [blame] | 212 | StringRef PECOFFLinkingContext::undecorateSymbol(StringRef name) const { |
| 213 | if (_machineType != llvm::COFF::IMAGE_FILE_MACHINE_I386) |
| 214 | return name; |
| Rui Ueyama | 11f3f1f | 2014-04-24 17:04:19 +0000 | [diff] [blame] | 215 | if (!name.startswith("_")) |
| 216 | return name; |
| Rui Ueyama | 090a7cd | 2013-12-24 09:15:57 +0000 | [diff] [blame] | 217 | return name.substr(1); |
| 218 | } |
| 219 | |
| Rui Ueyama | ea7e930 | 2014-01-31 04:49:13 +0000 | [diff] [blame] | 220 | uint64_t PECOFFLinkingContext::getBaseAddress() const { |
| 221 | if (_baseAddress == invalidBaseAddress) |
| Rui Ueyama | 8851d45 | 2014-01-31 04:57:03 +0000 | [diff] [blame] | 222 | return is64Bit() ? pe32PlusDefaultBaseAddress : pe32DefaultBaseAddress; |
| Rui Ueyama | ea7e930 | 2014-01-31 04:49:13 +0000 | [diff] [blame] | 223 | return _baseAddress; |
| 224 | } |
| Rui Ueyama | 9e56839 | 2013-05-28 18:13:31 +0000 | [diff] [blame] | 225 | |
| Rui Ueyama | ea7e930 | 2014-01-31 04:49:13 +0000 | [diff] [blame] | 226 | Writer &PECOFFLinkingContext::writer() const { return *_writer; } |
| Rui Ueyama | 9e56839 | 2013-05-28 18:13:31 +0000 | [diff] [blame] | 227 | |
| Rui Ueyama | 615b200 | 2013-11-27 21:34:16 +0000 | [diff] [blame] | 228 | void PECOFFLinkingContext::setSectionSetMask(StringRef sectionName, |
| 229 | uint32_t newFlags) { |
| 230 | _sectionSetMask[sectionName] |= newFlags; |
| 231 | _sectionClearMask[sectionName] &= ~newFlags; |
| 232 | const uint32_t rwx = (llvm::COFF::IMAGE_SCN_MEM_READ | |
| 233 | llvm::COFF::IMAGE_SCN_MEM_WRITE | |
| 234 | llvm::COFF::IMAGE_SCN_MEM_EXECUTE); |
| 235 | if (newFlags & rwx) |
| 236 | _sectionClearMask[sectionName] |= ~_sectionSetMask[sectionName] & rwx; |
| 237 | assert((_sectionSetMask[sectionName] & _sectionClearMask[sectionName]) == 0); |
| 238 | } |
| 239 | |
| 240 | void PECOFFLinkingContext::setSectionClearMask(StringRef sectionName, |
| 241 | uint32_t newFlags) { |
| 242 | _sectionClearMask[sectionName] |= newFlags; |
| 243 | _sectionSetMask[sectionName] &= ~newFlags; |
| 244 | assert((_sectionSetMask[sectionName] & _sectionClearMask[sectionName]) == 0); |
| 245 | } |
| 246 | |
| 247 | uint32_t PECOFFLinkingContext::getSectionAttributes(StringRef sectionName, |
| 248 | uint32_t flags) const { |
| 249 | auto si = _sectionSetMask.find(sectionName); |
| 250 | uint32_t setMask = (si == _sectionSetMask.end()) ? 0 : si->second; |
| 251 | auto ci = _sectionClearMask.find(sectionName); |
| 252 | uint32_t clearMask = (ci == _sectionClearMask.end()) ? 0 : ci->second; |
| 253 | return (flags | setMask) & ~clearMask; |
| 254 | } |
| Rui Ueyama | 170a1a8 | 2013-12-20 07:48:29 +0000 | [diff] [blame] | 255 | |
| Rui Ueyama | ffd8105 | 2013-12-28 08:40:37 +0000 | [diff] [blame] | 256 | // Returns true if two export descriptors have conflicting contents, |
| 257 | // e.g. different export ordinals. |
| 258 | static bool exportConflicts(const PECOFFLinkingContext::ExportDesc &a, |
| 259 | const PECOFFLinkingContext::ExportDesc &b) { |
| Rui Ueyama | 93f7604 | 2013-12-28 10:09:21 +0000 | [diff] [blame] | 260 | return (a.ordinal > 0 && b.ordinal > 0 && a.ordinal != b.ordinal) || |
| 261 | a.noname != b.noname || a.isData != b.isData; |
| Rui Ueyama | ffd8105 | 2013-12-28 08:40:37 +0000 | [diff] [blame] | 262 | } |
| 263 | |
| Rui Ueyama | cf46161 | 2013-12-25 06:46:45 +0000 | [diff] [blame] | 264 | void PECOFFLinkingContext::addDllExport(ExportDesc &desc) { |
| Rui Ueyama | ffd8105 | 2013-12-28 08:40:37 +0000 | [diff] [blame] | 265 | auto existing = _dllExports.insert(desc); |
| 266 | if (existing.second) |
| 267 | return; |
| 268 | if (!exportConflicts(*existing.first, desc)) { |
| 269 | _dllExports.erase(existing.first); |
| 270 | _dllExports.insert(desc); |
| Rui Ueyama | cf46161 | 2013-12-25 06:46:45 +0000 | [diff] [blame] | 271 | return; |
| 272 | } |
| Rui Ueyama | ffd8105 | 2013-12-28 08:40:37 +0000 | [diff] [blame] | 273 | llvm::errs() << "Export symbol '" << desc.name |
| 274 | << "' specified more than once.\n"; |
| Rui Ueyama | cf46161 | 2013-12-25 06:46:45 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| Rui Ueyama | 409ac18 | 2014-04-25 03:35:13 +0000 | [diff] [blame] | 277 | std::string PECOFFLinkingContext::getOutputImportLibraryPath() const { |
| 278 | if (!_implib.empty()) |
| 279 | return _implib; |
| 280 | SmallString<128> path = outputPath(); |
| 281 | llvm::sys::path::replace_extension(path, ".lib"); |
| 282 | return path.str(); |
| 283 | } |
| 284 | |
| Shankar Easwaran | 2bc2492 | 2013-10-29 05:12:14 +0000 | [diff] [blame] | 285 | void PECOFFLinkingContext::addPasses(PassManager &pm) { |
| Rui Ueyama | 1a11b3b | 2013-11-25 02:00:00 +0000 | [diff] [blame] | 286 | pm.add(std::unique_ptr<Pass>(new pecoff::SetSubsystemPass(*this))); |
| Rui Ueyama | c91c24e3 | 2013-12-13 06:58:27 +0000 | [diff] [blame] | 287 | pm.add(std::unique_ptr<Pass>(new pecoff::EdataPass(*this))); |
| Rui Ueyama | 3ee2bf6 | 2013-09-15 22:33:15 +0000 | [diff] [blame] | 288 | pm.add(std::unique_ptr<Pass>(new pecoff::IdataPass(*this))); |
| Nico Rieck | b9d84f4 | 2014-02-24 21:14:37 +0000 | [diff] [blame] | 289 | pm.add(std::unique_ptr<Pass>(new LayoutPass(registry()))); |
| Rui Ueyama | 2e09d93 | 2014-02-26 08:27:59 +0000 | [diff] [blame] | 290 | pm.add(std::unique_ptr<Pass>(new pecoff::LoadConfigPass(*this))); |
| Rui Ueyama | 32c3f17 | 2013-12-07 00:27:17 +0000 | [diff] [blame] | 291 | pm.add(std::unique_ptr<Pass>(new pecoff::GroupedSectionsPass())); |
| Rui Ueyama | d95a155 | 2013-06-17 16:59:54 +0000 | [diff] [blame] | 292 | } |
| Rui Ueyama | 091071f | 2013-12-13 02:58:27 +0000 | [diff] [blame] | 293 | |
| Rui Ueyama | 9e56839 | 2013-05-28 18:13:31 +0000 | [diff] [blame] | 294 | } // end namespace lld |