feat: restrict //export different symbol names to baremetal targets only

- Modified cl/import.go to check LLGO_TARGET_BAREMETAL env var
- For baremetal targets: //export SymbolName allows different export name (TinyGo-style)
- For normal targets: //export SymbolName uses SymbolName as function name (standard Go)
- Set LLGO_TARGET_BAREMETAL=1 in internal/build/build.go when baremetal tag present
- Added test for normal targets in _demo/normal/export/
- Added CI test to verify both embedded and normal target behavior

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
This commit is contained in:
xgopilot
2025-11-03 06:20:42 +00:00
parent 3348b645af
commit 940c6f7625
5 changed files with 146 additions and 3 deletions

View File

@@ -317,14 +317,20 @@ func (p *context) initLinkname(line string, f func(inPkgName string) (fullName s
// format: //export ExportName or //export FuncName ExportName
exportName := strings.TrimSpace(line[len(export):])
var inPkgName string
isBaremetal := os.Getenv("LLGO_TARGET_BAREMETAL") == "1"
if idx := strings.IndexByte(exportName, ' '); idx > 0 {
// format: //export FuncName ExportName (go-style)
inPkgName = exportName[:idx]
exportName = strings.TrimLeft(exportName[idx+1:], " ")
} else {
// format: //export ExportName (tinygo-style)
// use empty string to match any function
inPkgName = ""
// format: //export ExportName (tinygo-style, only for baremetal targets)
if !isBaremetal {
// For non-baremetal targets, treat as function name (standard Go behavior)
inPkgName = exportName
} else {
// For baremetal targets, use empty string to match any function
inPkgName = ""
}
}
if fullName, _, ok := f(inPkgName); ok {
p.prog.SetLinkname(fullName, exportName)