Thread overview
Windows build: how did you do it?
Jan 26, 2014
Carl
Jan 26, 2014
David Nadlinger
Jan 26, 2014
Kai Nacke
January 26, 2014
Hello guys,

I would like to ask a question more about llvm than about d :)
I'm not sure that this is "correct" thing to do, but I'm stuck and out of options.
(flame away if you feel like I'm abusing your forum)

I'm using llvm on windows (with mingw) to compile IR code that my program generates.

Which is pretty much what you did with the D compiler.

I do it in two phases:

       TargetMachine targetMachine = target.createTargetMachine(triple);

        targetMachine.setAsmVerbosityDefault(true);
        targetMachine.setFunctionSections(true);
        targetMachine.setDataSections(true);
        targetMachine.getOptions().setNoFramePointerElim(true);
        output.reset();
        targetMachine.emit(module, output, CodeGenFileType.AssemblyFile);
        module.dispose();
        context.dispose();

        byte[] asm = output.toByteArray();
        output.reset();
        asm = output.toByteArray();

        BufferedOutputStream oOut = new BufferedOutputStream(new FileOutputStream(oFile));

        targetMachine.assemble(asm, clazz.getClassName(), oOut);
        oOut.close();


Unfortunately, the assemble call fails with the error


org.robovm.llvm.LlvmException: java.io.PrintWriter:478:2: error: unknown directive
        .section        .text$java_io_PrintWriter_checkError__Z_lookup,"xr"
        ^
java.io.PrintWriter:479:2: error: unknown directive
        .linkonce discard
        ^
java.io.PrintWriter:629:2: error: unknown directive
        .section        .text$java_io_PrintWriter_clearError__V_lookup,"xr"
        ^
java.io.PrintWriter:630:2: error: unknown directive
        .linkonce discard
        ^
java.io.PrintWriter:818:2: error: unknown directive
        .section        .text$java_io_PrintWriter_close__V_lookup,"xr"
        ^
java.io.PrintWriter:819:2: error: unknown directive
        .linkonce discard
        ^
java.io.PrintWriter:1008:2: error: unknown directive
        .section        .text$java_io_PrintWriter_flush__V_lookup,"xr"
        ^
java.io.PrintWriter:1009:2: error: unknown directive
        .linkonce discard
        ^
java.io.PrintWriter:1062:2: error: unknown directive
        .section        .text$java_io_PrintWriter_format__Ljava_lang_String$3B$5BLjava_lang_Object$3B__Ljava_io_PrintWriter$3B_lookup,"xr"
        ^
java.io.PrintWriter:1063:2: error: unknown directive
        .linkonce discard

Did you ever get that error?
The fact is I need to generate my code in two steps (emit assembly and then assemble) because of some ASM processing.
It is interesting to notice that if I generate the obj directly with targetMachine.emit(module, output, CodeGenFileType.ObjectFile);
the generation is OKAY.

(but then my program is unable to process the ASM, so that's not good).
January 26, 2014
Hi Carl,

we are currently invoking gcc (i.e. GAS) as a subprocess for assembling, because the MC COFF backend does not support emitting Dwarf EH information yet (at least when I last checked). Before we had working EH, we were using MC to directly write out the COFF object files, which as you mentioned works without problems.

I never tried to make MC emit ASM and then parse it again, although it seems as though it should work.

David
January 26, 2014
On Sunday, 26 January 2014 at 13:48:29 UTC, Carl wrote:
> Did you ever get that error?

Hi Carl!

LLVM has not implemented everything which is needed for Windows. Some time ago I tried the same with clang:

clang -S -emit-llvm -o exc_alloc.ll exc_alloc.c
llc -filetype=asm exc_alloc.ll
clang -c exc_alloc.s

The file exc_alloc.c contained a dll_import reference which was/is not supported by the assembler. IMHO you are getting the same kind of error.

(Windows is not yet a first class citizen of LLVM. If you really need something implemented then you should look if you can contribute it to LLVM. I do the same.)

Regards,
Kai