diff --git a/builder/build.go b/builder/build.go index 6df86956..4d186271 100644 --- a/builder/build.go +++ b/builder/build.go @@ -171,7 +171,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil // Add compiler-rt dependency if needed. Usually this is a simple load from // a cache. if config.Target.RTLib == "compiler-rt" { - path, job, err := CompilerRT.load(config.Triple(), dir) + path, job, err := CompilerRT.load(config.Triple(), config.CPU(), dir) if err != nil { return err } @@ -187,7 +187,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil // Add libc dependency if needed. if config.Target.Libc == "picolibc" { - path, job, err := Picolibc.load(config.Triple(), dir) + path, job, err := Picolibc.load(config.Triple(), config.CPU(), dir) if err != nil { return err } diff --git a/builder/library.go b/builder/library.go index 886499d2..40699491 100644 --- a/builder/library.go +++ b/builder/library.go @@ -42,7 +42,7 @@ func (l *Library) sourcePaths(target string) []string { // The resulting file is stored in the provided tmpdir, which is expected to be // removed after the Load call. func (l *Library) Load(target, tmpdir string) (path string, err error) { - path, job, err := l.load(target, tmpdir) + path, job, err := l.load(target, "", tmpdir) if err != nil { return "", err } @@ -59,7 +59,7 @@ func (l *Library) Load(target, tmpdir string) (path string, err error) { // path is valid. // The provided tmpdir will be used to store intermediary files and possibly the // output archive file, it is expected to be removed after use. -func (l *Library) load(target, tmpdir string) (path string, job *compileJob, err error) { +func (l *Library) load(target, cpu, tmpdir string) (path string, job *compileJob, err error) { // Try to load a precompiled library. precompiledPath := filepath.Join(goenv.Get("TINYGOROOT"), "pkg", target, l.name+".a") if _, err := os.Stat(precompiledPath); err == nil { @@ -68,7 +68,12 @@ func (l *Library) load(target, tmpdir string) (path string, job *compileJob, err return precompiledPath, nil, nil } - outfile := l.name + "-" + target + ".a" + var outfile string + if cpu != "" { + outfile = l.name + "-" + target + "-" + cpu + ".a" + } else { + outfile = l.name + "-" + target + ".a" + } // Try to fetch this library from the cache. if path, err := cacheLoad(outfile, l.sourcePaths(target)); path != "" || err != nil { @@ -89,6 +94,9 @@ func (l *Library) load(target, tmpdir string) (path string, job *compileJob, err // reproducible. Otherwise the temporary directory is stored in the archive // itself, which varies each run. args := append(l.cflags(), "-c", "-Oz", "-g", "-ffunction-sections", "-fdata-sections", "-Wno-macro-redefined", "--target="+target, "-fdebug-prefix-map="+dir+"="+remapDir) + if cpu != "" { + args = append(args, "-mcpu="+cpu) + } if strings.HasPrefix(target, "arm") || strings.HasPrefix(target, "thumb") { args = append(args, "-fshort-enums", "-fomit-frame-pointer", "-mfloat-abi=soft") }