Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to compile & link Clang/LLVM using the gold linker?

I'm writing a custom pass for LLVM/Clang, and recompiling tends to take a while and use a lot of memory. I've heard that the gold linker (1) takes less time and (2) uses less memory than the standard ld linker.

Is there a way to pass flags into the LLVM/Clang build process and change to the gold linker? As per this answer, I've been attempting to use an override file, but I don't seem to be having a lot of success.

I'll also note that I'm compiling the latest Clang/LLVM build (4.0) using Clang 3.9; I don't mind switching back to GCC if necessary but would rather avoid it.

like image 971
tonysdg Avatar asked Nov 10 '16 20:11

tonysdg


People also ask

Is it possible to compile Java?

In Java, programs are not compiled into executable files; they are compiled into bytecode (as discussed earlier), which the JVM (Java Virtual Machine) then executes at runtime. Java source code is compiled into bytecode when we use the javac compiler. The bytecode gets saved on the disk with the file extension .

Is it possible to compile Python?

For the most part, Python is an interpreted language and not a compiled one, although compilation is a step. Python code, written in . py file is first compiled to what is called bytecode (discussed in detail further) which is stored with a . pyc or .

What is a compile process?

What is a compilation? The compilation is a process of converting the source code into object code. It is done with the help of the compiler. The compiler checks the source code for the syntactical or structural errors, and if the source code is error-free, then it generates the object code.

What does compiling actually do?

As we already mentioned, the compilation process converts high-level source code to a low-level machine code that can be executed by the target machine. Moreover, an essential role of compilers is to inform the developer about errors committed, especially syntax-related ones.


1 Answers

Post-4.0 (after commit rL292047), you should set LLVM_USE_LINKER to gold like so:

cmake ... -DLLVM_USE_LINKER=gold ...

Refer to http://llvm.org/docs/CMake.html#llvm-specific-variables


While you can still use gold, these days (October 2021) you should probably use lld if it's present in your host toolchain. If your host toolchain is a clang+llvm distribution from llvm.org, it probably will. If your host toolchain is from a linux distribution's package manager, it will likely be available but installed as a separate independent package.

cmake ... -DLLVM_ENABLE_LLD=ON ...
like image 147
Brian Cain Avatar answered Nov 15 '22 12:11

Brian Cain