Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executable generated with clang++ goes crazy

#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
using namespace std;

class Book{
    public:
        int a;
        int b;
};

int main()
{
    Book b1;
    b1.a = 10;
    b1.b = 20;
    cout<< b1.a << " " <<b1.b;
}

when we compile the above code with

clang++ test.cc -o a.exe

and run a.exe works perfectly. But when we compile the same program with

clang++ test.cc -emit-llvm -S -o a.exe

and now when we run it, the program goes crazy by launching ntvdm.exe (can be seen in process explorer) and command prompt starts behaving weird.

Software stack:

clang version 2.9 (tags/RELEASE_29/final)
Target: i386-pc-mingw32
Thread model: posix
like image 616
Vineel Kumar Reddy Avatar asked Sep 16 '11 06:09

Vineel Kumar Reddy


People also ask

What is Clang executable?

The clang executable is actually a small driver which controls the overall execution of other tools such as the compiler, assembler and linker. Typically you do not need to interact with the driver, but you transparently use it to run the other tools.

Is G ++ a Clang?

gcc and g++ are the traditional GNU compilers for C and C++ code. Recently, clang (and clang++) using LLVM has been gaining popularity as an alternative compiler.

Do I need GCC for Clang?

Prerequisites. One of the goals of the Clang project is to be compatible with GCC, in dialect and on the command-line (see #Differences from GCC). Occasionally some packages will fail to build correctly with it and some may build successfully but segfault when executed.

Can Clang compile to Windows?

Clang-cl support This means that most developers can use clang-cl to compile their C/C++ applications on Visual Studio/MSBuild on the Windows on Arm device, without needing to change the command line.


1 Answers

By adding '-emit-llvm -S' you are not generating machine code, but LLVM bytecode. To run that, you need to use lli.

As ntvdm.exe is virtual machine for running real-mode DOS programs, it might mean that windows interprets executable in LLVM bytecode as 16-bit DOS program and tries to run it as one.

like image 127
plaes Avatar answered Sep 26 '22 08:09

plaes