Skip to content

Commit

Permalink
newt/compiler: Pass autogenerated linker script's include dir to linker
Browse files Browse the repository at this point in the history
This tells the linker where to look for includes related with
autogenerated linker scripts.
  • Loading branch information
m-gorecki authored and kasjer committed Mar 6, 2024
1 parent 679b6a8 commit 7e93439
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
9 changes: 9 additions & 0 deletions newt/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()],
Expand Down Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions newt/builder/cmake.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ func (b *Builder) CMakeTargetWrite(w io.Writer, targetCompiler *toolchain.Compil
lFlags = append(lFlags, "-T"+ld)
}

lFlags = append(lFlags, "-L"+c.AutogeneratedLinkerIncludeDir)

var cFlags []string
cFlags = append(cFlags, c.GetCompilerInfo().Cflags...)
cFlags = append(cFlags, c.GetLocalCompilerInfo().Cflags...)
Expand Down Expand Up @@ -365,7 +367,8 @@ func CmakeCompilerInfoWrite(w io.Writer, archiveFile string, bpkg *BuildPackage,
}

func (t *TargetBuilder) CMakeTargetBuilderWrite(w io.Writer, targetCompiler *toolchain.Compiler) error {
if err := t.PrepBuild(); err != nil {
var err error
if err = t.PrepBuild(); err != nil {
return err
}

Expand All @@ -381,12 +384,15 @@ func (t *TargetBuilder) CMakeTargetBuilderWrite(w io.Writer, targetCompiler *too
project.ResetDeps(t.AppList)

targetCompiler.LinkerScripts = t.bspPkg.LinkerScripts
if targetCompiler.AutogeneratedLinkerIncludeDir, err = t.bspPkg.GetAutogeneratedLinkerIncludePath(); err != nil {
return err
}

if err := t.bspPkg.Reload(t.AppBuilder.cfg.SettingValues()); err != nil {
if err = t.bspPkg.Reload(t.AppBuilder.cfg.SettingValues()); err != nil {
return err
}

if err := t.AppBuilder.CMakeTargetWrite(w, targetCompiler); err != nil {
if err = t.AppBuilder.CMakeTargetWrite(w, targetCompiler); err != nil {
return err
}

Expand Down
10 changes: 10 additions & 0 deletions newt/pkg/bsp_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions newt/toolchain/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 7e93439

Please sign in to comment.