DevNews

Mold 2.42: correct metadata matters as much as speed

On this page
  1. The release changes
  2. A four-byte requirement cannot survive at any address
  3. Unwind information must follow surviving code

A linker can produce a smaller executable that is still wrong. Mold 2.42’s useful story is how code removal, folding and metadata must stay consistent.

Simplified alignment example: a merged output retaining a four-byte requirement cannot start at 0x1002 (remainder 2), but 0x1004 satisfies it (remainder 0). Matching instruction bytes alone do not establish safe folding. Not a mold test output.
Simplified alignment example: a merged output retaining a four-byte requirement cannot start at 0x1002 (remainder 2), but 0x1004 satisfies it (remainder 0). Matching instruction bytes alone do not establish safe folding. Not a mold test output. Chart : PeopleAreGeek. Data source.
View full-size image

The release changes

The 2.42.0 notes add SFrame v3 processing, Android packed relocations and selectable debug-compression levels. They also fix identical-code-folding issues involving exception behavior, preemptible symbols and alignment. The project reports performance improvements, but this article does not supply a measured build-time comparison.

These features operate at different layers. Relocation packing needs a loader that understands the format. Debug compression changes stored debugging data. Folding decides whether separate code sections may share an implementation. A successful link does not make those concerns interchangeable.

A four-byte requirement cannot survive at any address

Our simplified example has two candidate functions with matching instruction bytes. One requires four-byte alignment. If they are combined, an output address of 0x1002 fails that requirement because its remainder on division by four is two. 0x1004 satisfies it.

That arithmetic does not model all of mold’s equivalence checks. It isolates one reason “same instructions” is insufficient: the surviving placement must satisfy the relevant constraints of the combined inputs. Exception metadata and symbol interposition introduce other distinctions even before considering alignment.

The cover shows the two candidate addresses and the common requirement. It is an explanatory calculation, not an executable generated by our own mold test.

Unwind information must follow surviving code

SFrame support in this release processes entries when functions are removed or folded and builds an output ordered by function address. Think of an index into a book: removing or moving a chapter requires updating the index, even if every remaining chapter’s text is unchanged. Copying the old index verbatim would leave references to the wrong places.

For a toolchain update, validate the final artifact as well as the time spent linking. Exercise stack traces, exception behavior and any post-link tooling your build uses. For Android relocation packing, include the intended loader and supported Android environment in the compatibility test.

Compare the same inputs, compiler options and linker flags when timing builds. A smaller debug artifact may be useful even if compression takes longer; a faster link is not an acceptable trade for changed program behavior. Choose the measurement that matches the artifact you actually ship.

Explain linker metadata and alignment correctness; scope packed relocations to compatible loaders and avoid unmeasured speed claims.