Skip to content

Commit

Permalink
all: use compiler-rt from LLVM
Browse files Browse the repository at this point in the history
  • Loading branch information
aykevl authored and deadprogram committed Apr 10, 2022
1 parent 09a3c6a commit 83227e6
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 22 deletions.
5 changes: 3 additions & 2 deletions .circleci/config.yml
Expand Up @@ -22,15 +22,16 @@ commands:
steps:
- restore_cache:
keys:
- llvm-source-13-v1
- llvm-source-13-v3
- run:
name: "Fetch LLVM source"
command: make llvm-source
- save_cache:
key: llvm-source-13-v1
key: llvm-source-13-v3
paths:
- llvm-project/clang/lib/Headers
- llvm-project/clang/include
- llvm-project/compiler-rt
- llvm-project/lld/include
- llvm-project/llvm/include
hack-ninja-jobs:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/build-macos.yml
Expand Up @@ -35,10 +35,11 @@ jobs:
uses: actions/cache@v2
id: cache-llvm-source
with:
key: llvm-source-13-macos-v1
key: llvm-source-13-macos-v2
path: |
llvm-project/clang/lib/Headers
llvm-project/clang/include
llvm-project/compiler-rt
llvm-project/lld/include
llvm-project/llvm/include
- name: Download LLVM source
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/linux.yml
Expand Up @@ -38,10 +38,11 @@ jobs:
uses: actions/cache@v2
id: cache-llvm-source
with:
key: llvm-source-13-linux-v1
key: llvm-source-13-linux-v2
path: |
llvm-project/clang/lib/Headers
llvm-project/clang/include
llvm-project/compiler-rt
llvm-project/lld/include
llvm-project/llvm/include
- name: Download LLVM source
Expand Down Expand Up @@ -179,10 +180,11 @@ jobs:
uses: actions/cache@v2
id: cache-llvm-source
with:
key: llvm-source-13-linux-asserts-v1
key: llvm-source-13-linux-asserts-v2
path: |
llvm-project/clang/lib/Headers
llvm-project/clang/include
llvm-project/compiler-rt
llvm-project/lld/include
llvm-project/llvm/include
- name: Download LLVM source
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/windows.yml
Expand Up @@ -35,10 +35,11 @@ jobs:
uses: actions/cache@v2
id: cache-llvm-source
with:
key: llvm-source-13-windows-v1
key: llvm-source-13-windows-v2
path: |
llvm-project/clang/lib/Headers
llvm-project/clang/include
llvm-project/compiler-rt
llvm-project/lld/include
llvm-project/llvm/include
- name: Download LLVM source
Expand Down
4 changes: 0 additions & 4 deletions .gitmodules
Expand Up @@ -10,10 +10,6 @@
[submodule "lib/cmsis-svd"]
path = lib/cmsis-svd
url = https://github.com/tinygo-org/cmsis-svd
[submodule "lib/compiler-rt"]
path = lib/compiler-rt
url = https://github.com/llvm-mirror/compiler-rt.git
branch = release_80
[submodule "lib/wasi-libc"]
path = lib/wasi-libc
url = https://github.com/CraneStation/wasi-libc
Expand Down
6 changes: 2 additions & 4 deletions Makefile
Expand Up @@ -619,7 +619,6 @@ build/release: tinygo gen-device wasi-libc $(if $(filter 1,$(USE_SYSTEM_BINARYEN
@mkdir -p build/release/tinygo/bin
@mkdir -p build/release/tinygo/lib/clang/include
@mkdir -p build/release/tinygo/lib/CMSIS/CMSIS
@mkdir -p build/release/tinygo/lib/compiler-rt/lib
@mkdir -p build/release/tinygo/lib/macos-minimal-sdk
@mkdir -p build/release/tinygo/lib/mingw-w64/mingw-w64-crt/lib-common
@mkdir -p build/release/tinygo/lib/mingw-w64/mingw-w64-headers/defaults
Expand All @@ -641,9 +640,6 @@ endif
@cp -p $(abspath $(CLANG_SRC))/lib/Headers/*.h build/release/tinygo/lib/clang/include
@cp -rp lib/CMSIS/CMSIS/Include build/release/tinygo/lib/CMSIS/CMSIS
@cp -rp lib/CMSIS/README.md build/release/tinygo/lib/CMSIS
@cp -rp lib/compiler-rt/lib/builtins build/release/tinygo/lib/compiler-rt/lib
@cp -rp lib/compiler-rt/LICENSE.TXT build/release/tinygo/lib/compiler-rt
@cp -rp lib/compiler-rt/README.txt build/release/tinygo/lib/compiler-rt
@cp -rp lib/macos-minimal-sdk/* build/release/tinygo/lib/macos-minimal-sdk
@cp -rp lib/musl/arch/aarch64 build/release/tinygo/lib/musl/arch
@cp -rp lib/musl/arch/arm build/release/tinygo/lib/musl/arch
Expand Down Expand Up @@ -680,6 +676,8 @@ endif
@cp -rp lib/picolibc/newlib/libm/common build/release/tinygo/lib/picolibc/newlib/libm
@cp -rp lib/picolibc-stdio.c build/release/tinygo/lib
@cp -rp lib/wasi-libc/sysroot build/release/tinygo/lib/wasi-libc/sysroot
@cp -rp llvm-project/compiler-rt/lib/builtins build/release/tinygo/lib/compiler-rt-builtins
@cp -rp llvm-project/compiler-rt/LICENSE.TXT build/release/tinygo/lib/compiler-rt-builtins
@cp -rp src build/release/tinygo/src
@cp -rp targets build/release/tinygo/targets
./build/tinygo build-library -target=cortex-m0 -o build/release/tinygo/pkg/thumbv6m-unknown-unknown-eabi-cortex-m0/compiler-rt compiler-rt
Expand Down
15 changes: 14 additions & 1 deletion builder/builtins.go
@@ -1,7 +1,11 @@
package builder

import (
"os"
"path/filepath"
"strings"

"github.com/tinygo-org/tinygo/goenv"
)

// These are the GENERIC_SOURCES according to CMakeList.txt.
Expand Down Expand Up @@ -72,6 +76,7 @@ var genericBuiltins = []string{
"floatunsisf.c",
"floatuntidf.c",
"floatuntisf.c",
"fp_mode.c",
//"int_util.c",
"lshrdi3.c",
"lshrti3.c",
Expand Down Expand Up @@ -161,7 +166,15 @@ var CompilerRT = Library{
cflags: func(target, headerPath string) []string {
return []string{"-Werror", "-Wall", "-std=c11", "-nostdlibinc"}
},
sourceDir: "lib/compiler-rt/lib/builtins",
sourceDir: func() string {
llvmDir := filepath.Join(goenv.Get("TINYGOROOT"), "llvm-project/compiler-rt/lib/builtins")
if _, err := os.Stat(llvmDir); err == nil {
// Release build.
return llvmDir
}
// Development build.
return filepath.Join(goenv.Get("TINYGOROOT"), "lib/compiler-rt-builtins")
},
librarySources: func(target string) []string {
builtins := append([]string{}, genericBuiltins...) // copy genericBuiltins
if strings.HasPrefix(target, "arm") || strings.HasPrefix(target, "thumb") {
Expand Down
16 changes: 12 additions & 4 deletions builder/library.go
Expand Up @@ -24,8 +24,8 @@ type Library struct {
// cflags returns the C flags specific to this library
cflags func(target, headerPath string) []string

// The source directory, relative to TINYGOROOT.
sourceDir string
// The source directory.
sourceDir func() string

// The source files, relative to sourceDir.
librarySources func(target string) []string
Expand Down Expand Up @@ -161,6 +161,12 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ
if strings.HasPrefix(target, "riscv64-") {
args = append(args, "-march=rv64gc", "-mabi=lp64")
}
if strings.HasPrefix(target, "xtensa") {
// Hack to work around an issue in the Xtensa port:
// https://github.com/espressif/llvm-project/issues/52
// Hopefully this will be fixed soon (LLVM 14).
args = append(args, "-D__ELF__")
}

var once sync.Once

Expand Down Expand Up @@ -195,6 +201,8 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ
},
}

sourceDir := l.sourceDir()

// Create jobs to compile all sources. These jobs are depended upon by the
// archive job above, so must be run first.
for _, path := range l.librarySources(target) {
Expand All @@ -203,7 +211,7 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ
for strings.HasPrefix(cleanpath, "../") {
cleanpath = cleanpath[3:]
}
srcpath := filepath.Join(goenv.Get("TINYGOROOT"), l.sourceDir, path)
srcpath := filepath.Join(sourceDir, path)
objpath := filepath.Join(dir, cleanpath+".o")
os.MkdirAll(filepath.Dir(objpath), 0o777)
objs = append(objs, objpath)
Expand All @@ -227,7 +235,7 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ
// (It could be done in parallel with creating the ar file, but it probably
// won't make much of a difference in speed).
if l.crt1Source != "" {
srcpath := filepath.Join(goenv.Get("TINYGOROOT"), l.sourceDir, l.crt1Source)
srcpath := filepath.Join(sourceDir, l.crt1Source)
job.dependencies = append(job.dependencies, &compileJob{
description: "compile " + srcpath,
run: func(*compileJob) error {
Expand Down
1 change: 1 addition & 0 deletions builder/mingw-w64.go
Expand Up @@ -26,6 +26,7 @@ var MinGW = Library{
_, err = io.Copy(outf, inf)
return err
},
sourceDir: func() string { return "" }, // unused
cflags: func(target, headerPath string) []string {
// No flags necessary because there are no files to compile.
return nil
Expand Down
2 changes: 1 addition & 1 deletion builder/musl.go
Expand Up @@ -104,7 +104,7 @@ var Musl = Library{
"-fno-stack-protector",
}
},
sourceDir: "lib/musl/src",
sourceDir: func() string { return filepath.Join(goenv.Get("TINYGOROOT"), "lib/musl/src") },
librarySources: func(target string) []string {
arch := compileopts.MuslArchitecture(target)
globs := []string{
Expand Down
2 changes: 1 addition & 1 deletion builder/picolibc.go
Expand Up @@ -33,7 +33,7 @@ var Picolibc = Library{
"-I" + headerPath,
}
},
sourceDir: "lib/picolibc/newlib/libc",
sourceDir: func() string { return filepath.Join(goenv.Get("TINYGOROOT"), "lib/picolibc/newlib/libc") },
librarySources: func(target string) []string {
return picolibcSources
},
Expand Down
1 change: 0 additions & 1 deletion lib/compiler-rt
Submodule compiler-rt deleted from 5bc797

0 comments on commit 83227e6

Please sign in to comment.