Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 1 | //===- InputFiles.cpp -----------------------------------------------------===// |
| 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 | |
| 10 | #include "Chunks.h" |
Rui Ueyama | 8fd9fb9 | 2015-06-01 02:58:15 +0000 | [diff] [blame] | 11 | #include "Error.h" |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 12 | #include "InputFiles.h" |
| 13 | #include "Writer.h" |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/STLExtras.h" |
Peter Collingbourne | 60c1616 | 2015-06-01 20:10:10 +0000 | [diff] [blame] | 15 | #include "llvm/LTO/LTOModule.h" |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 16 | #include "llvm/Object/COFF.h" |
| 17 | #include "llvm/Support/COFF.h" |
| 18 | #include "llvm/Support/Debug.h" |
| 19 | #include "llvm/Support/Endian.h" |
| 20 | #include "llvm/Support/raw_ostream.h" |
| 21 | |
| 22 | using namespace llvm::object; |
| 23 | using namespace llvm::support::endian; |
| 24 | using llvm::COFF::ImportHeader; |
Rui Ueyama | 80141a4 | 2015-06-08 05:00:42 +0000 | [diff] [blame] | 25 | using llvm::COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE; |
Rui Ueyama | a299488 | 2015-06-26 00:42:21 +0000 | [diff] [blame] | 26 | using llvm::COFF::IMAGE_FILE_MACHINE_AMD64; |
| 27 | using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN; |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 28 | using llvm::RoundUpToAlignment; |
| 29 | using llvm::sys::fs::identify_magic; |
| 30 | using llvm::sys::fs::file_magic; |
| 31 | |
| 32 | namespace lld { |
| 33 | namespace coff { |
| 34 | |
| 35 | // Returns the last element of a path, which is supposed to be a filename. |
| 36 | static StringRef getBasename(StringRef Path) { |
Rui Ueyama | ea63a28 | 2015-06-18 20:16:26 +0000 | [diff] [blame] | 37 | size_t Pos = Path.find_last_of("\\/"); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 38 | if (Pos == StringRef::npos) |
| 39 | return Path; |
| 40 | return Path.substr(Pos + 1); |
| 41 | } |
| 42 | |
| 43 | // Returns a string in the format of "foo.obj" or "foo.obj(bar.lib)". |
| 44 | std::string InputFile::getShortName() { |
| 45 | if (ParentName == "") |
| 46 | return getName().lower(); |
| 47 | std::string Res = (getBasename(ParentName) + "(" + |
| 48 | getBasename(getName()) + ")").str(); |
| 49 | return StringRef(Res).lower(); |
| 50 | } |
| 51 | |
| 52 | std::error_code ArchiveFile::parse() { |
Rui Ueyama | d7c2f58 | 2015-05-31 21:04:56 +0000 | [diff] [blame] | 53 | // Parse a MemoryBufferRef as an archive file. |
| 54 | auto ArchiveOrErr = Archive::create(MB); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 55 | if (auto EC = ArchiveOrErr.getError()) |
| 56 | return EC; |
| 57 | File = std::move(ArchiveOrErr.get()); |
| 58 | |
| 59 | // Allocate a buffer for Lazy objects. |
Rui Ueyama | 605e1f6 | 2015-06-26 23:51:45 +0000 | [diff] [blame] | 60 | size_t NumSyms = File->getNumberOfSymbols(); |
| 61 | size_t BufSize = NumSyms * sizeof(Lazy); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 62 | Lazy *Buf = (Lazy *)Alloc.Allocate(BufSize, llvm::alignOf<Lazy>()); |
Rui Ueyama | 605e1f6 | 2015-06-26 23:51:45 +0000 | [diff] [blame] | 63 | SymbolBodies.reserve(NumSyms); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 64 | |
| 65 | // Read the symbol table to construct Lazy objects. |
| 66 | uint32_t I = 0; |
| 67 | for (const Archive::Symbol &Sym : File->symbols()) { |
Rui Ueyama | 29792a8 | 2015-06-19 21:25:44 +0000 | [diff] [blame] | 68 | auto *B = new (&Buf[I++]) Lazy(this, Sym); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 69 | // Skip special symbol exists in import library files. |
Rui Ueyama | 29792a8 | 2015-06-19 21:25:44 +0000 | [diff] [blame] | 70 | if (B->getName() != "__NULL_IMPORT_DESCRIPTOR") |
| 71 | SymbolBodies.push_back(B); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 72 | } |
| 73 | return std::error_code(); |
| 74 | } |
| 75 | |
| 76 | // Returns a buffer pointing to a member file containing a given symbol. |
| 77 | ErrorOr<MemoryBufferRef> ArchiveFile::getMember(const Archive::Symbol *Sym) { |
| 78 | auto ItOrErr = Sym->getMember(); |
| 79 | if (auto EC = ItOrErr.getError()) |
| 80 | return EC; |
| 81 | Archive::child_iterator It = ItOrErr.get(); |
| 82 | |
| 83 | // Return an empty buffer if we have already returned the same buffer. |
| 84 | const char *StartAddr = It->getBuffer().data(); |
| 85 | auto Pair = Seen.insert(StartAddr); |
| 86 | if (!Pair.second) |
| 87 | return MemoryBufferRef(); |
| 88 | return It->getMemoryBufferRef(); |
| 89 | } |
| 90 | |
| 91 | std::error_code ObjectFile::parse() { |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 92 | // Parse a memory buffer as a COFF file. |
Rui Ueyama | d7c2f58 | 2015-05-31 21:04:56 +0000 | [diff] [blame] | 93 | auto BinOrErr = createBinary(MB); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 94 | if (auto EC = BinOrErr.getError()) |
| 95 | return EC; |
| 96 | std::unique_ptr<Binary> Bin = std::move(BinOrErr.get()); |
| 97 | |
| 98 | if (auto *Obj = dyn_cast<COFFObjectFile>(Bin.get())) { |
| 99 | Bin.release(); |
| 100 | COFFObj.reset(Obj); |
| 101 | } else { |
Rui Ueyama | 8fd9fb9 | 2015-06-01 02:58:15 +0000 | [diff] [blame] | 102 | llvm::errs() << getName() << " is not a COFF file.\n"; |
| 103 | return make_error_code(LLDError::InvalidFile); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 104 | } |
Rui Ueyama | a299488 | 2015-06-26 00:42:21 +0000 | [diff] [blame] | 105 | if (COFFObj->getMachine() != IMAGE_FILE_MACHINE_AMD64 && |
| 106 | COFFObj->getMachine() != IMAGE_FILE_MACHINE_UNKNOWN) { |
| 107 | llvm::errs() << getName() << " is not an x64 object file.\n"; |
| 108 | return make_error_code(LLDError::InvalidFile); |
| 109 | } |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 110 | |
| 111 | // Read section and symbol tables. |
| 112 | if (auto EC = initializeChunks()) |
| 113 | return EC; |
| 114 | return initializeSymbols(); |
| 115 | } |
| 116 | |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 117 | std::error_code ObjectFile::initializeChunks() { |
| 118 | uint32_t NumSections = COFFObj->getNumberOfSections(); |
| 119 | Chunks.reserve(NumSections); |
| 120 | SparseChunks.resize(NumSections + 1); |
| 121 | for (uint32_t I = 1; I < NumSections + 1; ++I) { |
| 122 | const coff_section *Sec; |
| 123 | StringRef Name; |
Rui Ueyama | 8fd9fb9 | 2015-06-01 02:58:15 +0000 | [diff] [blame] | 124 | if (auto EC = COFFObj->getSection(I, Sec)) { |
| 125 | llvm::errs() << "getSection failed: " << Name << ": " |
| 126 | << EC.message() << "\n"; |
| 127 | return make_error_code(LLDError::BrokenFile); |
| 128 | } |
| 129 | if (auto EC = COFFObj->getSectionName(Sec, Name)) { |
| 130 | llvm::errs() << "getSectionName failed: " << Name << ": " |
| 131 | << EC.message() << "\n"; |
| 132 | return make_error_code(LLDError::BrokenFile); |
| 133 | } |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 134 | if (Name == ".drectve") { |
| 135 | ArrayRef<uint8_t> Data; |
| 136 | COFFObj->getSectionContents(Sec, Data); |
Rui Ueyama | e3a3350 | 2015-06-20 23:10:05 +0000 | [diff] [blame] | 137 | Directives = std::string((const char *)Data.data(), Data.size()); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 138 | continue; |
| 139 | } |
| 140 | if (Name.startswith(".debug")) |
| 141 | continue; |
| 142 | if (Sec->Characteristics & llvm::COFF::IMAGE_SCN_LNK_REMOVE) |
| 143 | continue; |
Peter Collingbourne | bd3a29d | 2015-06-24 00:12:36 +0000 | [diff] [blame] | 144 | auto *C = new (Alloc) SectionChunk(this, Sec); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 145 | Chunks.push_back(C); |
| 146 | SparseChunks[I] = C; |
| 147 | } |
| 148 | return std::error_code(); |
| 149 | } |
| 150 | |
| 151 | std::error_code ObjectFile::initializeSymbols() { |
| 152 | uint32_t NumSymbols = COFFObj->getNumberOfSymbols(); |
| 153 | SymbolBodies.reserve(NumSymbols); |
| 154 | SparseSymbolBodies.resize(NumSymbols); |
| 155 | int32_t LastSectionNumber = 0; |
| 156 | for (uint32_t I = 0; I < NumSymbols; ++I) { |
| 157 | // Get a COFFSymbolRef object. |
| 158 | auto SymOrErr = COFFObj->getSymbol(I); |
Rui Ueyama | 8fd9fb9 | 2015-06-01 02:58:15 +0000 | [diff] [blame] | 159 | if (auto EC = SymOrErr.getError()) { |
| 160 | llvm::errs() << "broken object file: " << getName() << ": " |
| 161 | << EC.message() << "\n"; |
| 162 | return make_error_code(LLDError::BrokenFile); |
| 163 | } |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 164 | COFFSymbolRef Sym = SymOrErr.get(); |
| 165 | |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 166 | const void *AuxP = nullptr; |
| 167 | if (Sym.getNumberOfAuxSymbols()) |
| 168 | AuxP = COFFObj->getSymbol(I + 1)->getRawPtr(); |
| 169 | bool IsFirst = (LastSectionNumber != Sym.getSectionNumber()); |
| 170 | |
Rui Ueyama | 57fe78d | 2015-06-08 19:43:59 +0000 | [diff] [blame] | 171 | SymbolBody *Body = createSymbolBody(Sym, AuxP, IsFirst); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 172 | if (Body) { |
| 173 | SymbolBodies.push_back(Body); |
| 174 | SparseSymbolBodies[I] = Body; |
| 175 | } |
| 176 | I += Sym.getNumberOfAuxSymbols(); |
| 177 | LastSectionNumber = Sym.getSectionNumber(); |
| 178 | } |
| 179 | return std::error_code(); |
| 180 | } |
| 181 | |
Rui Ueyama | 57fe78d | 2015-06-08 19:43:59 +0000 | [diff] [blame] | 182 | SymbolBody *ObjectFile::createSymbolBody(COFFSymbolRef Sym, const void *AuxP, |
| 183 | bool IsFirst) { |
| 184 | StringRef Name; |
| 185 | if (Sym.isUndefined()) { |
| 186 | COFFObj->getSymbolName(Sym, Name); |
Rui Ueyama | b4f791b | 2015-06-08 00:09:25 +0000 | [diff] [blame] | 187 | return new (Alloc) Undefined(Name); |
Rui Ueyama | 57fe78d | 2015-06-08 19:43:59 +0000 | [diff] [blame] | 188 | } |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 189 | if (Sym.isCommon()) { |
Rui Ueyama | fc510f4 | 2015-06-25 19:10:58 +0000 | [diff] [blame] | 190 | auto *C = new (Alloc) CommonChunk(Sym); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 191 | Chunks.push_back(C); |
Rui Ueyama | 68633f1 | 2015-06-25 23:22:00 +0000 | [diff] [blame] | 192 | return new (Alloc) DefinedCommon(this, Sym, C); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 193 | } |
Rui Ueyama | 57fe78d | 2015-06-08 19:43:59 +0000 | [diff] [blame] | 194 | if (Sym.isAbsolute()) { |
| 195 | COFFObj->getSymbolName(Sym, Name); |
| 196 | // Skip special symbols. |
| 197 | if (Name == "@comp.id" || Name == "@feat.00") |
| 198 | return nullptr; |
Rui Ueyama | ccde19d | 2015-06-26 03:09:23 +0000 | [diff] [blame] | 199 | return new (Alloc) DefinedAbsolute(Name, Sym); |
Rui Ueyama | 57fe78d | 2015-06-08 19:43:59 +0000 | [diff] [blame] | 200 | } |
Peter Collingbourne | c7b685d | 2015-06-24 00:05:50 +0000 | [diff] [blame] | 201 | if (Sym.getSectionNumber() == llvm::COFF::IMAGE_SYM_DEBUG) |
| 202 | return nullptr; |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 203 | // TODO: Handle IMAGE_WEAK_EXTERN_SEARCH_ALIAS |
| 204 | if (Sym.isWeakExternal()) { |
Rui Ueyama | 57fe78d | 2015-06-08 19:43:59 +0000 | [diff] [blame] | 205 | COFFObj->getSymbolName(Sym, Name); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 206 | auto *Aux = (const coff_aux_weak_external *)AuxP; |
| 207 | return new (Alloc) Undefined(Name, &SparseSymbolBodies[Aux->TagIndex]); |
| 208 | } |
Chandler Carruth | ee5bf52 | 2015-06-29 21:32:37 +0000 | [diff] [blame] | 209 | |
| 210 | // Nothing else to do without a section chunk. |
| 211 | auto *SC = cast_or_null<SectionChunk>(SparseChunks[Sym.getSectionNumber()]); |
| 212 | if (!SC) |
| 213 | return nullptr; |
| 214 | |
Rui Ueyama | 80141a4 | 2015-06-08 05:00:42 +0000 | [diff] [blame] | 215 | // Handle associative sections |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 216 | if (IsFirst && AuxP) { |
Chandler Carruth | ee5bf52 | 2015-06-29 21:32:37 +0000 | [diff] [blame] | 217 | auto *Aux = reinterpret_cast<const coff_aux_section_definition *>(AuxP); |
| 218 | if (Aux->Selection == IMAGE_COMDAT_SELECT_ASSOCIATIVE) |
| 219 | if (auto *ParentSC = cast_or_null<SectionChunk>( |
| 220 | SparseChunks[Aux->getNumber(Sym.isBigObj())])) |
| 221 | ParentSC->addAssociative(SC); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 222 | } |
Chandler Carruth | ee5bf52 | 2015-06-29 21:32:37 +0000 | [diff] [blame] | 223 | |
| 224 | auto *B = new (Alloc) DefinedRegular(this, Sym, SC); |
| 225 | if (SC->isCOMDAT() && Sym.getValue() == 0 && !AuxP) |
| 226 | SC->setSymbol(B); |
| 227 | |
| 228 | return B; |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | std::error_code ImportFile::parse() { |
Rui Ueyama | d7c2f58 | 2015-05-31 21:04:56 +0000 | [diff] [blame] | 232 | const char *Buf = MB.getBufferStart(); |
| 233 | const char *End = MB.getBufferEnd(); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 234 | const auto *Hdr = reinterpret_cast<const coff_import_header *>(Buf); |
| 235 | |
| 236 | // Check if the total size is valid. |
Denis Protivensky | 6833690 | 2015-06-01 09:26:32 +0000 | [diff] [blame] | 237 | if ((size_t)(End - Buf) != (sizeof(*Hdr) + Hdr->SizeOfData)) { |
Rui Ueyama | 8fd9fb9 | 2015-06-01 02:58:15 +0000 | [diff] [blame] | 238 | llvm::errs() << "broken import library\n"; |
| 239 | return make_error_code(LLDError::BrokenFile); |
| 240 | } |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 241 | |
| 242 | // Read names and create an __imp_ symbol. |
| 243 | StringRef Name = StringAlloc.save(StringRef(Buf + sizeof(*Hdr))); |
| 244 | StringRef ImpName = StringAlloc.save(Twine("__imp_") + Name); |
| 245 | StringRef DLLName(Buf + sizeof(coff_import_header) + Name.size() + 1); |
Rui Ueyama | fd99e01 | 2015-06-01 21:05:27 +0000 | [diff] [blame] | 246 | StringRef ExternalName = Name; |
| 247 | if (Hdr->getNameType() == llvm::COFF::IMPORT_ORDINAL) |
| 248 | ExternalName = ""; |
| 249 | auto *ImpSym = new (Alloc) DefinedImportData(DLLName, ImpName, ExternalName, |
| 250 | Hdr); |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 251 | SymbolBodies.push_back(ImpSym); |
| 252 | |
| 253 | // If type is function, we need to create a thunk which jump to an |
| 254 | // address pointed by the __imp_ symbol. (This allows you to call |
| 255 | // DLL functions just like regular non-DLL functions.) |
| 256 | if (Hdr->getType() == llvm::COFF::IMPORT_CODE) |
| 257 | SymbolBodies.push_back(new (Alloc) DefinedImportThunk(Name, ImpSym)); |
| 258 | return std::error_code(); |
| 259 | } |
| 260 | |
Peter Collingbourne | 60c1616 | 2015-06-01 20:10:10 +0000 | [diff] [blame] | 261 | std::error_code BitcodeFile::parse() { |
| 262 | std::string Err; |
Rui Ueyama | 81b030c | 2015-06-01 21:19:43 +0000 | [diff] [blame] | 263 | M.reset(LTOModule::createFromBuffer(MB.getBufferStart(), |
| 264 | MB.getBufferSize(), |
| 265 | llvm::TargetOptions(), Err)); |
Peter Collingbourne | 60c1616 | 2015-06-01 20:10:10 +0000 | [diff] [blame] | 266 | if (!Err.empty()) { |
| 267 | llvm::errs() << Err << '\n'; |
| 268 | return make_error_code(LLDError::BrokenFile); |
| 269 | } |
| 270 | |
Rui Ueyama | 223fe1b | 2015-06-18 20:29:41 +0000 | [diff] [blame] | 271 | llvm::BumpPtrStringSaver Saver(Alloc); |
Peter Collingbourne | 60c1616 | 2015-06-01 20:10:10 +0000 | [diff] [blame] | 272 | for (unsigned I = 0, E = M->getSymbolCount(); I != E; ++I) { |
Peter Collingbourne | df637ea | 2015-06-08 20:21:28 +0000 | [diff] [blame] | 273 | lto_symbol_attributes Attrs = M->getSymbolAttributes(I); |
| 274 | if ((Attrs & LTO_SYMBOL_SCOPE_MASK) == LTO_SYMBOL_SCOPE_INTERNAL) |
| 275 | continue; |
| 276 | |
Rui Ueyama | 223fe1b | 2015-06-18 20:29:41 +0000 | [diff] [blame] | 277 | StringRef SymName = Saver.save(M->getSymbolName(I)); |
Peter Collingbourne | df637ea | 2015-06-08 20:21:28 +0000 | [diff] [blame] | 278 | int SymbolDef = Attrs & LTO_SYMBOL_DEFINITION_MASK; |
| 279 | if (SymbolDef == LTO_SYMBOL_DEFINITION_UNDEFINED) { |
Peter Collingbourne | 60c1616 | 2015-06-01 20:10:10 +0000 | [diff] [blame] | 280 | SymbolBodies.push_back(new (Alloc) Undefined(SymName)); |
| 281 | } else { |
Peter Collingbourne | 1b6fd1f | 2015-06-11 21:49:54 +0000 | [diff] [blame] | 282 | bool Replaceable = (SymbolDef == LTO_SYMBOL_DEFINITION_TENTATIVE || |
| 283 | (Attrs & LTO_SYMBOL_COMDAT)); |
| 284 | SymbolBodies.push_back(new (Alloc) DefinedBitcode(SymName, Replaceable)); |
Peter Collingbourne | 8b2492f | 2015-06-18 05:22:15 +0000 | [diff] [blame] | 285 | |
| 286 | const llvm::GlobalValue *GV = M->getSymbolGV(I); |
| 287 | if (GV && GV->hasDLLExportStorageClass()) { |
| 288 | Directives += " /export:"; |
| 289 | Directives += SymName; |
| 290 | if (!GV->getValueType()->isFunctionTy()) |
| 291 | Directives += ",data"; |
| 292 | } |
Peter Collingbourne | 60c1616 | 2015-06-01 20:10:10 +0000 | [diff] [blame] | 293 | } |
| 294 | } |
Peter Collingbourne | ace2f09 | 2015-06-06 02:00:45 +0000 | [diff] [blame] | 295 | |
| 296 | // Extract any linker directives from the bitcode file, which are represented |
| 297 | // as module flags with the key "Linker Options". |
| 298 | llvm::SmallVector<llvm::Module::ModuleFlagEntry, 8> Flags; |
| 299 | M->getModule().getModuleFlagsMetadata(Flags); |
| 300 | for (auto &&Flag : Flags) { |
| 301 | if (Flag.Key->getString() != "Linker Options") |
| 302 | continue; |
| 303 | |
| 304 | for (llvm::Metadata *Op : cast<llvm::MDNode>(Flag.Val)->operands()) { |
| 305 | for (llvm::Metadata *InnerOp : cast<llvm::MDNode>(Op)->operands()) { |
| 306 | Directives += " "; |
| 307 | Directives += cast<llvm::MDString>(InnerOp)->getString(); |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | |
Peter Collingbourne | 60c1616 | 2015-06-01 20:10:10 +0000 | [diff] [blame] | 312 | return std::error_code(); |
| 313 | } |
Rui Ueyama | 81b030c | 2015-06-01 21:19:43 +0000 | [diff] [blame] | 314 | |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 315 | } // namespace coff |
| 316 | } // namespace lld |