Find the compiler error before the final make failure
The end of an OpenWrt build log often contains a cascade of make[...] Error lines. The final line usually reports only that a parent target failed; it may not contain the header, symbol, or option first rejected by the compiler. Before repeating a complete world build, rebuild only the failed target with verbose logging and preserve the full output.
tools/elfutils is a build-host tool stage, not a runtime package for the target router. Host compiler state, prerequisites, source revision, and stale build artifacts therefore come before a target-device package hypothesis.
Build a reproducible baseline
| Baseline | Value to retain | Reason |
|---|---|---|
| Source | Branch, commit, and git status | Do not combine failures from different revisions. |
| Host | Distribution, compiler, and prerequisites | Make the build-host combination reproducible. |
| Config | Diffconfig and target | Preserve selections without publishing the full .config. |
| Feeds | Update and install time plus changes | Freeze the source-tree and feed combination. |
| First error | First compiler or configure failure with context | Investigate the cause rather than parent make failures. |
umask 077
DIAG_DIR=$(mktemp -d "${TMPDIR:-/tmp}/elfutils-diag.XXXXXXXX") || exit 1
git status --short
git rev-parse HEAD
test -f .config || exit 1
cp -p .config "$DIAG_DIR/config-before" || exit 1
./scripts/diffconfig.sh >"$DIAG_DIR/diffconfig-before.txt" || exit 1
gcc --version
# Do not run make defconfig just to capture the current failure.
OpenWrt documentation says to build as an unprivileged user without sudo and to avoid spaces in the build path. Mixed source-tree ownership or a network filesystem that does not preserve Unix permissions can produce additional failures, so record path and permission context as well.
Clean only the target and rebuild verbosely
make -j1 tools/elfutils/clean V=s >"$DIAG_DIR/clean.log" 2>&1 || exit 1
# Bash; keep full build output private.
set -o pipefail
set +e
make -j1 tools/elfutils/compile V=s 2>&1 | tee "$DIAG_DIR/elfutils-build.log" >/dev/null
build_status=("${PIPESTATUS[@]}")
printf 'make=%s tee=%s\n' "${build_status[0]}" "${build_status[1]}"
if (( build_status[0] != 0 || build_status[1] != 0 )); then
printf '%s\n' 'STOP: inspect the private log; build did not succeed' >&2
exit 1
fi
Capture make and tee exit codes through PIPESTATUS immediately after the Bash pipeline. A saved tee log does not prove make succeeded. On failure, inspect the first compiler error and context in the private log. -j1 narrows output interleaving; it does not fix a compiler defect. A synthetic make exit 7 with tee exit 0 was checked to stop the shell flow; no real OpenWrt build was reproduced.
Let the first error define the scope
- A host header or library is missing: use the build-system setup page for the active OpenWrt branch and host distribution. Package names differ among distributions and releases.
- The compiler rejects an option: compare the host compiler version with the source branch’s supported environment. Removing the option blindly can produce an invalid tool in a later stage.
- A download or checksum fails: do not classify it as a compiler problem. Inspect the URL, download cache, proxy, and storage separately.
- Stale objects are suspected: clean
tools/elfutilsfirst. Broad removal of the toolchain and configuration is a last resort. - Local source modifications exist: preserve
git statusand the diff. Compare with a clean checkout in another worktree without deleting the original changes.
Do not move feeds and configuration at the same time
OpenWrt documents updating and installing feeds, then using make defconfig to reconcile old configuration. During diagnosis, however, changing the branch, feeds, host packages, and config together destroys causality. Preserve the current failure first and change one layer at a time.
# Separate change after preserving the original failure and feed revisions.
./scripts/feeds update -a || exit 1
./scripts/feeds install -a || exit 1
make defconfig || exit 1
# Bash; keep full build output private.
set -o pipefail
set +e
make -j1 tools/elfutils/compile V=s 2>&1 | tee "$DIAG_DIR/elfutils-build-after.log" >/dev/null
build_status=("${PIPESTATUS[@]}")
printf 'make=%s tee=%s\n' "${build_status[0]}" "${build_status[1]}"
if (( build_status[0] != 0 || build_status[1] != 0 )); then
printf '%s\n' 'STOP: inspect the private log; build did not succeed' >&2
exit 1
fi
Know the boundary of dirclean and distclean
make dirclean removes build tools and the toolchain broadly. make distclean removes still more state, including configuration and feeds. OpenWrt describes distclean as close to a factory reset of the build system. Running it before preserving diffconfig, patches, download state, and logs erases diagnostic evidence.
Plan a broader clean only after targeted clean, prerequisite correction, and same-revision reproduction fail. Keep commit and diffconfig identical across the comparison so stale-artifact effects can be measured.
Define success precisely
A successful tools/elfutils/compile proves that host-tool stage, not the complete firmware build. If another target fails in the later world build, treat its first error as a new branch. Redact home paths, tokens in feed URLs, and private repository addresses before sharing logs.
Compare the current diffconfig with diffconfig-before.txt after success. An image file alone does not prove that the intended target profile and package selections remained unchanged.
Related guides
Official references
- OpenWrt build instructions – official prerequisites and the basic build sequence
- OpenWrt host build rules – the actual prepare, configure, and compile rules for host tools
- OpenWrt tools/elfutils source – current build-tool definition and source revision
- OpenWrt top-level Makefile – top-level build targets and include structure
Earlier verification notes preserved from this article
Verification level: official documentation checked
OpenWrt target builds, verbose logging, and cleanup scope were checked against official documentation. No particular compiler failure was reproduced, so the guide does not claim one elfutils root cause or patch.