Repository navigation
from-elf: read memory regions from linker maps (--map) - #5
Merged
Merged
Conversation
`memmap from-elf firmware.elf --map firmware.map` takes the memory regions from the map file the linker writes, telling the format apart by its content: the Memory Configuration table of GNU ld, the execution regions of armlink (Keil), and the placement summary of IAR ILINK, whose unnamed ranges are called ROM, RAM or Memory by what is placed there. A --region with the id of a map region replaces it, and one with a new id adds a region. A map region that holds no section stays in memory without a column. memmap reads maps, not linker scripts, scatter files or .icf files, as a map holds what the linker worked out. When the map gives no region to draw, as an lld map, a GNU ld map without MEMORY or an armlink map without a scatter file does, and no --region stands in, from-elf writes nothing and exits 2. Its hint names the --region specs to give, and failures from from-elf now carry such hints in --json. Map regions left out, for no size, size 0, running past the address space, overlapping a --region or another map region, or being too small for a section, are noted in the config's header. New warning W112 reports each one whose loss changes the drawing, with the --region to give instead. A section across the edge of a map region leaves that region out rather than stopping the import. The from_elf module becomes a package, with the map readers in from_elf/linker. docs/elf-testing.md becomes docs/from-elf.md, which covers each toolchain's map, the limits, future ideas such as Rust and lld, and the tests. Tests: the readers on excerpts of 13 real GNU ld, armlink and IAR maps, against tests/golden/linker/regions.json; the fixture firmware with its own GNU ld map, which build.sh now writes; and synthetic cases for lld maps, missing sizes, overlaps, address-space edges and files that are not maps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
memmap from-elf firmware.elf --map firmware.mapnow takes the memory regions from the map file the linker writes, so most users no longer copyORIGINandLENGTHby hand.Maxas the size--region: a--regionwith a map region's id replaces it, and one with a new id adds a region.memorywithout a column.Why maps only
Linker scripts, scatter files and
.icffiles are not read. A map already holds what the linker worked out, including preprocessing,INCLUDEand--defsym. That keeps one small reader per toolchain instead of an expression evaluator. An earlier draft of this branch also readMEMORYblocks with--ldscript; it was removed before this PR to keep the tool simpler.When the map is not enough
MEMORYblock, or an armlink map without a scatter file, when no--regionstands in.from-elfwrites nothing and exits 2 (E090). The hint names the--regionspecs to give, such as--region er_ro=0x08000000:SIZE. Failures fromfrom-elfnow carry hints in--json.--regionor another map region, or being too small for a section. W112 fires only when the drawing loses something, and its hint gives the--regionto use. Every left-out region is also noted in the config's header.--region's edge still stops the import.For reviewers
memmap/from_elf.pyinto a package (importer,regions,writer,blocks,sizes,linker/). The ELF goldens intests/golden/elf/are unchanged, which shows the split kept the old behaviour.docs/elf-testing.mdis nowdocs/from-elf.md. It explains the feature in depth: each toolchain's map, a limits table, how sections become blocks, a Future ideas section (Rust and lld, armlink load regions, Arm Compiler 6, stable IAR ids), the tests, and the drawings. The README section is down to two commands and a link.memmap guideprints it unchanged.ramis the CCM andram_2the main SRAM.Tests
tests/golden/linker/regions.json.build.shnow writes. It gives the same config as the matching--regionspecs.--strictrunLocally,
uv run pytest(570 passed),uv run mypyanduv run ruff checkpass.🤖 Generated with Claude Code