From 8fd3eda7286b19a53e1e0ad6c76772774dd24089 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Tue, 12 Feb 2013 23:55:08 +0100 Subject: [PATCH] Use the system assembler on MinGW. MC does not support writing out the exception handling tables to COFF files yet. --- driver/toobj.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/driver/toobj.cpp b/driver/toobj.cpp index e374867d..f19f1471 100644 --- a/driver/toobj.cpp +++ b/driver/toobj.cpp @@ -8,9 +8,11 @@ //===----------------------------------------------------------------------===// #include "driver/toobj.h" +#include "driver/tool.h" #include "gen/irstate.h" #include "gen/logger.h" #include "gen/optimizer.h" +#include "gen/programs.h" #include "llvm/Analysis/Verifier.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/PassManager.h" @@ -26,7 +28,6 @@ #include #include - // based on llc code, University of Illinois Open Source License static void codegenModule(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostream& out, llvm::TargetMachine::CodeGenFileType fileType) @@ -62,6 +63,30 @@ static void codegenModule(llvm::TargetMachine &Target, llvm::Module& m, Passes.doFinalization(); } +static void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objpath) +{ + std::vector args; + args.push_back("-O3"); + args.push_back("-c"); + args.push_back("-xassembler"); + args.push_back(asmpath.str()); + args.push_back("-o"); + args.push_back(objpath.str()); + + if (global.params.is64bit) + args.push_back("-m64"); + else + args.push_back("-m32"); + + // Run the compiler to assembly the program. + int R = executeToolAndWait(getGcc(), args, global.params.verbose); + if (R) + { + error("Error while invoking external assembler."); + fatal(); + } +} + ////////////////////////////////////////////////////////////////////////////////////////// void writeModule(llvm::Module* m, std::string filename) @@ -69,6 +94,11 @@ void writeModule(llvm::Module* m, std::string filename) // run optimizer ldc_optimize_module(m); + // We don't use the integrated assembler with MinGW as it does not support + // emitting DW2 exception handling tables. + bool const assembleExternally = global.params.output_o && + global.params.targetTriple.getOS() == llvm::Triple::MinGW32; + // eventually do our own path stuff, dmd's is a bit strange. typedef llvm::sys::Path LLPath; @@ -105,10 +135,12 @@ void writeModule(llvm::Module* m, std::string filename) } // write native assembly - if (global.params.output_s) { + if (global.params.output_s || assembleExternally) { LLPath spath = LLPath(filename); spath.eraseSuffix(); spath.appendSuffix(std::string(global.s_ext)); + if (!global.params.output_s) spath.createTemporaryFileOnDisk(); + Logger::println("Writing native asm to: %s\n", spath.c_str()); std::string err; { @@ -123,9 +155,17 @@ void writeModule(llvm::Module* m, std::string filename) fatal(); } } + + if (assembleExternally) + { + LLPath objpath(filename); + assemble(spath, objpath); + } + + if (!global.params.output_s) spath.eraseFromDisk(); } - if (global.params.output_o) { + if (global.params.output_o && !assembleExternally) { LLPath objpath = LLPath(filename); Logger::println("Writing object file to: %s\n", objpath.c_str()); std::string err;