diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -2311,10 +2311,10 @@ } if (!IsAArch64 && BC->getDynamicRelocationAt(Rel.getOffset())) { - LLVM_DEBUG( - dbgs() << "BOLT-DEBUG: address 0x" << Twine::utohexstr(Rel.getOffset()) - << " has a dynamic relocation against it. Ignoring static " - "relocation.\n"); + LLVM_DEBUG({ + dbgs() << formatv("BOLT-DEBUG: address {0:x} has a ", Rel.getOffset()) + << "dynamic relocation against it. Ignoring static relocation.\n"; + }); return; } @@ -2326,17 +2326,19 @@ bool Skip; if (!analyzeRelocation(Rel, RType, SymbolName, IsSectionRelocation, SymbolAddress, Addend, ExtractedValue, Skip)) { - LLVM_DEBUG(dbgs() << "BOLT-WARNING: failed to analyze relocation @ " - << "offset = 0x" << Twine::utohexstr(Rel.getOffset()) - << "; type name = " << TypeName << '\n'); + LLVM_DEBUG({ + dbgs() << "BOLT-WARNING: failed to analyze relocation @ offset = " + << formatv("{0:x}; type name = {1}\n", Rel.getOffset(), TypeName); + }); ++NumFailedRelocations; return; } if (Skip) { - LLVM_DEBUG(dbgs() << "BOLT-DEBUG: skipping relocation @ offset = 0x" - << Twine::utohexstr(Rel.getOffset()) - << "; type name = " << TypeName << '\n'); + LLVM_DEBUG({ + dbgs() << "BOLT-DEBUG: skipping relocation @ offset = " + << formatv("{0:x}; type name = {1}\n", Rel.getOffset(), TypeName); + }); return; } @@ -2356,8 +2358,8 @@ assert(ContainingBF && "cannot find function for address in code"); if (!IsAArch64 && !ContainingBF->containsAddress(Rel.getOffset())) { if (opts::Verbosity >= 1) - outs() << "BOLT-INFO: " << *ContainingBF - << " has relocations in padding area\n"; + outs() << formatv("BOLT-INFO: {0} has relocations in padding area\n", + *ContainingBF); ContainingBF->setSize(ContainingBF->getMaxSize()); ContainingBF->setSimple(false); return; @@ -2398,10 +2400,10 @@ ContainingBF->addRelocation(Rel.getOffset(), ReferencedSymbol, RType, Addend, ExtractedValue); } else { - LLVM_DEBUG( - dbgs() << "BOLT-DEBUG: not creating PC-relative relocation at 0x" - << Twine::utohexstr(Rel.getOffset()) << " for " << SymbolName - << "\n"); + LLVM_DEBUG({ + dbgs() << "BOLT-DEBUG: not creating PC-relative relocation at" + << formatv("{0:x} for {1}\n", Rel.getOffset(), SymbolName); + }); } return; @@ -2427,14 +2429,12 @@ if (BF != ReferencedBF) { // It's possible we are referencing a function without referencing any // code, e.g. when taking a bitmask action on a function address. - errs() << "BOLT-WARNING: non-standard function reference (e.g. " - "bitmask) detected against function " - << *BF; + errs() << "BOLT-WARNING: non-standard function reference (e.g. bitmask)" + << formatv(" detected against function {0} from ", *BF); if (IsFromCode) - errs() << " from function " << *ContainingBF << '\n'; + errs() << formatv("function {0}\n", *ContainingBF); else - errs() << " from data section at 0x" - << Twine::utohexstr(Rel.getOffset()) << '\n'; + errs() << formatv("data section at {0:x}\n", Rel.getOffset()); LLVM_DEBUG(printRelocationInfo(Rel, SymbolName, SymbolAddress, Addend, ExtractedValue)); ReferencedBF = BF; @@ -2467,10 +2467,10 @@ } if (Found) { - errs() << "BOLT-WARNING: detected possible compiler " - "de-virtualization bug: -1 addend used with " - "non-pc-relative relocation against function " - << *RogueBF << " in function " << *ContainingBF << '\n'; + errs() << "BOLT-WARNING: detected possible compiler de-virtualization " + "bug: -1 addend used with non-pc-relative relocation against " + << formatv("function {0} in function {1}\n", *RogueBF, + *ContainingBF); return; } } @@ -2503,10 +2503,9 @@ } if (opts::Verbosity > 1 && !BinarySection(*BC, RelocatedSection).isReadOnly()) - errs() << "BOLT-WARNING: writable reference into the middle of " - << "the function " << *ReferencedBF - << " detected at address 0x" - << Twine::utohexstr(Rel.getOffset()) << '\n'; + errs() << "BOLT-WARNING: writable reference into the middle of the " + << formatv("function {0} detected at address {1:x}\n", + *ReferencedBF, Rel.getOffset()); } SymbolAddress = Address; Addend = 0; @@ -2514,7 +2513,7 @@ LLVM_DEBUG({ dbgs() << " referenced function " << *ReferencedBF; if (Address != ReferencedBF->getAddress()) - dbgs() << " at offset 0x" << Twine::utohexstr(RefFunctionOffset); + dbgs() << formatv(" at offset {0:x}", RefFunctionOffset); dbgs() << '\n'; }); } else { @@ -2529,7 +2528,7 @@ // section symbol. If we are here, this means we are probably accessing // data, so it is imperative to keep the original address. if (IsAArch64) { - SymbolName = ("SYMBOLat0x" + Twine::utohexstr(Address)).str(); + SymbolName = formatv("SYMBOLat{0:x}", Address); SymbolAddress = Address; Addend = 0; } @@ -2547,8 +2546,8 @@ (BD->nameStartsWith("ANONYMOUS") && (BD->getSectionName().startswith(".plt") || BD->getSectionName().endswith(".plt")))) && - "BOLT symbol names of all non-section relocations must match " - "up with symbol names referenced in the relocation"); + "BOLT symbol names of all non-section relocations must match up " + "with symbol names referenced in the relocation"); if (IsSectionRelocation) BC->markAmbiguousRelocations(*BD, Address); @@ -2578,8 +2577,8 @@ if (SymbolFlags & SymbolRef::SF_Global) { Name = SymbolName; } else { - if (StringRef(SymbolName) - .startswith(BC->AsmInfo->getPrivateGlobalPrefix())) + StringRef PGPrefix(BC->AsmInfo->getPrivateGlobalPrefix()); + if (StringRef(SymbolName).startswith(PGPrefix)) Name = NR.uniquify("PG" + SymbolName); else Name = NR.uniquify(SymbolName); @@ -2599,8 +2598,10 @@ ++NumDataRelocations; if (opts::MaxDataRelocations && NumDataRelocations + 1 == opts::MaxDataRelocations) { - LLVM_DEBUG(dbgs() << "BOLT-DEBUG: processing ending on data relocation " - << NumDataRelocations << ": "); + LLVM_DEBUG({ + dbgs() << "BOLT-DEBUG: processing ending on data relocation " + << NumDataRelocations << ": "; + }); printRelocationInfo(Rel, ReferencedSymbol->getName(), SymbolAddress, Addend, ExtractedValue); }