diff options
| author | Nico Rieck <nico.rieck@gmail.com> | 2014-02-25 09:50:40 +0000 |
|---|---|---|
| committer | Nico Rieck <nico.rieck@gmail.com> | 2014-02-25 09:50:40 +0000 |
| commit | 01143f9a517ff0be74594286601f2d4a2a514c36 (patch) | |
| tree | 58b5d3d7a6039696322dce8fb75b39a84ff45555 | |
| parent | a8c4cc68f5f5f5b1b2dfa86e572623fc45bf6404 (diff) | |
| download | bcm5719-llvm-01143f9a517ff0be74594286601f2d4a2a514c36.tar.gz bcm5719-llvm-01143f9a517ff0be74594286601f2d4a2a514c36.zip | |
Reuse constants for COFF string table entry offsets
llvm-svn: 202130
| -rw-r--r-- | llvm/lib/MC/WinCOFFObjectWriter.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp index 12f3fdf0111..381fe0ee03c 100644 --- a/llvm/lib/MC/WinCOFFObjectWriter.cpp +++ b/llvm/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 { |

