Skip to content

redo_main() calls abort() with no message for unsupported targets #1553

@karesansui-u

Description

@karesansui-u

Summary

When mold auto-detects a target architecture from ELF headers and the target is not compiled in, redo_main() in src/passes.cc:82 calls abort() with no diagnostic message. The user sees only Aborted (core dumped).

In contrast, when the same situation occurs via the -m flag (explicit target selection), parse_nonpositional_args() in src/cmdline.cc:763 provides a helpful error:

'-m arm64' is not supported; you may want to rebuild mold with ARM64LE support

Steps to reproduce

  1. Build mold with limited target support, e.g. -DMOLD_TARGETS='X86_64'
  2. Try to link an ARM64 ELF file without -m:
    mold -o out arm64_input.o
    
  3. Result: Aborted (core dumped) — no indication of what went wrong

With -m elf_aarch64, the same scenario produces a clear error message.

Root cause

redo_main() (src/passes.cc:21-83) iterates through all HAVE_TARGET_* configurations with if constexpr. If none match the auto-detected target, it falls through to abort() on line 82. Unlike the -m path, redo_main() does not have access to Context<E>, so it cannot use Fatal(ctx).

Suggested fix

Replace abort() with a diagnostic message via std::cerr and exit(1):

std::cerr << "mold: unsupported target: " << target
          << "; rebuild mold with the appropriate target support\n";
exit(1);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions