Sym2srec is a command-line tool that extracts the .symtab and .strtab sections
from an ELF32 executable and embeds them as loadable segments into a new S-Record file.
It is used as part of the Mk build pipeline to enable dynamic loading: external applications can reference Mk kernel symbols at runtime without statically linking against the kernel. A GNU hash table is also generated alongside the symbol tables to accelerate symbol resolution.
make all (Mk)
├── Link → Mk.elf (firmware + full debug symbol table)
├── Strip → Mk-Strip.elf (debug symbols removed, only exported API symbols kept)
└── sym2srec Mk-Strip.elf Mk.srec 0x002C0000
└── Mk.srec (firmware + Mk API symbol table → only file to flash)
Mk.srec is the only file written to the target. It encodes both the firmware binary and
the kernel symbol table with their target addresses. Mk.elf is preserved intact and
loaded in Eclipse/GDB as the debug symbol file.
sym2srec <input.elf> <output.srec> <base_address>
| Argument | Description |
|---|---|
input.elf |
ELF32 executable containing the symbols to export. |
output.srec |
Path of the S-Record file to generate. |
base_address |
Address where the symbol table will be loaded in memory. Must be 4-byte aligned, 8 hex digits (e.g. 0x002C0000). |
Example:
sym2srec Mk-Strip.elf Mk.srec 0x002C0000
Before running sym2srec, strip local and debug symbols from the input ELF to keep only the exported API symbols in the generated symbol table:
arm-none-eabi-strip --discard-all --strip-debug Mk.elf -o Mk-Strip.elf
After cloning the repository, mark the prebuilt binary as executable before use:
chmod +x Mk/Make/sym2srecGit does not always preserve executable permissions after a clone or checkout. Run this command once after cloning the repository.
For a detailed description of the symbol resolution protocol (bloom filter, GNU hash table lookup, relocation), see the wiki.
Prebuilt executables for Windows and Linux are available in the Releases section of this repository. Build from source only if you need to modify the tool.
sym2srec must be compiled as a 32-bit binary (-m32) because it directly maps ELF32
structures to C structs. Compiling as 64-bit would produce incorrect pointer sizes and
struct layouts, causing silent data corruption at runtime.
- GCC 15.2.0 (POSIX threads) + MinGW-w64 13.0.0 UCRT (release 6)
- GNU Make 4.3
- One of the following Unix shell environments (provides
sh,find,rm):- MSYS2 (recommended)
- Git for Windows
The Makefile automatically detects MSYS2 or Git Bash at their default installation paths (
C:/msys64andC:/Program Files/Git). If your installation is elsewhere, updateMSYS2_BINorGITBASH_BINat the top ofsym2srec/make/makefile.
Steps:
- Set
MINGW_PATHinsym2srec/make/makefileto your MinGW-w64bin/directory. - Build:
make clean
make all- GCC (system) with 32-bit multilib support
- GNU Make 4.3
Install the 32-bit build dependencies before building:
sudo apt-get install gcc-multilib g++-multilibSteps:
make clean
make all| Platform | Tool | Version |
|---|---|---|
| Windows | gcc (MinGW) |
15.2.0 POSIX (WinLibs) |
| Windows | make |
GNU Make 4.3 |
| Linux | gcc |
system GCC with gcc-multilib |
| Linux | make |
GNU Make 4.3 |
Every push and pull request is automatically built by GitHub Actions.
The workflow installs the required dependencies, runs make all,
and uploads sym2srec as a downloadable build artifact.
The latest successful build artifact is available on the Actions tab of this repository.
Copyright © 2024 Mathieu Renard. All rights reserved.
This project is licensed under the BSD 3-Clause License — see the LICENSE.txt file for details.