* fix(bflt): reject relocation ranges before data * docs(bflt): clarify unavailable relocation counts * fix(bflt): reject relocation tables overlapping initialized data --------- Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com> Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
7.4 KiB
uClinux bFLT flat executables
inspect-artifact and extract-artifact recognize a uClinux flat executable
by its bFLT magic, regardless of filename. These files come from no-MMU
embedded Linux systems (Cortex-M, ColdFire, Blackfin, RISC-V nommu). The
reader works on local bytes only: it does not run the program or apply its
relocations, and it does not change the file.
The root is an archive with unknown executable architecture. The flat header does not name a CPU, so the target architecture must come from elsewhere, such as the firmware image or the kernel configuration.
Header facts
The 64-byte header is big-endian. Its offsets count from the start of the
file as the loader sees it, header included. The root format_metadata
(kind: "bflt") reports:
| Field | Meaning |
|---|---|
revision |
4 (FLAT_VERSION) or 2 (OLD_FLAT_VERSION); others are kept |
entry |
Offset of the first instruction |
data_start, data_end, bss_end |
Segment boundaries; text_size, data_size, bss_size follow |
stack_size |
Requested stack size |
reloc_start, reloc_count |
Relocation table position and entry count |
flags, flag_names, unknown_flags |
ram, gotpic, gzip, gzdata, ktrace, l1stk; other bits stay in unknown_flags |
build_date, build_date_iso |
Revision 4 build time, or null when zero |
compression, inflated_bytes |
none, gzip or gzdata, and the inflated body size |
relocations, relocations_truncated |
The first 64 relocation offsets |
out_of_range_relocation_count |
Revision 4 entries past the end of bss, measured from the byte after the header; null for revision 2, when entries exist but that end is not established, or when entries exist but the table is not read (it starts before data_end, runs past the image, or the gzip body cannot be inflated) |
Segments
Each segment is one extractable entry (kind: "bflt-segment"):
text.bin: image bytes[0, data_start), header included.entryis a file offset into this image. Revision 4 relocation offsets count from the first byte after the header, and the loader accepts them through the end of bss. For ARM M-profile targets, open it asraw-binarywitharchitecture: "arm", anarchitecture_variant,base_addressat the load base andentry_pointat that base plusentry; for other CPUs,raw-binarymaps offset 0 atentry_pointand starts analysis in the header rather than atbase + entry.data.bin:[data_start, data_end).relocations.bin: the complete relocation table,reloc_countbig-endian 32-bit values. Revision 4 values are offsets from the first byte after the header.
Stored segments keep their file range as source_location. Segments that
exist only after inflation have no file range; image_offset gives their
position in the inflated image.
Compressed bodies
With gzip, everything after the header is one gzip stream. With gzdata,
text is stored and the stream starts at data_start. Revision 2 loaders
ignore these flags, so a revision 2 body is always read as stored. The reader
inflates the stream in memory under artifact_limits.expanded_bytes (by
default 500 times the file size, at least 256 MiB), capped at a fixed 128 MiB
in-memory inflation ceiling. When the stream exceeds the active limit or cannot
be inflated, the header facts are still reported, coverage is unknown, a
limitation names the cause, and the stored bytes are served as
compressed-body.gz (plus text.bin for gzdata).
Limits and limitations
The reader admits files up to a fixed 128 MiB, as the DfuSe and Intel HEX readers do. Only a missing magic or a header shorter than 64 bytes refuses the file. Other problems become limitations beside the facts that still hold:
- an unknown revision, reported with the revision 4 layout;
- revision 2, whose loaders ignore stored flags and whose relocation entries pack a segment type beside an offset whose bit order and base segment depend on the target CPU; entries are listed as stored and not range-checked;
- inconsistent
data_startanddata_end, which leaves both segments unavailable; - a data segment past the image, which leaves coverage unknown. A complete
code segment is still available as
text.bin; - an entry point outside text, or
bss_endbeforedata_end; - a relocation table starting before the end of the data segment or ending past the image leaves coverage unknown. Complete text and data segments remain available;
- more than 64 relocations, where the inline list is truncated and
relocations.binkeeps the full table.