diff options
author | Weining Lu <luweining@loongson.cn> | 2022-08-23 13:11:32 +0800 |
---|---|---|
committer | Weining Lu <luweining@loongson.cn> | 2022-08-23 13:47:22 +0800 |
commit | 15b65bcd65195df8c9c0e84b64a1a825d9901ba6 (patch) | |
tree | 4b3ece1032fc1af60849c2915b172b019bc5d457 /clang/lib/Basic/Targets.cpp | |
parent | 6c6c4f6a9b3ef2d7db937cb78784245ea8a61418 (diff) | |
download | llvm-15b65bcd65195df8c9c0e84b64a1a825d9901ba6.zip llvm-15b65bcd65195df8c9c0e84b64a1a825d9901ba6.tar.gz llvm-15b65bcd65195df8c9c0e84b64a1a825d9901ba6.tar.bz2 |
[Clang][LoongArch] Add initial LoongArch target and driver support
With the initial support added, clang can compile `helloworld` C
to executable file for loongarch64. For example:
```
$ cat hello.c
int main() {
printf("Hello, world!\n");
return 0;
}
$ clang --target=loongarch64-unknown-linux-gnu --gcc-toolchain=xxx --sysroot=xxx hello.c
```
The output a.out can run within qemu or native machine. For example:
```
$ file ./a.out
./a.out: ELF 64-bit LSB pie executable, LoongArch, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-loongarch-lp64d.so.1, for GNU/Linux 5.19.0, with debug_info, not stripped
$ ./a.out
Hello, world!
```
Currently gcc toolchain and sysroot can be found here:
https://github.com/loongson/build-tools/releases/download/2022.08.11/loongarch64-clfs-5.1-cross-tools-gcc-glibc.tar.xz
Reference: https://github.com/loongson/LoongArch-Documentation
The last commit hash (main branch) is:
99016636af64d02dee05e39974d4c1e55875c45b
Note loongarch32 is not fully tested because there is no reference
gcc toolchain yet.
Differential Revision: https://reviews.llvm.org/D130255
Diffstat (limited to 'clang/lib/Basic/Targets.cpp')
-rw-r--r-- | clang/lib/Basic/Targets.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 2d6ef99..3824480 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -24,6 +24,7 @@ #include "Targets/Hexagon.h" #include "Targets/Lanai.h" #include "Targets/Le64.h" +#include "Targets/LoongArch.h" #include "Targets/M68k.h" #include "Targets/MSP430.h" #include "Targets/Mips.h" @@ -670,6 +671,20 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple, default: return new CSKYTargetInfo(Triple, Opts); } + case llvm::Triple::loongarch32: + switch (os) { + case llvm::Triple::Linux: + return new LinuxTargetInfo<LoongArch32TargetInfo>(Triple, Opts); + default: + return new LoongArch32TargetInfo(Triple, Opts); + } + case llvm::Triple::loongarch64: + switch (os) { + case llvm::Triple::Linux: + return new LinuxTargetInfo<LoongArch64TargetInfo>(Triple, Opts); + default: + return new LoongArch64TargetInfo(Triple, Opts); + } } } } // namespace targets |