diff --git a/lld/MachO/ConcatOutputSection.cpp b/lld/MachO/ConcatOutputSection.cpp --- a/lld/MachO/ConcatOutputSection.cpp +++ b/lld/MachO/ConcatOutputSection.cpp @@ -186,10 +186,10 @@ log("thunks = " + std::to_string(thunkMap.size()) + ", potential = " + std::to_string(maxPotentialThunks) + ", stubs = " + std::to_string(in.stubs->getSize()) + ", isecVA = " + - to_hexString(isecVA) + ", threshold = " + to_hexString(stubsInRangeVA) + - ", isecEnd = " + to_hexString(isecEnd) + - ", tail = " + to_hexString(isecEnd - isecVA) + - ", slop = " + to_hexString(forwardBranchRange - (isecEnd - isecVA))); + utohexstr(isecVA) + ", threshold = " + utohexstr(stubsInRangeVA) + + ", isecEnd = " + utohexstr(isecEnd) + + ", tail = " + utohexstr(isecEnd - isecVA) + + ", slop = " + utohexstr(forwardBranchRange - (isecEnd - isecVA))); return stubsInRangeVA; } diff --git a/llvm/include/llvm/Support/ScopedPrinter.h b/llvm/include/llvm/Support/ScopedPrinter.h --- a/llvm/include/llvm/Support/ScopedPrinter.h +++ b/llvm/include/llvm/Support/ScopedPrinter.h @@ -81,7 +81,6 @@ }; raw_ostream &operator<<(raw_ostream &OS, const HexNumber &Value); -std::string to_hexString(uint64_t Value, bool UpperCase = true); template std::string to_string(const T &Value) { std::string number; @@ -95,7 +94,7 @@ for (const EnumEntry &EnumItem : EnumValues) if (EnumItem.Value == Value) return std::string(EnumItem.AltName); - return to_hexString(Value, false); + return utohexstr(Value, true); } class ScopedPrinter { diff --git a/llvm/lib/Support/ScopedPrinter.cpp b/llvm/lib/Support/ScopedPrinter.cpp --- a/llvm/lib/Support/ScopedPrinter.cpp +++ b/llvm/lib/Support/ScopedPrinter.cpp @@ -7,17 +7,10 @@ namespace llvm { raw_ostream &operator<<(raw_ostream &OS, const HexNumber &Value) { - OS << "0x" << to_hexString(Value.Value); + OS << "0x" << utohexstr(Value.Value); return OS; } -std::string to_hexString(uint64_t Value, bool UpperCase) { - std::string number; - llvm::raw_string_ostream stream(number); - stream << format_hex_no_prefix(Value, 1, UpperCase); - return stream.str(); -} - void ScopedPrinter::printBinaryImpl(StringRef Label, StringRef Str, ArrayRef Data, bool Block, uint32_t StartOffset) { diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp @@ -149,7 +149,7 @@ if (FixupOffset & 0xff000000) { Asm.getContext().reportError(Fixup.getLoc(), "can not encode offset '0x" + - to_hexString(FixupOffset) + + utohexstr(FixupOffset) + "' in resulting scattered relocation."); return; } @@ -264,7 +264,7 @@ if (FixupOffset & 0xff000000) { Asm.getContext().reportError(Fixup.getLoc(), "can not encode offset '0x" + - to_hexString(FixupOffset) + + utohexstr(FixupOffset) + "' in resulting scattered relocation."); return; } diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp --- a/llvm/tools/llvm-profgen/PerfReader.cpp +++ b/llvm/tools/llvm-profgen/PerfReader.cpp @@ -467,9 +467,9 @@ if (OContextStr.str().size()) OContextStr << " @ "; OContextStr << "0x" - << to_hexString( + << utohexstr( Binary->virtualAddrToOffset(CtxKey->Context[I]), - false); + true); } return OContextStr.str(); } else { diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -3309,7 +3309,7 @@ OS.PadToColumn(2u); OS << "Version:"; OS.PadToColumn(37u); - OS << to_hexString(e.e_ident[ELF::EI_VERSION]); + OS << utohexstr(e.e_ident[ELF::EI_VERSION]); if (e.e_version == ELF::EV_CURRENT) OS << " (current)"; OS << "\n"; @@ -3322,19 +3322,19 @@ Str = E->AltName.str(); } else { if (e.e_type >= ET_LOPROC) - Str = "Processor Specific: (" + to_hexString(e.e_type, false) + ")"; + Str = "Processor Specific: (" + utohexstr(e.e_type, true) + ")"; else if (e.e_type >= ET_LOOS) - Str = "OS Specific: (" + to_hexString(e.e_type, false) + ")"; + Str = "OS Specific: (" + utohexstr(e.e_type, true) + ")"; else - Str = ": " + to_hexString(e.e_type, false); + Str = ": " + utohexstr(e.e_type, true); } printFields(OS, "Type:", Str); Str = enumToString(e.e_machine, makeArrayRef(ElfMachineType)); printFields(OS, "Machine:", Str); - Str = "0x" + to_hexString(e.e_version); + Str = "0x" + utohexstr(e.e_version); printFields(OS, "Version:", Str); - Str = "0x" + to_hexString(e.e_entry); + Str = "0x" + utohexstr(e.e_entry); printFields(OS, "Entry point address:", Str); Str = to_string(e.e_phoff) + " (bytes into file)"; printFields(OS, "Start of program headers:", Str); @@ -3351,7 +3351,7 @@ else if (e.e_machine == EM_AVR) ElfFlags = printFlags(e.e_flags, makeArrayRef(ElfHeaderAVRFlags), unsigned(ELF::EF_AVR_ARCH_MASK)); - Str = "0x" + to_hexString(e.e_flags); + Str = "0x" + utohexstr(e.e_flags); if (!ElfFlags.empty()) Str = Str + ", " + ElfFlags; printFields(OS, "Flags:", Str); @@ -3529,7 +3529,7 @@ Addend = " + "; } } - Addend += to_hexString(RelAddend, false); + Addend += utohexstr(RelAddend, true); } OS << Addend << "\n"; } @@ -3561,7 +3561,7 @@ const DynRegionInfo &Reg) { uint64_t Offset = Reg.Addr - this->Obj.base(); OS << "\n'" << Name.str().c_str() << "' relocation section at offset 0x" - << to_hexString(Offset, false) << " contains " << Reg.Size << " bytes:\n"; + << utohexstr(Offset, true) << " contains " << Reg.Size << " bytes:\n"; printRelocHeaderFields(OS, Type); } @@ -3614,7 +3614,7 @@ uintX_t Offset = Sec.sh_offset; StringRef Name = this->getPrintableSectionName(Sec); OS << "\nRelocation section '" << Name << "' at offset 0x" - << to_hexString(Offset, false) << " contains " << EntriesNum + << utohexstr(Offset, true) << " contains " << EntriesNum << " entries:\n"; printRelocHeaderFields(OS, Sec.sh_type); this->printRelocationsHelper(Sec); @@ -3629,12 +3629,12 @@ // returned as '' followed by the type value. static std::string getSectionTypeOffsetString(unsigned Type) { if (Type >= SHT_LOOS && Type <= SHT_HIOS) - return "LOOS+0x" + to_hexString(Type - SHT_LOOS); + return "LOOS+0x" + utohexstr(Type - SHT_LOOS); else if (Type >= SHT_LOPROC && Type <= SHT_HIPROC) - return "LOPROC+0x" + to_hexString(Type - SHT_LOPROC); + return "LOPROC+0x" + utohexstr(Type - SHT_LOPROC); else if (Type >= SHT_LOUSER && Type <= SHT_HIUSER) - return "LOUSER+0x" + to_hexString(Type - SHT_LOUSER); - return "0x" + to_hexString(Type) + ": "; + return "LOUSER+0x" + utohexstr(Type - SHT_LOUSER); + return "0x" + utohexstr(Type) + ": "; } static std::string getSectionTypeString(unsigned Machine, unsigned Type) { @@ -3679,7 +3679,7 @@ ArrayRef Sections = cantFail(this->Obj.sections()); OS << "There are " << to_string(Sections.size()) << " section headers, starting at offset " - << "0x" << to_hexString(this->Obj.getHeader().e_shoff, false) << ":\n\n"; + << "0x" << utohexstr(this->Obj.getHeader().e_shoff, true) << ":\n\n"; OS << "Section Headers:\n"; Field Fields[11] = { {"[Nr]", 2}, {"Name", 7}, {"Type", 25}, @@ -3837,7 +3837,7 @@ Other &= ~STO_AARCH64_VARIANT_PCS; Fields[5].Str += " [VARIANT_PCS"; if (Other != 0) - Fields[5].Str.append(" | " + to_hexString(Other, false)); + Fields[5].Str.append(" | " + utohexstr(Other, true)); Fields[5].Str.append("]"); } } else if (this->Obj.getHeader().e_machine == ELF::EM_RISCV) { @@ -3846,7 +3846,7 @@ Other &= ~STO_RISCV_VARIANT_CC; Fields[5].Str += " [VARIANT_CC"; if (Other != 0) - Fields[5].Str.append(" | " + to_hexString(Other, false)); + Fields[5].Str.append(" | " + utohexstr(Other, true)); Fields[5].Str.append("]"); } } else { @@ -4058,7 +4058,7 @@ ArrayRef Sections = cantFail(this->Obj.sections()); OS << "There are " << to_string(Sections.size()) << " section headers, starting at offset " - << "0x" << to_hexString(this->Obj.getHeader().e_shoff, false) << ":\n\n"; + << "0x" << utohexstr(this->Obj.getHeader().e_shoff, true) << ":\n\n"; OS << "Section Headers:\n"; @@ -6464,7 +6464,7 @@ else TypeStr = "Unknown"; } - W.printString("Type", TypeStr + " (0x" + to_hexString(E.e_type) + ")"); + W.printString("Type", TypeStr + " (0x" + utohexstr(E.e_type) + ")"); W.printEnum("Machine", E.e_machine, makeArrayRef(ElfMachineType)); W.printNumber("Version", E.e_version);