[PATCH] D63115: [llvm-readobj] Fix output interleaving issue caused by using multiple streams at the same time.
Yuanfang Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 10 19:06:24 PDT 2019
ychen created this revision.
ychen added reviewers: jhenderson, grimar, MaskRay, phosek, rupprecht.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
ychen edited the summary of this revision.
Use llvm::fouts() as the default stream for outputing. No new stream
should be constructed to output at the same time.
https://bugs.llvm.org/show_bug.cgi?id=42140
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D63115
Files:
llvm/test/tools/llvm-readobj/fix-interleaved-output.test
llvm/tools/llvm-readobj/COFFDumper.cpp
llvm/tools/llvm-readobj/ELFDumper.cpp
llvm/tools/llvm-readobj/MachODumper.cpp
llvm/tools/llvm-readobj/llvm-readobj.cpp
Index: llvm/tools/llvm-readobj/llvm-readobj.cpp
===================================================================
--- llvm/tools/llvm-readobj/llvm-readobj.cpp
+++ llvm/tools/llvm-readobj/llvm-readobj.cpp
@@ -466,6 +466,7 @@
Writer.printString("AddressSize",
formatv("{0}bit", 8 * Obj->getBytesInAddress()));
Dumper->printLoadName();
+ Writer.flush();
}
if (opts::FileHeaders)
@@ -619,7 +620,7 @@
/// Opens \a File and dumps it.
static void dumpInput(StringRef File) {
- ScopedPrinter Writer(outs());
+ ScopedPrinter Writer(fouts());
// Attempt to open the binary.
Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(File);
Index: llvm/tools/llvm-readobj/MachODumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/MachODumper.cpp
+++ llvm/tools/llvm-readobj/MachODumper.cpp
@@ -689,7 +689,7 @@
llvm::stable_sort(Libs);
for (const auto &L : Libs) {
- outs() << " " << L << "\n";
+ W.startLine() << L << "\n";
}
}
Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -382,13 +382,14 @@
};
template <typename ELFT> class GNUStyle : public DumpStyle<ELFT> {
- formatted_raw_ostream OS;
+ formatted_raw_ostream &OS;
public:
TYPEDEF_ELF_TYPES(ELFT)
GNUStyle(ScopedPrinter &W, ELFDumper<ELFT> *Dumper)
- : DumpStyle<ELFT>(Dumper), OS(W.getOStream()) {}
+ : DumpStyle<ELFT>(Dumper),
+ OS(static_cast<formatted_raw_ostream&>(W.getOStream())) {}
void printFileHeaders(const ELFO *Obj) override;
void printGroupSections(const ELFFile<ELFT> *Obj) override;
Index: llvm/tools/llvm-readobj/COFFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/COFFDumper.cpp
+++ llvm/tools/llvm-readobj/COFFDumper.cpp
@@ -1565,7 +1565,7 @@
llvm::stable_sort(Libs);
for (const auto &L : Libs) {
- outs() << " " << L << "\n";
+ W.startLine() << L << "\n";
}
}
Index: llvm/test/tools/llvm-readobj/fix-interleaved-output.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-readobj/fix-interleaved-output.test
@@ -0,0 +1,25 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readelf --needed-libs --dynamic-table %t | FileCheck %s
+
+# CHECK: Dynamic section at offset 0x1b8 contains 1 entries:
+# CHECK-NEXT: Tag Type Name/Value
+# CHECK-NEXT: 0x0000000000000000 (NULL) 0x0
+# CHECK-NEXT: NeededLibraries [
+# CHECK-NEXT: ]
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .dynamic
+ Type: SHT_DYNAMIC
+ Entries:
+ - Tag: DT_NULL
+ Value: 0
+ProgramHeaders:
+ - Type: PT_DYNAMIC
+ Sections:
+ - Section: .dynamic
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63115.203954.patch
Type: text/x-patch
Size: 3010 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190611/21e87115/attachment.bin>
More information about the llvm-commits
mailing list