cl,build: support //export with different names on embedded targets

Add support for using different C symbol names in //export directives
when compiling for embedded targets (enabled via -target flag).

This is for TinyGo compatibility on embedded platforms where hardware
interrupt handlers often require specific naming conventions.

Implementation:
- Add EnableExportRename() to control export rename behavior
- Add isExport parameter to initLink callback for context awareness
- Update initLinknameByDoc() to handle export rename logic:
  * When isExport && enableExportRename: allow different names
  * Otherwise: require name match
- Clean error handling in initLink():
  * export + enableExportRename: silent return (already processed)
  * export + !enableExportRename: panic with clear error message
  * other cases: warning for missing linkname

Example:
  //export LPSPI2_IRQHandler
  func interruptLPSPI2() { ... }

The Go function is named interruptLPSPI2 but exported as
LPSPI2_IRQHandler for the hardware vector table.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
luoliwoshang
2025-11-10 18:52:36 +08:00
parent 742bfd95a2
commit dac3365c73
3 changed files with 29 additions and 6 deletions

View File

@@ -53,6 +53,11 @@ var (
enableDbg bool
enableDbgSyms bool
disableInline bool
// enableExportRename enables //export to use different C symbol names than Go function names.
// This is for TinyGo compatibility when using -target flag for embedded targets.
// Currently, using -target implies TinyGo embedded target mode.
enableExportRename bool
)
// SetDebug sets debug flags.
@@ -73,6 +78,12 @@ func EnableTrace(b bool) {
enableCallTracing = b
}
// EnableExportRename enables or disables //export with different C symbol names.
// This is enabled when using -target flag for TinyGo compatibility.
func EnableExportRename(b bool) {
enableExportRename = b
}
// -----------------------------------------------------------------------------
type instrOrValue interface {