1

How can I make use of llvm as clang backend to compile C++ files without using gcc as clang's backend? I am pretty sure clang is using gcc because

$ clang++ --version
clang version 6.0.1 (tags/RELEASE_601/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin

it uses gnu as target instead of llvm. My llvm-config output:

$ llvm-config --version --targets-built
6.0.1
X86

I built both clang and llvm from source using standard options for my build target(X86).

EDIT: I think it is using gcc as backend because this code produces error in online ide but works on my machine with clang++ and g++. Code relies on fact that gcc has implementation of policy based data structures which are not part of standard.

5
  • 2
    Are you worried about the "Target"? Then don't be, it's the target platform (processor and operating system) which is almost universally always "linux-gnu" for Linux. Commented Jul 5, 2018 at 5:20
  • I am new to this so I mentioned everything I thought would be useful to find help! Commented Jul 5, 2018 at 5:32
  • 3
    Why do you think it is using GCC as its backend? Commented Jul 5, 2018 at 5:50
  • @Galik Because when I used -H option it included all the path as g++ includes. And also all policy based data structure which are gcc's implementation shouldn't work in llvm backend (I suppose). Commented Jul 5, 2018 at 6:49
  • 1
    On Linux clang uses GCC Standard Libraries libstdc++. But it doesn't use the compiler. Commented Jul 5, 2018 at 6:58

1 Answer 1

1

The problem is in the interpretation of the data. The target that clang refers to has to do with the platform for which you are generating code.

  • x86_64 This is a 64 bit processor compatible with Intel/and
  • unknown I'm uncertain about this one, though I believe it specifies more detail about the processor, which ain't available
  • linux You are using a Linux kernel/operation system
  • gnu The object structure should follow the gnu standards, I believe this directly maps on ELF

This will be different if you use BSD or windows as OS, or when your processor is an ARM, Intel 32 bit, Spark ...

The only moment you should be worrying about the target is when you are cross compiling. In other words, if the computer on which you are running the compiler has other requirements for the executable structure than the machine on which you will be running it.

PS: Clang always uses LLVM for it's IR. ignoring the deprecated Clang+C2, it always uses the LLVM optimizer and code generator.

Sign up to request clarification or add additional context in comments.

3 Comments

but if clang uses only LLVM tools then how is it possible to run clang without llvm installed? or does clang come with required llvm tools for it to compile without gcc backend?
@madhur4127 if installed through a package manager, clang has a dependency on libllvm
AFAIK the unknown part is related to the vendor. As a small reference, see here : wiki.osdev.org/Target_Triplet .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.