From 57575e11d1397eaca3174044a85648e3c94f8878 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 6 Sep 2018 00:06:25 +0000 Subject: [PATCH] [llvm-dwp] Use buffer_stream if output file is not seekable (e.g. "-") Reviewers: dblaikie, pcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D51707 llvm-svn: 341509 --- llvm/test/tools/llvm-dwp/X86/merge.test | 6 ++---- llvm/tools/llvm-dwp/llvm-dwp.cpp | 10 +++++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/llvm/test/tools/llvm-dwp/X86/merge.test b/llvm/test/tools/llvm-dwp/X86/merge.test index c9ba6d1..ea0adcc 100644 --- a/llvm/test/tools/llvm-dwp/X86/merge.test +++ b/llvm/test/tools/llvm-dwp/X86/merge.test @@ -1,7 +1,5 @@ -RUN: llvm-dwp %p/../Inputs/merge/notypes/c.dwo %p/../Inputs/merge/notypes/ab.dwp -o %t -RUN: llvm-dwarfdump -v %t | FileCheck --check-prefix=CHECK --check-prefix=NOTYP %s - -FIXME: For some reason, piping straight from llvm-dwp to llvm-dwarfdump -v doesn't behave well - looks like dwarfdump is reading/closes before dwp has finished. +RUN: llvm-dwp %p/../Inputs/merge/notypes/c.dwo %p/../Inputs/merge/notypes/ab.dwp -o - | \ +RUN: llvm-dwarfdump -v - | FileCheck --check-prefix=CHECK --check-prefix=NOTYP %s DWP from a DWO (c.dwo) and a DWP (ab.dwp, created from a.dwo and b.dwo) Make sure the entries for A and B are updated correctly when read/processed from ab.dwp diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp index d3380b5..4a1835a 100644 --- a/llvm/tools/llvm-dwp/llvm-dwp.cpp +++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -697,13 +697,21 @@ int main(int argc, char **argv) { // Create the output file. std::error_code EC; raw_fd_ostream OutFile(OutputFilename, EC, sys::fs::F_None); + Optional BOS; + raw_pwrite_stream *OS; if (EC) return error(Twine(OutputFilename) + ": " + EC.message(), Context); + if (OutFile.supportsSeeking()) { + OS = &OutFile; + } else { + BOS.emplace(OutFile); + OS = BOS.getPointer(); + } MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags(); std::unique_ptr MS(TheTarget->createMCObjectStreamer( TheTriple, MC, std::unique_ptr(MAB), - MAB->createObjectWriter(OutFile), std::unique_ptr(MCE), + MAB->createObjectWriter(*OS), std::unique_ptr(MCE), *MSTI, MCOptions.MCRelaxAll, MCOptions.MCIncrementalLinkerCompatible, /*DWARFMustBeAtTheEnd*/ false)); if (!MS) -- 2.7.4