This is an automated email from the ASF dual-hosted git repository.
kasjer pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git
The following commit(s) were added to refs/heads/master by this push:
new d5d4f114 newt: Use compiler binutils instead of arm-none-eabi ones
d5d4f114 is described below
commit d5d4f114f847f43cc4b0693b309cfe86df416acb
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Sun Oct 18 22:05:02 2026 +0200
newt: Use compiler binutils instead of arm-none-eabi ones
newt create-image and newt size -F/-R/-S always executed
arm-none-eabi-objdump, arm-none-eabi-nm and arm-none-eabi-addr2line,
regardless of the compiler used by the target. Projects using other
toolchains (e.g. xc32 for PIC32 or RISC-V gcc) failed with:
exec: "arm-none-eabi-objdump": executable file not found in %PATH%
unless an ARM toolchain was also installed.
Now objdump path is taken from compiler.path.objdump. nm and addr2line
can be specified with new optional compiler.path.nm and
compiler.path.addr2line, by default they are derived from objdump path
(e.g. xc32-objdump -> xc32-nm, xc32-addr2line).
create-image runs objdump only when --sections is specified since
its output is not used otherwise.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jerzy Kasenberg <[email protected]>
---
newt/builder/size.go | 7 ++++++-
newt/builder/size_report.go | 43 +++++++++++++++++++++++++------------------
newt/imgprod/imgprod.go | 37 ++++++++++++++++++++++++++++++-------
newt/toolchain/compiler.go | 32 ++++++++++++++++++++++++++++++++
4 files changed, 93 insertions(+), 26 deletions(-)
diff --git a/newt/builder/size.go b/newt/builder/size.go
index 8da6f1a8..37841634 100644
--- a/newt/builder/size.go
+++ b/newt/builder/size.go
@@ -482,7 +482,12 @@ func (t *TargetBuilder) SizeReport(sectionName string,
diffFriendly bool) error
func (b *Builder) SizeReport(sectionName string, diffFriendly bool) error {
srcBase := interfaces.GetProject().Path() + "/"
- err := SizeReport(b.AppElfPath(), srcBase, sectionName, diffFriendly)
+ c, err := b.newCompiler(b.appPkg, b.FileBinDir(b.AppElfPath()))
+ if err != nil {
+ return err
+ }
+
+ err = SizeReport(c, b.AppElfPath(), srcBase, sectionName, diffFriendly)
if err != nil {
return util.NewNewtError(err.Error())
}
diff --git a/newt/builder/size_report.go b/newt/builder/size_report.go
index d62f5b28..79699428 100644
--- a/newt/builder/size_report.go
+++ b/newt/builder/size_report.go
@@ -22,6 +22,7 @@ package builder
import (
"bufio"
"fmt"
+ "mynewt.apache.org/newt/newt/toolchain"
"mynewt.apache.org/newt/util"
"os"
"os/exec"
@@ -29,12 +30,12 @@ import (
"strings"
)
-func runNmCommand(elfFilePath string) ([]byte, error) {
+func runNmCommand(nmPath string, elfFilePath string) ([]byte, error) {
var (
cmdOut []byte
err error
)
- cmdName := "arm-none-eabi-nm"
+ cmdName := nmPath
cmdArgs := []string{elfFilePath, "-S", "-l", "--size-sort"}
if cmdOut, err = exec.Command(cmdName, cmdArgs...).Output(); err != nil
{
@@ -45,12 +46,13 @@ func runNmCommand(elfFilePath string) ([]byte, error) {
return cmdOut, err
}
-func runObjdumpCommand(elfFilePath string, params string) ([]byte, error) {
+func runObjdumpCommand(odPath string, elfFilePath string,
+ params string) ([]byte, error) {
var (
cmdOut []byte
err error
)
- cmdName := "arm-none-eabi-objdump"
+ cmdName := odPath
cmdArgs := []string{params, elfFilePath}
if cmdOut, err = exec.Command(cmdName, cmdArgs...).Output(); err != nil
{
fmt.Fprintln(os.Stderr, "There was an error running objdump
command: ",
@@ -61,12 +63,13 @@ func runObjdumpCommand(elfFilePath string, params string)
([]byte, error) {
return cmdOut, err
}
-func runAddr2lineCommand(elfFilePath string, address string) ([]byte, error) {
+func runAddr2lineCommand(a2lPath string, elfFilePath string,
+ address string) ([]byte, error) {
var (
cmdOut []byte
err error
)
- cmdName := "arm-none-eabi-addr2line"
+ cmdName := a2lPath
cmdArgs := []string{"-e", elfFilePath, address}
cmdOut, err = exec.Command(cmdName, cmdArgs...).Output()
@@ -76,11 +79,11 @@ func runAddr2lineCommand(elfFilePath string, address
string) ([]byte, error) {
return cmdOut, err
}
-func loadSymbolsAndPaths(elfFilePath, pathToStrip string) (map[string]string,
- error) {
+func loadSymbolsAndPaths(c *toolchain.Compiler, elfFilePath,
+ pathToStrip string) (map[string]string, error) {
symbolsPath := make(map[string]string)
- nmOut, err := runNmCommand(elfFilePath)
+ nmOut, err := runNmCommand(c.GetNmPath(), elfFilePath)
if err != nil {
return nil, err
}
@@ -95,7 +98,8 @@ func loadSymbolsAndPaths(elfFilePath, pathToStrip string)
(map[string]string,
var path string
if len(fields) < 5 {
- addr2lineOut, err := runAddr2lineCommand(elfFilePath,
fields[0])
+ addr2lineOut, err :=
runAddr2lineCommand(c.GetAddr2linePath(), elfFilePath,
+ fields[0])
if err != nil {
path = "(other)"
} else {
@@ -148,8 +152,9 @@ func (m *MemoryRegion) PartOf(addr uint64) bool {
return addr >= m.Offset && addr < m.EndOff
}
-func loadSymbolsAndSections(elfFilePath string) (map[string]*Symbol, error) {
- objdumpOut, err := runObjdumpCommand(elfFilePath, "-tw")
+func loadSymbolsAndSections(c *toolchain.Compiler,
+ elfFilePath string) (map[string]*Symbol, error) {
+ objdumpOut, err := runObjdumpCommand(c.GetObjdumpPath(), elfFilePath,
"-tw")
if err != nil {
return nil, err
}
@@ -178,7 +183,8 @@ func loadSymbolsAndSections(elfFilePath string)
(map[string]*Symbol, error) {
return symbols, nil
}
-func getMemoryRegion(elfFilePath string, sectionName string) (*MemoryRegion,
+func getMemoryRegion(c *toolchain.Compiler, elfFilePath string,
+ sectionName string) (*MemoryRegion,
error) {
mapFile := elfFilePath + ".map"
@@ -187,7 +193,7 @@ func getMemoryRegion(elfFilePath string, sectionName
string) (*MemoryRegion,
return nil, err
}
- objdumpOut, err := runObjdumpCommand(elfFilePath, "-hw")
+ objdumpOut, err := runObjdumpCommand(c.GetObjdumpPath(), elfFilePath,
"-hw")
if err != nil {
return nil, err
}
@@ -289,16 +295,17 @@ func logMemoryRegionStats(memRegion *MemoryRegion,
sectionName string) {
util.StatusMessage(util.VERBOSITY_VERBOSE, "\n")
}
-func SizeReport(elfFilePath, srcBase string, sectionName string, diffFriendly
bool) error {
- symbolsPath, err := loadSymbolsAndPaths(elfFilePath, srcBase)
+func SizeReport(c *toolchain.Compiler, elfFilePath, srcBase string,
+ sectionName string, diffFriendly bool) error {
+ symbolsPath, err := loadSymbolsAndPaths(c, elfFilePath, srcBase)
if err != nil {
return err
}
- loadedSectionSizes, err := loadSymbolsAndSections(elfFilePath)
+ loadedSectionSizes, err := loadSymbolsAndSections(c, elfFilePath)
if err != nil {
return err
}
- sectionRegion, err := getMemoryRegion(elfFilePath, sectionName)
+ sectionRegion, err := getMemoryRegion(c, elfFilePath, sectionName)
if err != nil {
return err
}
diff --git a/newt/imgprod/imgprod.go b/newt/imgprod/imgprod.go
index 1e82977f..f94524ad 100644
--- a/newt/imgprod/imgprod.go
+++ b/newt/imgprod/imgprod.go
@@ -319,19 +319,30 @@ func OptsFromTgtBldr(b *builder.TargetBuilder, ver
image.ImageVersion,
return opts, nil
}
-func ProduceAll(t *builder.TargetBuilder, ver image.ImageVersion,
- sigKeys []sec.PrivSignKey, encKeyFilename string, encKeyIndex int,
- hdrPad int, imagePad int, sectionString string, useLegacyTLV bool)
error {
+// Finds offsets and sizes of the specified comma-separated list of sections
+// relative to the start of the app image.
+func imageSections(t *builder.TargetBuilder,
+ sectionString string) ([]image.Section, error) {
+
+ var sections []image.Section
+
+ if sectionString == "" {
+ return sections, nil
+ }
elfPath := t.AppBuilder.AppElfPath()
- cmdName := "arm-none-eabi-objdump"
- cmdOut, err := exec.Command(cmdName, elfPath, "-hw").Output()
+ c, err := t.NewCompiler(t.AppBuilder.FileBinDir(elfPath), "")
if err != nil {
- return err
+ return nil, err
+ }
+
+ cmdOut, err := exec.Command(c.GetObjdumpPath(), elfPath, "-hw").Output()
+ if err != nil {
+ return nil, util.FmtNewtError("Failed to read sections of %s:
%s",
+ elfPath, err.Error())
}
- var sections []image.Section
section_list := strings.Split(sectionString, ",")
lines := strings.Split(string(cmdOut), "\n")
var imgBase int
@@ -368,6 +379,18 @@ func ProduceAll(t *builder.TargetBuilder, ver
image.ImageVersion,
sections[s].Offset = sections[s].Offset - imgBase
}
+ return sections, nil
+}
+
+func ProduceAll(t *builder.TargetBuilder, ver image.ImageVersion,
+ sigKeys []sec.PrivSignKey, encKeyFilename string, encKeyIndex int,
+ hdrPad int, imagePad int, sectionString string, useLegacyTLV bool)
error {
+
+ sections, err := imageSections(t, sectionString)
+ if err != nil {
+ return err
+ }
+
popts, err := OptsFromTgtBldr(t, ver, sigKeys, encKeyFilename,
encKeyIndex,
hdrPad, imagePad, sections, useLegacyTLV)
if err != nil {
diff --git a/newt/toolchain/compiler.go b/newt/toolchain/compiler.go
index d1590200..f22f671e 100644
--- a/newt/toolchain/compiler.go
+++ b/newt/toolchain/compiler.go
@@ -87,6 +87,8 @@ type Compiler struct {
odPath string
osPath string
ocPath string
+ nmPath string
+ a2lPath string
ldResolveCircularDeps bool
ldMapFile bool
ldBinFile bool
@@ -144,6 +146,24 @@ func (c *Compiler) GetSizePath() string {
return c.osPath
}
+func (c *Compiler) GetNmPath() string {
+ return c.nmPath
+}
+
+func (c *Compiler) GetAddr2linePath() string {
+ return c.a2lPath
+}
+
+// Returns path of binutils tool with given name that belongs to the same
+// toolchain as objdump, e.g. arm-none-eabi-objdump -> arm-none-eabi-nm.
+func siblingToolPath(odPath string, tool string) string {
+ if strings.HasSuffix(odPath, "objdump") {
+ return strings.TrimSuffix(odPath, "objdump") + tool
+ }
+
+ return "arm-none-eabi-" + tool
+}
+
func (c *Compiler) GetLdResolveCircularDeps() bool {
return c.ldResolveCircularDeps
}
@@ -389,6 +409,18 @@ func (c *Compiler) load(compilerDir string, buildProfile
string, cfg *cfgv.Setti
c.ocPath, err = yc.GetValString("compiler.path.objcopy", settings)
util.OneTimeWarningError(err)
+ c.nmPath, err = yc.GetValString("compiler.path.nm", settings)
+ util.OneTimeWarningError(err)
+ if c.nmPath == "" {
+ c.nmPath = siblingToolPath(c.odPath, "nm")
+ }
+
+ c.a2lPath, err = yc.GetValString("compiler.path.addr2line", settings)
+ util.OneTimeWarningError(err)
+ if c.a2lPath == "" {
+ c.a2lPath = siblingToolPath(c.odPath, "addr2line")
+ }
+
c.lclInfo.Cflags = loadFlags(yc, settings, "compiler.flags", cfg)
c.lclInfo.CXXflags = loadFlags(yc, settings, "compiler.cxx.flags", cfg)
c.lclInfo.Lflags = loadFlags(yc, settings, "compiler.ld.flags", cfg)