From b650a546cd8acb4274781f25aa076042d106dbf8 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Sat, 16 Aug 2025 10:47:39 +0800 Subject: [PATCH] supports linkerscript --- internal/crosscompile/crosscompile.go | 10 ++++++++-- internal/targets/config.go | 7 ++++--- internal/targets/loader.go | 3 +++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/internal/crosscompile/crosscompile.go b/internal/crosscompile/crosscompile.go index a1b4da87..bb475105 100644 --- a/internal/crosscompile/crosscompile.go +++ b/internal/crosscompile/crosscompile.go @@ -361,12 +361,18 @@ func useTarget(targetName string) (export Export, err error) { } // Handle Linker - keep it for external usage - export.Linker = config.Linker + if config.Linker != "" { + export.Linker = filepath.Join(clangRoot, "bin", config.Linker) + } + if config.LinkerScript != "" { + ldflags = append(ldflags, "-T", config.LinkerScript) + } + ldflags = append(ldflags, "-L", env.LLGoROOT()) // search targets/*.ld // Combine with config flags export.CFLAGS = config.CFlags export.CCFLAGS = ccflags - export.LDFLAGS = append(ldflags, filterCompatibleLDFlags(config.LDFlags)...) + export.LDFLAGS = append(ldflags, config.LDFlags...) export.EXTRAFLAGS = []string{} return export, nil diff --git a/internal/targets/config.go b/internal/targets/config.go index 66874434..821a38fc 100644 --- a/internal/targets/config.go +++ b/internal/targets/config.go @@ -16,9 +16,10 @@ type Config struct { GOARCH string `json:"goarch"` // Compiler and linker configuration - Linker string `json:"linker"` - CFlags []string `json:"cflags"` - LDFlags []string `json:"ldflags"` + Linker string `json:"linker"` + LinkerScript string `json:"linkerscript"` + CFlags []string `json:"cflags"` + LDFlags []string `json:"ldflags"` } // RawConfig represents the raw JSON configuration before inheritance resolution diff --git a/internal/targets/loader.go b/internal/targets/loader.go index cea4ee6d..9ec30f28 100644 --- a/internal/targets/loader.go +++ b/internal/targets/loader.go @@ -148,6 +148,9 @@ func (l *Loader) mergeConfig(dst, src *Config) { if len(src.LDFlags) > 0 { dst.LDFlags = append(dst.LDFlags, src.LDFlags...) } + if src.LinkerScript != "" { + dst.LinkerScript = src.LinkerScript + } } // GetTargetsDir returns the targets directory path