1 //===-- LTOModule.cpp - LLVM Link Time Optimizer --------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file implements the Link Time Optimization library. This library is 11 // intended to be used by linker to optimize code at link time. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #include "llvm/LTO/LTOModule.h" 16 #include "llvm/ADT/Triple.h" 17 #include "llvm/Bitcode/ReaderWriter.h" 18 #include "llvm/CodeGen/Analysis.h" 19 #include "llvm/IR/Constants.h" 20 #include "llvm/IR/LLVMContext.h" 21 #include "llvm/IR/Metadata.h" 22 #include "llvm/IR/Module.h" 23 #include "llvm/MC/MCExpr.h" 24 #include "llvm/MC/MCInst.h" 25 #include "llvm/MC/MCInstrInfo.h" 26 #include "llvm/MC/MCParser/MCAsmParser.h" 27 #include "llvm/MC/MCSection.h" 28 #include "llvm/MC/MCSubtargetInfo.h" 29 #include "llvm/MC/MCSymbol.h" 30 #include "llvm/MC/MCTargetAsmParser.h" 31 #include "llvm/MC/SubtargetFeature.h" 32 #include "llvm/Object/IRObjectFile.h" 33 #include "llvm/Object/ObjectFile.h" 34 #include "llvm/Support/CommandLine.h" 35 #include "llvm/Support/FileSystem.h" 36 #include "llvm/Support/Host.h" 37 #include "llvm/Support/MemoryBuffer.h" 38 #include "llvm/Support/Path.h" 39 #include "llvm/Support/SourceMgr.h" 40 #include "llvm/Support/TargetRegistry.h" 41 #include "llvm/Support/TargetSelect.h" 42 #include "llvm/Target/TargetLowering.h" 43 #include "llvm/Target/TargetLoweringObjectFile.h" 44 #include "llvm/Target/TargetRegisterInfo.h" 45 #include "llvm/Target/TargetSubtargetInfo.h" 46 #include "llvm/Transforms/Utils/GlobalStatus.h" 47 #include <system_error> 48 using namespace llvm; 49 using namespace llvm::object; 50 51 LTOModule::LTOModule(std::unique_ptr<object::IRObjectFile> Obj, 52 llvm::TargetMachine *TM) 53 : IRFile(std::move(Obj)), _target(TM) {} 54 55 LTOModule::LTOModule(std::unique_ptr<object::IRObjectFile> Obj, 56 llvm::TargetMachine *TM, 57 std::unique_ptr<LLVMContext> Context) 58 : OwnedContext(std::move(Context)), IRFile(std::move(Obj)), _target(TM) {} 59 60 LTOModule::~LTOModule() {} 61 62 /// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM 63 /// bitcode. 64 bool LTOModule::isBitcodeFile(const void *Mem, size_t Length) { 65 ErrorOr<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer( 66 MemoryBufferRef(StringRef((const char *)Mem, Length), "<mem>")); 67 return bool(BCData); 68 } 69 70 bool LTOModule::isBitcodeFile(const char *Path) { 71 ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr = 72 MemoryBuffer::getFile(Path); 73 if (!BufferOrErr) 74 return false; 75 76 ErrorOr<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer( 77 BufferOrErr.get()->getMemBufferRef()); 78 return bool(BCData); 79 } 80 81 bool LTOModule::isBitcodeForTarget(MemoryBuffer *Buffer, 82 StringRef TriplePrefix) { 83 ErrorOr<MemoryBufferRef> BCOrErr = 84 IRObjectFile::findBitcodeInMemBuffer(Buffer->getMemBufferRef()); 85 if (!BCOrErr) 86 return false; 87 LLVMContext Context; 88 std::string Triple = getBitcodeTargetTriple(*BCOrErr, Context); 89 return StringRef(Triple).startswith(TriplePrefix); 90 } 91 92 LTOModule *LTOModule::createFromFile(const char *path, TargetOptions options, 93 std::string &errMsg) { 94 ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr = 95 MemoryBuffer::getFile(path); 96 if (std::error_code EC = BufferOrErr.getError()) { 97 errMsg = EC.message(); 98 return nullptr; 99 } 100 std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrErr.get()); 101 return makeLTOModule(Buffer->getMemBufferRef(), options, errMsg, 102 &getGlobalContext()); 103 } 104 105 LTOModule *LTOModule::createFromOpenFile(int fd, const char *path, size_t size, 106 TargetOptions options, 107 std::string &errMsg) { 108 return createFromOpenFileSlice(fd, path, size, 0, options, errMsg); 109 } 110 111 LTOModule *LTOModule::createFromOpenFileSlice(int fd, const char *path, 112 size_t map_size, off_t offset, 113 TargetOptions options, 114 std::string &errMsg) { 115 ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr = 116 MemoryBuffer::getOpenFileSlice(fd, path, map_size, offset); 117 if (std::error_code EC = BufferOrErr.getError()) { 118 errMsg = EC.message(); 119 return nullptr; 120 } 121 std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrErr.get()); 122 return makeLTOModule(Buffer->getMemBufferRef(), options, errMsg, 123 &getGlobalContext()); 124 } 125 126 LTOModule *LTOModule::createFromBuffer(const void *mem, size_t length, 127 TargetOptions options, 128 std::string &errMsg, StringRef path) { 129 return createInContext(mem, length, options, errMsg, path, 130 &getGlobalContext()); 131 } 132 133 LTOModule *LTOModule::createInLocalContext(const void *mem, size_t length, 134 TargetOptions options, 135 std::string &errMsg, 136 StringRef path) { 137 return createInContext(mem, length, options, errMsg, path, nullptr); 138 } 139 140 LTOModule *LTOModule::createInContext(const void *mem, size_t length, 141 TargetOptions options, 142 std::string &errMsg, StringRef path, 143 LLVMContext *Context) { 144 StringRef Data((const char *)mem, length); 145 MemoryBufferRef Buffer(Data, path); 146 return makeLTOModule(Buffer, options, errMsg, Context); 147 } 148 149 LTOModule *LTOModule::makeLTOModule(MemoryBufferRef Buffer, 150 TargetOptions options, std::string &errMsg, 151 LLVMContext *Context) { 152 std::unique_ptr<LLVMContext> OwnedContext; 153 if (!Context) { 154 OwnedContext = llvm::make_unique<LLVMContext>(); 155 Context = OwnedContext.get(); 156 } 157 158 ErrorOr<MemoryBufferRef> MBOrErr = 159 IRObjectFile::findBitcodeInMemBuffer(Buffer); 160 if (std::error_code EC = MBOrErr.getError()) { 161 errMsg = EC.message(); 162 return nullptr; 163 } 164 ErrorOr<Module *> MOrErr = parseBitcodeFile(*MBOrErr, *Context); 165 if (std::error_code EC = MOrErr.getError()) { 166 errMsg = EC.message(); 167 return nullptr; 168 } 169 std::unique_ptr<Module> M(MOrErr.get()); 170 171 std::string TripleStr = M->getTargetTriple(); 172 if (TripleStr.empty()) 173 TripleStr = sys::getDefaultTargetTriple(); 174 llvm::Triple Triple(TripleStr); 175 176 // find machine architecture for this module 177 const Target *march = TargetRegistry::lookupTarget(TripleStr, errMsg); 178 if (!march) 179 return nullptr; 180 181 // construct LTOModule, hand over ownership of module and target 182 SubtargetFeatures Features; 183 Features.getDefaultSubtargetFeatures(Triple); 184 std::string FeatureStr = Features.getString(); 185 // Set a default CPU for Darwin triples. 186 std::string CPU; 187 if (Triple.isOSDarwin()) { 188 if (Triple.getArch() == llvm::Triple::x86_64) 189 CPU = "core2"; 190 else if (Triple.getArch() == llvm::Triple::x86) 191 CPU = "yonah"; 192 else if (Triple.getArch() == llvm::Triple::aarch64) 193 CPU = "cyclone"; 194 } 195 196 TargetMachine *target = march->createTargetMachine(TripleStr, CPU, FeatureStr, 197 options); 198 M->setDataLayout(target->getSubtargetImpl()->getDataLayout()); 199 200 std::unique_ptr<object::IRObjectFile> IRObj( 201 new object::IRObjectFile(Buffer, std::move(M))); 202 203 LTOModule *Ret; 204 if (OwnedContext) 205 Ret = new LTOModule(std::move(IRObj), target, std::move(OwnedContext)); 206 else 207 Ret = new LTOModule(std::move(IRObj), target); 208 209 if (Ret->parseSymbols(errMsg)) { 210 delete Ret; 211 return nullptr; 212 } 213 214 Ret->parseMetadata(); 215 216 return Ret; 217 } 218 219 /// Create a MemoryBuffer from a memory range with an optional name. 220 std::unique_ptr<MemoryBuffer> 221 LTOModule::makeBuffer(const void *mem, size_t length, StringRef name) { 222 const char *startPtr = (const char*)mem; 223 return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), name, false); 224 } 225 226 /// objcClassNameFromExpression - Get string that the data pointer points to. 227 bool 228 LTOModule::objcClassNameFromExpression(const Constant *c, std::string &name) { 229 if (const ConstantExpr *ce = dyn_cast<ConstantExpr>(c)) { 230 Constant *op = ce->getOperand(0); 231 if (GlobalVariable *gvn = dyn_cast<GlobalVariable>(op)) { 232 Constant *cn = gvn->getInitializer(); 233 if (ConstantDataArray *ca = dyn_cast<ConstantDataArray>(cn)) { 234 if (ca->isCString()) { 235 name = ".objc_class_name_" + ca->getAsCString().str(); 236 return true; 237 } 238 } 239 } 240 } 241 return false; 242 } 243 244 /// addObjCClass - Parse i386/ppc ObjC class data structure. 245 void LTOModule::addObjCClass(const GlobalVariable *clgv) { 246 const ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer()); 247 if (!c) return; 248 249 // second slot in __OBJC,__class is pointer to superclass name 250 std::string superclassName; 251 if (objcClassNameFromExpression(c->getOperand(1), superclassName)) { 252 auto IterBool = 253 _undefines.insert(std::make_pair(superclassName, NameAndAttributes())); 254 if (IterBool.second) { 255 NameAndAttributes &info = IterBool.first->second; 256 info.name = IterBool.first->first().data(); 257 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; 258 info.isFunction = false; 259 info.symbol = clgv; 260 } 261 } 262 263 // third slot in __OBJC,__class is pointer to class name 264 std::string className; 265 if (objcClassNameFromExpression(c->getOperand(2), className)) { 266 auto Iter = _defines.insert(className).first; 267 268 NameAndAttributes info; 269 info.name = Iter->first().data(); 270 info.attributes = LTO_SYMBOL_PERMISSIONS_DATA | 271 LTO_SYMBOL_DEFINITION_REGULAR | LTO_SYMBOL_SCOPE_DEFAULT; 272 info.isFunction = false; 273 info.symbol = clgv; 274 _symbols.push_back(info); 275 } 276 } 277 278 /// addObjCCategory - Parse i386/ppc ObjC category data structure. 279 void LTOModule::addObjCCategory(const GlobalVariable *clgv) { 280 const ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer()); 281 if (!c) return; 282 283 // second slot in __OBJC,__category is pointer to target class name 284 std::string targetclassName; 285 if (!objcClassNameFromExpression(c->getOperand(1), targetclassName)) 286 return; 287 288 auto IterBool = 289 _undefines.insert(std::make_pair(targetclassName, NameAndAttributes())); 290 291 if (!IterBool.second) 292 return; 293 294 NameAndAttributes &info = IterBool.first->second; 295 info.name = IterBool.first->first().data(); 296 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; 297 info.isFunction = false; 298 info.symbol = clgv; 299 } 300 301 /// addObjCClassRef - Parse i386/ppc ObjC class list data structure. 302 void LTOModule::addObjCClassRef(const GlobalVariable *clgv) { 303 std::string targetclassName; 304 if (!objcClassNameFromExpression(clgv->getInitializer(), targetclassName)) 305 return; 306 307 auto IterBool = 308 _undefines.insert(std::make_pair(targetclassName, NameAndAttributes())); 309 310 if (!IterBool.second) 311 return; 312 313 NameAndAttributes &info = IterBool.first->second; 314 info.name = IterBool.first->first().data(); 315 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; 316 info.isFunction = false; 317 info.symbol = clgv; 318 } 319 320 void LTOModule::addDefinedDataSymbol(const object::BasicSymbolRef &Sym) { 321 SmallString<64> Buffer; 322 { 323 raw_svector_ostream OS(Buffer); 324 Sym.printName(OS); 325 } 326 327 const GlobalValue *V = IRFile->getSymbolGV(Sym.getRawDataRefImpl()); 328 addDefinedDataSymbol(Buffer.c_str(), V); 329 } 330 331 void LTOModule::addDefinedDataSymbol(const char *Name, const GlobalValue *v) { 332 // Add to list of defined symbols. 333 addDefinedSymbol(Name, v, false); 334 335 if (!v->hasSection() /* || !isTargetDarwin */) 336 return; 337 338 // Special case i386/ppc ObjC data structures in magic sections: 339 // The issue is that the old ObjC object format did some strange 340 // contortions to avoid real linker symbols. For instance, the 341 // ObjC class data structure is allocated statically in the executable 342 // that defines that class. That data structures contains a pointer to 343 // its superclass. But instead of just initializing that part of the 344 // struct to the address of its superclass, and letting the static and 345 // dynamic linkers do the rest, the runtime works by having that field 346 // instead point to a C-string that is the name of the superclass. 347 // At runtime the objc initialization updates that pointer and sets 348 // it to point to the actual super class. As far as the linker 349 // knows it is just a pointer to a string. But then someone wanted the 350 // linker to issue errors at build time if the superclass was not found. 351 // So they figured out a way in mach-o object format to use an absolute 352 // symbols (.objc_class_name_Foo = 0) and a floating reference 353 // (.reference .objc_class_name_Bar) to cause the linker into erroring when 354 // a class was missing. 355 // The following synthesizes the implicit .objc_* symbols for the linker 356 // from the ObjC data structures generated by the front end. 357 358 // special case if this data blob is an ObjC class definition 359 std::string Section = v->getSection(); 360 if (Section.compare(0, 15, "__OBJC,__class,") == 0) { 361 if (const GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) { 362 addObjCClass(gv); 363 } 364 } 365 366 // special case if this data blob is an ObjC category definition 367 else if (Section.compare(0, 18, "__OBJC,__category,") == 0) { 368 if (const GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) { 369 addObjCCategory(gv); 370 } 371 } 372 373 // special case if this data blob is the list of referenced classes 374 else if (Section.compare(0, 18, "__OBJC,__cls_refs,") == 0) { 375 if (const GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) { 376 addObjCClassRef(gv); 377 } 378 } 379 } 380 381 void LTOModule::addDefinedFunctionSymbol(const object::BasicSymbolRef &Sym) { 382 SmallString<64> Buffer; 383 { 384 raw_svector_ostream OS(Buffer); 385 Sym.printName(OS); 386 } 387 388 const Function *F = 389 cast<Function>(IRFile->getSymbolGV(Sym.getRawDataRefImpl())); 390 addDefinedFunctionSymbol(Buffer.c_str(), F); 391 } 392 393 void LTOModule::addDefinedFunctionSymbol(const char *Name, const Function *F) { 394 // add to list of defined symbols 395 addDefinedSymbol(Name, F, true); 396 } 397 398 void LTOModule::addDefinedSymbol(const char *Name, const GlobalValue *def, 399 bool isFunction) { 400 // set alignment part log2() can have rounding errors 401 uint32_t align = def->getAlignment(); 402 uint32_t attr = align ? countTrailingZeros(align) : 0; 403 404 // set permissions part 405 if (isFunction) { 406 attr |= LTO_SYMBOL_PERMISSIONS_CODE; 407 } else { 408 const GlobalVariable *gv = dyn_cast<GlobalVariable>(def); 409 if (gv && gv->isConstant()) 410 attr |= LTO_SYMBOL_PERMISSIONS_RODATA; 411 else 412 attr |= LTO_SYMBOL_PERMISSIONS_DATA; 413 } 414 415 // set definition part 416 if (def->hasWeakLinkage() || def->hasLinkOnceLinkage()) 417 attr |= LTO_SYMBOL_DEFINITION_WEAK; 418 else if (def->hasCommonLinkage()) 419 attr |= LTO_SYMBOL_DEFINITION_TENTATIVE; 420 else 421 attr |= LTO_SYMBOL_DEFINITION_REGULAR; 422 423 // set scope part 424 if (def->hasLocalLinkage()) 425 // Ignore visibility if linkage is local. 426 attr |= LTO_SYMBOL_SCOPE_INTERNAL; 427 else if (def->hasHiddenVisibility()) 428 attr |= LTO_SYMBOL_SCOPE_HIDDEN; 429 else if (def->hasProtectedVisibility()) 430 attr |= LTO_SYMBOL_SCOPE_PROTECTED; 431 else if (canBeOmittedFromSymbolTable(def)) 432 attr |= LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN; 433 else 434 attr |= LTO_SYMBOL_SCOPE_DEFAULT; 435 436 auto Iter = _defines.insert(Name).first; 437 438 // fill information structure 439 NameAndAttributes info; 440 StringRef NameRef = Iter->first(); 441 info.name = NameRef.data(); 442 assert(info.name[NameRef.size()] == '\0'); 443 info.attributes = attr; 444 info.isFunction = isFunction; 445 info.symbol = def; 446 447 // add to table of symbols 448 _symbols.push_back(info); 449 } 450 451 /// addAsmGlobalSymbol - Add a global symbol from module-level ASM to the 452 /// defined list. 453 void LTOModule::addAsmGlobalSymbol(const char *name, 454 lto_symbol_attributes scope) { 455 auto IterBool = _defines.insert(name); 456 457 // only add new define if not already defined 458 if (!IterBool.second) 459 return; 460 461 NameAndAttributes &info = _undefines[IterBool.first->first().data()]; 462 463 if (info.symbol == nullptr) { 464 // FIXME: This is trying to take care of module ASM like this: 465 // 466 // module asm ".zerofill __FOO, __foo, _bar_baz_qux, 0" 467 // 468 // but is gross and its mother dresses it funny. Have the ASM parser give us 469 // more details for this type of situation so that we're not guessing so 470 // much. 471 472 // fill information structure 473 info.name = IterBool.first->first().data(); 474 info.attributes = 475 LTO_SYMBOL_PERMISSIONS_DATA | LTO_SYMBOL_DEFINITION_REGULAR | scope; 476 info.isFunction = false; 477 info.symbol = nullptr; 478 479 // add to table of symbols 480 _symbols.push_back(info); 481 return; 482 } 483 484 if (info.isFunction) 485 addDefinedFunctionSymbol(info.name, cast<Function>(info.symbol)); 486 else 487 addDefinedDataSymbol(info.name, info.symbol); 488 489 _symbols.back().attributes &= ~LTO_SYMBOL_SCOPE_MASK; 490 _symbols.back().attributes |= scope; 491 } 492 493 /// addAsmGlobalSymbolUndef - Add a global symbol from module-level ASM to the 494 /// undefined list. 495 void LTOModule::addAsmGlobalSymbolUndef(const char *name) { 496 auto IterBool = _undefines.insert(std::make_pair(name, NameAndAttributes())); 497 498 _asm_undefines.push_back(IterBool.first->first().data()); 499 500 // we already have the symbol 501 if (!IterBool.second) 502 return; 503 504 uint32_t attr = LTO_SYMBOL_DEFINITION_UNDEFINED; 505 attr |= LTO_SYMBOL_SCOPE_DEFAULT; 506 NameAndAttributes &info = IterBool.first->second; 507 info.name = IterBool.first->first().data(); 508 info.attributes = attr; 509 info.isFunction = false; 510 info.symbol = nullptr; 511 } 512 513 /// Add a symbol which isn't defined just yet to a list to be resolved later. 514 void LTOModule::addPotentialUndefinedSymbol(const object::BasicSymbolRef &Sym, 515 bool isFunc) { 516 SmallString<64> name; 517 { 518 raw_svector_ostream OS(name); 519 Sym.printName(OS); 520 } 521 522 auto IterBool = _undefines.insert(std::make_pair(name, NameAndAttributes())); 523 524 // we already have the symbol 525 if (!IterBool.second) 526 return; 527 528 NameAndAttributes &info = IterBool.first->second; 529 530 info.name = IterBool.first->first().data(); 531 532 const GlobalValue *decl = IRFile->getSymbolGV(Sym.getRawDataRefImpl()); 533 534 if (decl->hasExternalWeakLinkage()) 535 info.attributes = LTO_SYMBOL_DEFINITION_WEAKUNDEF; 536 else 537 info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; 538 539 info.isFunction = isFunc; 540 info.symbol = decl; 541 } 542 543 /// parseSymbols - Parse the symbols from the module and model-level ASM and add 544 /// them to either the defined or undefined lists. 545 bool LTOModule::parseSymbols(std::string &errMsg) { 546 for (auto &Sym : IRFile->symbols()) { 547 const GlobalValue *GV = IRFile->getSymbolGV(Sym.getRawDataRefImpl()); 548 uint32_t Flags = Sym.getFlags(); 549 if (Flags & object::BasicSymbolRef::SF_FormatSpecific) 550 continue; 551 552 bool IsUndefined = Flags & object::BasicSymbolRef::SF_Undefined; 553 554 if (!GV) { 555 SmallString<64> Buffer; 556 { 557 raw_svector_ostream OS(Buffer); 558 Sym.printName(OS); 559 } 560 const char *Name = Buffer.c_str(); 561 562 if (IsUndefined) 563 addAsmGlobalSymbolUndef(Name); 564 else if (Flags & object::BasicSymbolRef::SF_Global) 565 addAsmGlobalSymbol(Name, LTO_SYMBOL_SCOPE_DEFAULT); 566 else 567 addAsmGlobalSymbol(Name, LTO_SYMBOL_SCOPE_INTERNAL); 568 continue; 569 } 570 571 auto *F = dyn_cast<Function>(GV); 572 if (IsUndefined) { 573 addPotentialUndefinedSymbol(Sym, F != nullptr); 574 continue; 575 } 576 577 if (F) { 578 addDefinedFunctionSymbol(Sym); 579 continue; 580 } 581 582 if (isa<GlobalVariable>(GV)) { 583 addDefinedDataSymbol(Sym); 584 continue; 585 } 586 587 assert(isa<GlobalAlias>(GV)); 588 addDefinedDataSymbol(Sym); 589 } 590 591 // make symbols for all undefines 592 for (StringMap<NameAndAttributes>::iterator u =_undefines.begin(), 593 e = _undefines.end(); u != e; ++u) { 594 // If this symbol also has a definition, then don't make an undefine because 595 // it is a tentative definition. 596 if (_defines.count(u->getKey())) continue; 597 NameAndAttributes info = u->getValue(); 598 _symbols.push_back(info); 599 } 600 601 return false; 602 } 603 604 /// parseMetadata - Parse metadata from the module 605 void LTOModule::parseMetadata() { 606 // Linker Options 607 if (Metadata *Val = getModule().getModuleFlag("Linker Options")) { 608 MDNode *LinkerOptions = cast<MDNode>(Val); 609 for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) { 610 MDNode *MDOptions = cast<MDNode>(LinkerOptions->getOperand(i)); 611 for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) { 612 MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii)); 613 // FIXME: Make StringSet::insert match Self-Associative Container 614 // requirements, returning <iter,bool> rather than bool, and use that 615 // here. 616 StringRef Op = 617 _linkeropt_strings.insert(MDOption->getString()).first->first(); 618 StringRef DepLibName = _target->getSubtargetImpl() 619 ->getTargetLowering() 620 ->getObjFileLowering() 621 .getDepLibFromLinkerOpt(Op); 622 if (!DepLibName.empty()) 623 _deplibs.push_back(DepLibName.data()); 624 else if (!Op.empty()) 625 _linkeropts.push_back(Op.data()); 626 } 627 } 628 } 629 630 // Add other interesting metadata here. 631 } 632