[PATCH] MC: Support larger COFF string tables
Nico Rieck
nico.rieck at gmail.com
Sun Jul 28 14:59:09 PDT 2013
Clarified constants. Dropped base64 encoding.
Hi LegalizeAdulthood, asl, Bigcheese,
http://llvm-reviews.chandlerc.com/D667
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D667?vs=1835&id=3047#toc
Files:
lib/MC/WinCOFFObjectWriter.cpp
test/MC/COFF/section-name-encoding.s
Index: lib/MC/WinCOFFObjectWriter.cpp
===================================================================
--- lib/MC/WinCOFFObjectWriter.cpp
+++ lib/MC/WinCOFFObjectWriter.cpp
@@ -475,18 +475,21 @@
/// name into the string table if needed
void WinCOFFObjectWriter::MakeSectionReal(COFFSection &S, size_t Number) {
if (S.Name.size() > COFF::NameSize) {
- size_t StringTableEntry = Strings.insert(S.Name.c_str());
-
- // FIXME: Why is this number 999999? This number is never mentioned in the
- // spec. I'm assuming this is due to the printed value needing to fit into
- // the S.Header.Name field. In which case why not 9999999 (7 9's instead of
- // 6)? The spec does not state if this entry should be null terminated in
- // this case, and thus this seems to be the best way to do it. I think I
- // just solved my own FIXME...
- if (StringTableEntry > 999999)
- report_fatal_error("COFF string table is greater than 999999 bytes.");
-
- std::sprintf(S.Header.Name, "/%d", unsigned(StringTableEntry));
+ const unsigned Max6DecimalSize = 999999;
+ const unsigned Max7DecimalSize = 9999999;
+ uint64_t StringTableEntry = Strings.insert(S.Name.c_str());
+
+ if (StringTableEntry <= Max6DecimalSize) {
+ std::sprintf(S.Header.Name, "/%d", unsigned(StringTableEntry));
+ } else if (StringTableEntry <= Max7DecimalSize) {
+ // 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 {
+ report_fatal_error("COFF string table is greater than 9,999,999 bytes.");
+ }
} else
std::memcpy(S.Header.Name, S.Name.c_str(), S.Name.size());
Index: test/MC/COFF/section-name-encoding.s
===================================================================
--- /dev/null
+++ test/MC/COFF/section-name-encoding.s
@@ -0,0 +1,30 @@
+// Check that COFF section names are properly encoded.
+//
+// Encodings for different lengths:
+// [0, 8]: raw name
+// (8, 999999]: base 10 string table index (/9999999)
+//
+// RUN: llvm-mc -triple x86_64-pc-win32 -filetype=obj %s | llvm-readobj -s | FileCheck %s
+
+// Raw encoding
+.section s; f1: ret
+.section s1234567; f2: ret
+
+// CHECK: Section {
+// CHECK: Number: 1
+// CHECK: Name: s (73 00 00 00 00 00 00 00)
+// CHECK: }
+// CHECK: Section {
+// CHECK: Number: 2
+// CHECK: Name: s1234567 (73 31 32 33 34 35 36 37)
+// CHECK: }
+
+
+// Base 10 encoding
+.section s12345678; f3: ret
+
+// /4
+// CHECK: Section {
+// CHECK: Number: 3
+// CHECK: Name: s12345678 (2F 34 00 00 00 00 00 00)
+// CHECK: }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D667.4.patch
Type: text/x-patch
Size: 2810 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130728/cf54c405/attachment.bin>
More information about the llvm-commits
mailing list