if (Options.NoOutput)
return true;
- Streamer = llvm::make_unique<DwarfStreamer>(OutFile);
+ Streamer = llvm::make_unique<DwarfStreamer>(OutFile, Options);
return Streamer->init(TheTriple);
}
if (LLVM_UNLIKELY(Options.Update)) {
for (auto &CurrentUnit : LinkContext.CompileUnits)
CurrentUnit->markEverythingAsKept();
- Streamer->copyInvariantDebugSection(*LinkContext.ObjectFile, Options);
+ Streamer->copyInvariantDebugSection(*LinkContext.ObjectFile);
} else {
for (auto &CurrentUnit : LinkContext.CompileUnits)
lookForDIEsToKeep(LinkContext.RelocMgr, LinkContext.Ranges,
if (!MSTI)
return error("no subtarget info for target " + TripleName, Context);
- MCTargetOptions Options;
- MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, Options);
+ MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags();
+ MAB = TheTarget->createMCAsmBackend(*MSTI, *MRI, MCOptions);
if (!MAB)
return error("no asm backend for target " + TripleName, Context);
if (!MCE)
return error("no code emitter for target " + TripleName, Context);
- MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags();
- MS = TheTarget->createMCObjectStreamer(
- TheTriple, *MC, std::unique_ptr<MCAsmBackend>(MAB),
- MAB->createObjectWriter(OutFile), std::unique_ptr<MCCodeEmitter>(MCE),
- *MSTI, MCOptions.MCRelaxAll, MCOptions.MCIncrementalLinkerCompatible,
- /*DWARFMustBeAtTheEnd*/ false);
+ switch (Options.FileType) {
+ case OutputFileType::Assembly: {
+ MIP = TheTarget->createMCInstPrinter(TheTriple, MAI->getAssemblerDialect(),
+ *MAI, *MII, *MRI);
+ MS = TheTarget->createAsmStreamer(
+ *MC, llvm::make_unique<formatted_raw_ostream>(OutFile), true, true, MIP,
+ std::unique_ptr<MCCodeEmitter>(MCE), std::unique_ptr<MCAsmBackend>(MAB),
+ true);
+ break;
+ }
+ case OutputFileType::Object: {
+ MS = TheTarget->createMCObjectStreamer(
+ TheTriple, *MC, std::unique_ptr<MCAsmBackend>(MAB),
+ MAB->createObjectWriter(OutFile), std::unique_ptr<MCCodeEmitter>(MCE),
+ *MSTI, MCOptions.MCRelaxAll, MCOptions.MCIncrementalLinkerCompatible,
+ /*DWARFMustBeAtTheEnd*/ false);
+ break;
+ }
+ }
+
if (!MS)
return error("no object streamer for target " + TripleName, Context);
bool DwarfStreamer::finish(const DebugMap &DM) {
bool Result = true;
- if (DM.getTriple().isOSDarwin() && !DM.getBinaryPath().empty())
+ if (DM.getTriple().isOSDarwin() && !DM.getBinaryPath().empty() &&
+ Options.FileType == OutputFileType::Object)
Result = MachOUtils::generateDsymCompanion(DM, *MS, OutFile);
else
MS->Finish();
MS->EmitBytes(Contents);
}
-void DwarfStreamer::copyInvariantDebugSection(const object::ObjectFile &Obj,
- LinkOptions &Options) {
+void DwarfStreamer::copyInvariantDebugSection(const object::ObjectFile &Obj) {
MS->SwitchSection(MC->getObjectFileInfo()->getDwarfLineSection());
emitSectionContents(Obj, "debug_line", MS);
#include "CompileUnit.h"
#include "DebugMap.h"
+#include "LinkUtils.h"
#include "NonRelocatableStringpool.h"
#include "llvm/CodeGen/AccelTable.h"
#include "llvm/CodeGen/AsmPrinter.h"
namespace llvm {
namespace dsymutil {
-struct LinkOptions;
-
/// The Dwarf streaming logic.
///
/// All interactions with the MC layer that is used to build the debug
/// information binary representation are handled in this class.
class DwarfStreamer {
public:
- DwarfStreamer(raw_fd_ostream &OutFile) : OutFile(OutFile) {}
+ DwarfStreamer(raw_fd_ostream &OutFile, LinkOptions Options)
+ : OutFile(OutFile), Options(std::move(Options)) {}
+
bool init(Triple TheTriple);
/// Dump the file to the disk.
unsigned AdddressSize);
/// Copy over the debug sections that are not modified when updating.
- void copyInvariantDebugSection(const object::ObjectFile &Obj, LinkOptions &);
+ void copyInvariantDebugSection(const object::ObjectFile &Obj);
uint32_t getLineSectionSize() const { return LineSectionSize; }
MCAsmBackend *MAB; // Owned by MCStreamer
std::unique_ptr<MCInstrInfo> MII;
std::unique_ptr<MCSubtargetInfo> MSTI;
+ MCInstPrinter *MIP; // Owned by AsmPrinter
MCCodeEmitter *MCE; // Owned by MCStreamer
MCStreamer *MS; // Owned by AsmPrinter
std::unique_ptr<TargetMachine> TM;
/// The file we stream the linked Dwarf to.
raw_fd_ostream &OutFile;
+ LinkOptions Options;
+
uint32_t RangesSectionSize;
uint32_t LocSectionSize;
uint32_t LineSectionSize;
desc("Specify a directory to prepend to the paths of object files."),
value_desc("path"), cat(DsymCategory));
+static opt<bool> Assembly(
+ "S",
+ desc("Output textual assembly instead of a binary dSYM companion file."),
+ init(false), cat(DsymCategory), cl::Hidden);
+
static opt<bool> DumpStab(
"symtab",
desc("Dumps the symbol table found in executable or object file(s) and\n"
Options.NoTimestamp = NoTimestamp;
Options.PrependPath = OsoPrependPath;
+ if (Assembly)
+ Options.FileType = OutputFileType::Assembly;
+
if (Options.Update && std::find(InputFiles.begin(), InputFiles.end(), "-") !=
InputFiles.end()) {
// FIXME: We cannot use stdin for an update because stdin will be