feat: support riscv32

This commit is contained in:
Haolan
2025-09-01 14:48:54 +08:00
parent 1b3889ebc9
commit 997ea2849b
15 changed files with 1518 additions and 24 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -3,10 +3,33 @@ package rtlib
import (
"fmt"
"path/filepath"
"strings"
"github.com/goplus/llgo/internal/crosscompile/compile"
)
func platformSpecifiedFiles(builtinsDir, target string) []string {
switch {
case strings.Contains(target, "riscv32"):
return []string{
filepath.Join(builtinsDir, "riscv", "mulsi3.S"),
filepath.Join(builtinsDir, "riscv", "fp_mode.c"),
filepath.Join(builtinsDir, "riscv", "save.S"),
filepath.Join(builtinsDir, "riscv", "restore.S"),
}
case target == "xtensa":
return []string{
filepath.Join(builtinsDir, "xtensa", "ieee754_sqrtf.S"),
}
}
return nil
}
func withPlatformSpecifiedFiles(baseDir, target string, files []string) []string {
builtinsDir := filepath.Join(baseDir, "lib", "builtins")
return append(files, platformSpecifiedFiles(builtinsDir, target)...)
}
func GetCompilerRTConfig(baseDir, target string) *compile.CompileConfig {
return &compile.CompileConfig{
Url: "https://github.com/goplus/compiler-rt/archive/refs/tags/v0.1.0.tar.gz",
@@ -14,8 +37,7 @@ func GetCompilerRTConfig(baseDir, target string) *compile.CompileConfig {
Groups: []compile.CompileGroup{
{
OutputFileName: fmt.Sprintf("libclang_builtins-%s.a", target),
Files: []string{
filepath.Join(baseDir, "lib", "builtins", "xtensa/ieee754_sqrtf.S"),
Files: withPlatformSpecifiedFiles(baseDir, target, []string{
filepath.Join(baseDir, "lib", "builtins", "absvdi2.c"),
filepath.Join(baseDir, "lib", "builtins", "absvsi2.c"),
filepath.Join(baseDir, "lib", "builtins", "absvti2.c"),
@@ -163,7 +185,8 @@ func GetCompilerRTConfig(baseDir, target string) *compile.CompileConfig {
filepath.Join(baseDir, "lib", "builtins", "trunctfdf2.c"),
filepath.Join(baseDir, "lib", "builtins", "trunctfhf2.c"),
filepath.Join(baseDir, "lib", "builtins", "trunctfsf2.c"),
},
filepath.Join(baseDir, "lib", "builtins", "atomic.c"),
}),
CFlags: []string{
"-DNDEBUG",
"-DVISIBILITY_HIDDEN",

View File

@@ -317,12 +317,12 @@ func use(goos, goarch string, wasiThreads bool) (export Export, err error) {
export.CCFLAGS = append(
export.CCFLAGS,
"-fdata-sections",
"-ffunction-sections",
// "-ffunction-sections",
)
export.LDFLAGS = append(
export.LDFLAGS,
"-fdata-sections",
"-ffunction-sections",
// "-ffunction-sections",
"-Xlinker",
"--gc-sections",
"-lm",
@@ -612,7 +612,7 @@ func useTarget(targetName string) (export Export, err error) {
baseDir := filepath.Join(cacheRoot(), "crosscompile")
outputDir := filepath.Join(baseDir, config.Libc)
compileConfig, err = getLibcCompileConfigByName(baseDir, config.Libc, config.LLVMTarget)
compileConfig, err = getLibcCompileConfigByName(baseDir, config.Libc, config.LLVMTarget, config.CPU)
if err != nil {
return
}

View File

@@ -11,7 +11,7 @@ import (
// GetCompileConfigByName retrieves libc compilation configuration by name
// Returns compilation file lists and corresponding cflags
func getLibcCompileConfigByName(baseDir, libcName, target string) (*compile.CompileConfig, error) {
func getLibcCompileConfigByName(baseDir, libcName, target, mcpu string) (*compile.CompileConfig, error) {
if libcName == "" {
return nil, fmt.Errorf("libc name cannot be empty")
}
@@ -21,7 +21,7 @@ func getLibcCompileConfigByName(baseDir, libcName, target string) (*compile.Comp
case "picolibc":
return libc.GetPicolibcConfig(libcDir, target), nil
case "newlib-esp32":
return libc.GetNewlibESP32Config(libcDir, target), nil
return libc.GetNewlibESP32Config(libcDir, target, mcpu), nil
default:
return nil, fmt.Errorf("unsupported libc: %s", libcName)
}