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 committed Mar 6, 2024
1 parent 679b6a8 commit 60352fc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 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
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 60352fc

Please sign in to comment.