Skip to content

fix: statically link build.mcpp host helpers with musl toolchains #295

Description

@wellwei

Reproduction

On a fresh Ubuntu 24.04 ARM64 host, mcpp selects gcc@15.1.0-musl as the native toolchain. A project containing even this minimal build program fails:

#include <cstdio>
int main() {
    std::puts("build helper ran");
    return 0;
}
build.mcpp compiling
build.mcpp running
build.mcpp exited with 127

readelf shows target/.build-mcpp/build.mcpp.bin is dynamically linked with interpreter /lib/ld-musl-aarch64.so.1. The glibc Ubuntu host does not provide that loader, and strace reports execve(.../build.mcpp.bin, ...) = -1 ENOENT.

Root cause

prepare.cppm correctly defaults musl project output to static linkage, but build_program.cppm constructs the host-helper link command independently and does not add -static. process.cppm then collapses the posix_spawnp error into exit 127 with empty output.

Expected behavior

  • A build program compiled with a musl host toolchain is fully static and runs without a host musl loader.
  • A posix_spawnp failure retains a useful error message instead of returning an unexplained empty exit 127.

Proposed fix

  • Add -static only to the final build.mcpp helper link when the resolved host toolchain targets musl.
  • Rev the build-program cache identity so older helper-link policy caches are invalidated.
  • Preserve the direct posix_spawnp error code and message in captured output.
  • Add native Ubuntu ARM64 fresh-install coverage that runs a minimal build.mcpp and asserts the helper has no PT_INTERP.

Environment

  • mcpp: 0.0.109
  • Host: Ubuntu 24.04 ARM64 (glibc)
  • Toolchain selected by mcpp: gcc@15.1.0-musl

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions