summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-01-24 20:46:11 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-01-24 20:46:11 +0000
commitf088f52a1fccdeb120c4d8f47e9956ddb8c85cbf (patch)
tree9d7d35791ff8d745f8bcebce359a29a0597df4a3 /llvm/lib
parentc67668ff21e3e8b6098668bc1f696a9f2cec6631 (diff)
downloadbcm5719-llvm-f088f52a1fccdeb120c4d8f47e9956ddb8c85cbf.tar.gz
bcm5719-llvm-f088f52a1fccdeb120c4d8f47e9956ddb8c85cbf.zip
[COFF] Simplify SetSectionName
Consolidate the code which handles string table offsets less than 999999 with the code for offsets less than 9999999. While we are here, simplify the code by not using sprintf to generate the string. llvm-svn: 258664
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/MC/WinCOFFObjectWriter.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp
index 36b317eebb9..825e488755b 100644
--- a/llvm/lib/MC/WinCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp
@@ -426,9 +426,8 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &Symbol,
}
// 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
+enum : unsigned { Max7DecimalOffset = 9999999U };
+enum : 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', ...
@@ -456,22 +455,21 @@ void WinCOFFObjectWriter::SetSectionName(COFFSection &S) {
if (S.Name.size() > COFF::NameSize) {
uint64_t StringTableEntry = Strings.getOffset(S.Name);
- if (StringTableEntry <= Max6DecimalOffset) {
- std::sprintf(S.Header.Name, "/%d", unsigned(StringTableEntry));
- } 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);
+ if (StringTableEntry <= Max7DecimalOffset) {
+ SmallVector<char, COFF::NameSize> Buffer;
+ Twine('/').concat(Twine(StringTableEntry)).toVector(Buffer);
+ assert(Buffer.size() <= COFF::NameSize && Buffer.size() >= 2);
+
+ std::memcpy(S.Header.Name, Buffer.data(), Buffer.size());
} else if (StringTableEntry <= MaxBase64Offset) {
// Starting with 10,000,000, offsets are encoded as base64.
encodeBase64StringEntry(S.Header.Name, StringTableEntry);
} else {
report_fatal_error("COFF string table is greater than 64 GB.");
}
- } else
+ } else {
std::memcpy(S.Header.Name, S.Name.c_str(), S.Name.size());
+ }
}
void WinCOFFObjectWriter::SetSymbolName(COFFSymbol &S) {
OpenPOWER on IntegriCloud