Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newt: Generate link tables header #542

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions newt/builder/extcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,47 @@ func (t *TargetBuilder) execExtCmds(sf stage.StageFunc, userSrcDir string,
return nil
}

func getLinkTableEntry(name string) string {
indent := " "

entry := indent + "__" + name + "_start__ = .;\n" +
indent + "KEEP(*(." + name + "))\n" +
indent + "__" + name + "_end__ = .;\n\n"

return entry
}

func (t *TargetBuilder) generateLinkTables() {
var s []string

for _, pkg := range t.res.LpkgRpkgMap {
s = append(s, pkg.Lpkg.LinkTables()...)
}

if len(s) == 0 {
return
}

dir := GeneratedBaseDir(t.target.FullName()) + "/link/include"
err := os.MkdirAll(dir, os.ModePerm)
if err != nil {
log.Error("Generate link tables error:\n", err)
return
}

linkHeader, err := os.Create(dir + "/link_tables.ld.h")
if err != nil {
log.Error("Generate link tables error:\n", err)
return
}

for _, linkTable := range s {
linkHeader.WriteString(getLinkTableEntry(linkTable))
}

}

//link tables
// execPreBuildCmds runs the target's set of pre-build user commands. It is an
// error if any command fails (exits with a nonzero status).
func (t *TargetBuilder) execPreBuildCmds(workDir string) error {
Expand Down
2 changes: 2 additions & 0 deletions newt/builder/targetbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ func (t *TargetBuilder) Build() error {
os.RemoveAll(workDir)
}()

t.generateLinkTables()

// Execute the set of pre-build user scripts.
if err := t.execPreBuildCmds(workDir); err != nil {
return err
Expand Down
17 changes: 17 additions & 0 deletions newt/pkg/localpackage.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type LocalPackage struct {
// General information about the package
desc *PackageDesc

linkTables []string

// Extra package-specific settings that don't come from syscfg. For
// example, SELFTEST gets set when the newt test command is used.
injectedSettings *cfgv.Settings
Expand Down Expand Up @@ -145,6 +147,10 @@ func (pkg *LocalPackage) Desc() *PackageDesc {
return pkg.desc
}

func (pkg *LocalPackage) LinkTables() []string {
return pkg.linkTables
}

func (pkg *LocalPackage) SetName(name string) {
pkg.name = name
}
Expand Down Expand Up @@ -197,6 +203,15 @@ func (pkg *LocalPackage) readDesc(yc ycfg.YCfg) (*PackageDesc, error) {
return pdesc, nil
}

func (pkg *LocalPackage) readLinkTables(yc ycfg.YCfg) ([]string, error) {
var err error

sections, err := yc.GetValStringSlice("pkg.link_tables", nil)
util.OneTimeWarningError(err)

return sections, nil
}

func (pkg *LocalPackage) sequenceString(key string) string {
var buffer bytes.Buffer

Expand Down Expand Up @@ -361,6 +376,8 @@ func (pkg *LocalPackage) Load() error {
return err
}

pkg.linkTables, err = pkg.readLinkTables(pkg.PkgY)

// Load syscfg settings.
pkg.SyscfgY, err = config.ReadFile(pkg.SyscfgYamlPath())
if err != nil && !util.IsNotExist(err) {
Expand Down
Loading