[PATCH] D105522: [llvm-readobj][XCOFF] Fix the error dumping for the first item of StringTable.
Esme Yi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 12 00:48:09 PDT 2021
Esme updated this revision to Diff 357855.
Esme added a comment.
Herald added a subscriber: hiraditya.
Addressed comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D105522/new/
https://reviews.llvm.org/D105522
Files:
llvm/lib/Object/XCOFFObjectFile.cpp
llvm/test/tools/yaml2obj/XCOFF/long-symbol-name.yaml
llvm/tools/llvm-readobj/ObjDumper.cpp
llvm/tools/llvm-readobj/ObjDumper.h
llvm/tools/llvm-readobj/XCOFFDumper.cpp
Index: llvm/tools/llvm-readobj/XCOFFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/XCOFFDumper.cpp
+++ llvm/tools/llvm-readobj/XCOFFDumper.cpp
@@ -460,7 +460,9 @@
void XCOFFDumper::printStringTable() {
DictScope DS(W, "StringTable");
StringRef StrTable = Obj.getStringTable();
- printAsStringList(StrTable);
+ // Print strings from byte 4, since the first three bytes contain the length
+ // (in bytes) of the string table (including the length field).
+ printAsStringList(StrTable, 4);
}
void XCOFFDumper::printDynamicSymbols() {
Index: llvm/tools/llvm-readobj/ObjDumper.h
===================================================================
--- llvm/tools/llvm-readobj/ObjDumper.h
+++ llvm/tools/llvm-readobj/ObjDumper.h
@@ -110,7 +110,7 @@
virtual void printStackMap() const = 0;
- void printAsStringList(StringRef StringContent);
+ void printAsStringList(StringRef StringContent, size_t StringDataOffset = 0);
void printSectionsAsString(const object::ObjectFile &Obj,
ArrayRef<std::string> Sections);
Index: llvm/tools/llvm-readobj/ObjDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/ObjDumper.cpp
+++ llvm/tools/llvm-readobj/ObjDumper.cpp
@@ -53,9 +53,13 @@
W << (isPrint(Start[i]) ? static_cast<char>(Start[i]) : '.');
}
-void ObjDumper::printAsStringList(StringRef StringContent) {
+void ObjDumper::printAsStringList(StringRef StringContent,
+ size_t StringDataOffset) {
const uint8_t *StrContent = StringContent.bytes_begin();
- const uint8_t *CurrentWord = StrContent;
+ // Some formats contain additional metadata at the start which should not be
+ // interpreted as strings. Skip these bytes, but account for them in the
+ // string offsets.
+ const uint8_t *CurrentWord = StrContent + StringDataOffset;
const uint8_t *StrEnd = StringContent.bytes_end();
while (CurrentWord <= StrEnd) {
Index: llvm/test/tools/yaml2obj/XCOFF/long-symbol-name.yaml
===================================================================
--- llvm/test/tools/yaml2obj/XCOFF/long-symbol-name.yaml
+++ llvm/test/tools/yaml2obj/XCOFF/long-symbol-name.yaml
@@ -2,8 +2,6 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-readobj --symbols --string-table %t | FileCheck %s
-## FIXME: The first item of StringTable should be `[ 4] .longname`.
-
# CHECK: AddressSize: 32bit
# CHECK-NEXT: Symbols [
# CHECK-NEXT: Symbol {
@@ -26,7 +24,7 @@
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: StringTable {
-# CHECK-NEXT: [ 3] ..longname
+# CHECK-NEXT: [ 4] .longname
# CHECK-NEXT: }
--- !XCOFF
Index: llvm/lib/Object/XCOFFObjectFile.cpp
===================================================================
--- llvm/lib/Object/XCOFFObjectFile.cpp
+++ llvm/lib/Object/XCOFFObjectFile.cpp
@@ -188,7 +188,9 @@
}
StringRef XCOFFObjectFile::getStringTable() const {
- return StringRef(StringTable.Data, StringTable.Size);
+ // If the size is less then 4, then the string table contains no string data.
+ return StringRef(StringTable.Data,
+ StringTable.Size > 4 ? StringTable.Size : 0);
}
Expected<StringRef>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105522.357855.patch
Type: text/x-patch
Size: 3271 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210712/a2265b7c/attachment.bin>
More information about the llvm-commits
mailing list