#1671·mold

Single-dash long options are read as a short option with an attached value

Author: lu-zeroCreated Sep 22, 2026Updated Sep 23, 2026

Summary

mold reads some single-dash long options as a short option with an attached value, where GNU ld and lld read the long option. The result is silent: a wrong entry symbol, a bogus dynamic entry, or an input file that disappears.

bash
$ ld.bfd -nostdlib t.o -o out -entry=main     # entry = main
$ ld.lld -nostdlib t.o -o out -entry=main     # entry = main
$ mold    -nostdlib t.o -o out -entry=main
mold: warning: entry symbol is not defined: ntry=main

mold reads -entry=main as -e ntry=main, because parse_args tries options in the order it lists them and -e comes first.

Affected options

command line GNU ld and lld mold
-entry=main --entry=main -e ntry=main, entry symbol undefined
-eh-frame-hdr --eh-frame-hdr -e h-frame-hdr
-enable-new-dtags --enable-new-dtags -e nable-new-dtags
-error-unresolved-symbols --error-unresolved-symbols -e rror-unresolved-symbols
-end-group --end-group -e nd-group
-filter libf.so DT_FILTER -f ilter, then libf.so is an input file: mold: fatal: cannot open libf.so
-fix-cortex-a53-835769, -fix-cortex-a53-843419 the erratum workaround -f ix-..., leaving DT_AUXILIARY [ix-cortex-a53-843419] in the output and no workaround applied

A related one, independent of the dash rule: --thinlto-index-only takes the next argument as its value, but in lld it is a flag, or takes a file after =. mold --thinlto-index-only a.o -o out consumes a.o and then fails with -m option is missing.

Where this shows up

Compiler drivers use the double-dash spellings on common targets, which is presumably why nobody has hit it. It shows up where a toolchain or a build writes the single-dash form, which GNU ld documents as equivalent:

  • GCC's s390 TPF spec passes it directly: #define ENTRY_SPEC "%{mmain:-entry=_start} %{!mmain:-entry=0}" (gcc/config/s390/tpf.h). mold supports s390x, so on that target every link gets an undefined entry symbol and the default entry point.
  • GCC's microblaze config and newlib's libgloss specs emit -start-group ... -end-group. -start-group is harmless (-s takes no value), but -end-group is read as -e nd-group.
  • Hand-written embedded and bare-metal builds that use -Wl,-entry=_start or -Wl,-eh-frame-hdr. A wrong entry point on a microcontroller means it does not boot.
  • -Wl,-fix-cortex-a53-843419 is the quietest: no diagnostic at all, a DT_AUXILIARY entry the loader will try to resolve, and no erratum workaround.

Cause

match_option plus the order of the if/else chain in parse_args. GNU ld tries a single-dash token as a long option first and only then as a short one with an attached value (getopt_long_only), keeping a per-option list of names that need two dashes (EXACTLY_TWO_DASHES in ld/lexsup.c), and rewriting -lX to --library=X beforehand. lld has the same kind of per-option rule (F/J/Eq/B accept one dash, FF/JJ/EEq/BB do not).

This is not a regression from the Rust rewrite: mold 2.41 (C++) behaves identically, and the last C++ src/cmdline.cc has the same match_option and first-match read_arg. #216 was the same class of bug in 2021.

Fix

PR #1670 matches each token without attached short values first, retry with them only if nothing names the token, and keep a small list of options that GNU ld or lld also reads as a short plus a value.