Skip to content

Conversation

@gabboclaa
Copy link

MacOS Troubleshooting - Rewrite section names macOS

Description

This PR introduces a cross-platform, rewrite step that normalizes section names inside the generated file: generated//static_parameters.zig

When XIP (Execute-In-Place) is enabled, the generated static_parameters.zig may contain Mach-O section names:

  • __DATA,__flash_weights
  • __TEXT,__const

These are valid only on macOS (Mach-O), but break builds when targeting boards.
This caused build/linker errors as soon as XIP was enabled on non-macOS platforms.

What this adds:
A small host-side tool (rewrite_sections.zig) that:

  • Scans static_parameters.zig.
  • Detects platform-specific section names.
  • Rewrites them into universally valid ELF-compatible names:
    - __DATA,__flash_weights → .flash_weight
    - __TEXT,__const → .rodata
  • A clean and isolated build step integrated into build.zig, placed after codegen and before static library compilation.
  • The tool automatically inherits the correct optimization mode and runs only when XIP is enabled, preserving performance and build determinism.

Type of Change

Please mark the options that are relevant:

  • Bug fix 🐛
  • New feature 🚀
  • Documentation update 📚
  • Other (please describe):

Checklist

  • My code follows the project's coding style guidelines.
  • I have performed a self-review of my own code.
  • All existing tests pass.

Testing

The idea was simple:

  • When XIP is enabled + target is ELF → rewrite must run
  • Otherwise → rewrite step must be skipped and nothing changes
    So I tested the two scenarios and the rewrite step works as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant