From 60352fc7bd55c509fec14d877c38fea90dec4a4e Mon Sep 17 00:00:00 2001 From: Michal Gorecki Date: Wed, 6 Mar 2024 11:58:19 +0100 Subject: [PATCH] newt/compiler: Pass autogenerated linker script's include dir to linker This tells the linker where to look for includes related with autogenerated linker scripts. --- newt/builder/build.go | 9 +++++++++ newt/pkg/bsp_package.go | 10 ++++++++++ newt/toolchain/compiler.go | 8 ++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/newt/builder/build.go b/newt/builder/build.go index 651c7dc47..d2fc0c9e0 100644 --- a/newt/builder/build.go +++ b/newt/builder/build.go @@ -150,6 +150,10 @@ func (b *Builder) addPackage(rpkg *resolve.ResolvePackage) ( return bpkg, nil } +func (b *Builder) GetAutogeneratedLinkerIncludeDir() (string, error) { + return b.targetBuilder.BspPkg().GetAutogeneratedLinkerIncludePath() +} + func pkgTypeConflictErr(p1 *BuildPackage, p2 *BuildPackage) error { return util.FmtNewtError("Two %s packages in build: %s, %s", pkg.PackageTypeNames[p1.rpkg.Lpkg.Type()], @@ -470,6 +474,11 @@ func (b *Builder) link(elfName string, linkerScripts []string, } c.LinkerScripts = linkerScripts + c.AutogeneratedLinkerIncludeDir, err = b.GetAutogeneratedLinkerIncludeDir() + if err != nil { + return err + } + err = c.CompileElf(elfName, trimmedANames, keepSymbols, b.linkElf) if err != nil { return err diff --git a/newt/pkg/bsp_package.go b/newt/pkg/bsp_package.go index 39e466695..46ecb7fb1 100644 --- a/newt/pkg/bsp_package.go +++ b/newt/pkg/bsp_package.go @@ -92,6 +92,16 @@ func (bsp *BspPackage) getAutogeneratedLinkerScriptPath() (string, error) { return path, nil } +func (bsp *BspPackage) GetAutogeneratedLinkerIncludePath() (string, error) { + defaultLinkerScriptPath := "bin/" + bsp.yov.Pkg.Name() + "/generated/link/include" + proj := interfaces.GetProject() + path, err := proj.ResolvePath(proj.Path(), defaultLinkerScriptPath) + if err != nil { + return "", err + } + return path, nil +} + // Interprets a setting as either a single linker script or a list of linker // scripts. func (bsp *BspPackage) resolveLinkerScriptSetting( diff --git a/newt/toolchain/compiler.go b/newt/toolchain/compiler.go index c63eabbf6..82ee88c15 100644 --- a/newt/toolchain/compiler.go +++ b/newt/toolchain/compiler.go @@ -70,8 +70,9 @@ type CompileCommand struct { } type Compiler struct { - objPathList map[string]bool - LinkerScripts []string + objPathList map[string]bool + LinkerScripts []string + AutogeneratedLinkerIncludeDir string // Needs to be locked whenever a mutable field in this struct is accessed // during a build. Currently, objPathList is the only such member. @@ -1040,6 +1041,9 @@ func (c *Compiler) CompileBinaryCmd(dstFile string, options map[string]bool, cmd = append(cmd, "-T") cmd = append(cmd, ls) } + cmd = append(cmd, "-L") + cmd = append(cmd, c.AutogeneratedLinkerIncludeDir) + if options["mapFile"] { cmd = append(cmd, "-Wl,-Map="+dstFile+".map") }