From 6c35c95c737f2930b7089257f31cb996ae7e7c0d Mon Sep 17 00:00:00 2001 From: Nico Rieck Date: Tue, 25 Feb 2014 09:50:40 +0000 Subject: Reuse constants for COFF string table entry offsets git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202130 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/WinCOFFObjectWriter.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/MC/WinCOFFObjectWriter.cpp b/lib/MC/WinCOFFObjectWriter.cpp index 12f3fdf011..381fe0ee03 100644 --- a/lib/MC/WinCOFFObjectWriter.cpp +++ b/lib/MC/WinCOFFObjectWriter.cpp @@ -468,11 +468,16 @@ void WinCOFFObjectWriter::DefineSymbol(MCSymbolData const &SymbolData, } } +// Maximum offsets for different string table entry encodings. +static const unsigned Max6DecimalOffset = 999999; +static const unsigned Max7DecimalOffset = 9999999; +static const uint64_t MaxBase64Offset = 0xFFFFFFFFFULL; // 64^6, including 0 + // Encode a string table entry offset in base 64, padded to 6 chars, and // prefixed with a double slash: '//AAAAAA', '//AAAAAB', ... // Buffer must be at least 8 bytes large. No terminating null appended. static void encodeBase64StringEntry(char* Buffer, uint64_t Value) { - assert(Value > 9999999 && Value <= 0xFFFFFFFFF && + assert(Value > Max7DecimalOffset && Value <= MaxBase64Offset && "Illegal section name encoding for value"); static const char Alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -494,20 +499,17 @@ static void encodeBase64StringEntry(char* Buffer, uint64_t Value) { /// name into the string table if needed void WinCOFFObjectWriter::MakeSectionReal(COFFSection &S, size_t Number) { if (S.Name.size() > COFF::NameSize) { - const unsigned Max6DecimalSize = 999999; - const unsigned Max7DecimalSize = 9999999; - const uint64_t MaxBase64Size = 0xFFFFFFFFF; // 64^6, including 0 uint64_t StringTableEntry = Strings.insert(S.Name.c_str()); - if (StringTableEntry <= Max6DecimalSize) { + if (StringTableEntry <= Max6DecimalOffset) { std::sprintf(S.Header.Name, "/%d", unsigned(StringTableEntry)); - } else if (StringTableEntry <= Max7DecimalSize) { + } else if (StringTableEntry <= Max7DecimalOffset) { // With seven digits, we have to skip the terminating null. Because // sprintf always appends it, we use a larger temporary buffer. char buffer[9] = { }; std::sprintf(buffer, "/%d", unsigned(StringTableEntry)); std::memcpy(S.Header.Name, buffer, 8); - } else if (StringTableEntry <= MaxBase64Size) { + } else if (StringTableEntry <= MaxBase64Offset) { // Starting with 10,000,000, offsets are encoded as base64. encodeBase64StringEntry(S.Header.Name, StringTableEntry); } else { -- cgit v1.2.3