diff --git a/esphome/components/libretiny/patch_linker.py.script b/esphome/components/libretiny/patch_linker.py.script index 0be4df0a33..183759559a 100644 --- a/esphome/components/libretiny/patch_linker.py.script +++ b/esphome/components/libretiny/patch_linker.py.script @@ -114,7 +114,11 @@ def _post_link(target, source, env): elf = env.subst("$BUILD_DIR/${PROGNAME}.elf") if not os.path.isfile(elf): return - nm = env.subst("$NM") or env.subst("${TOOLCHAIN_PREFIX}nm") + # $NM may be unset; derive from $CC (e.g. arm-none-eabi-gcc -> arm-none-eabi-nm). + nm = env.subst("$NM") + if not nm: + cc = env.subst("$CC") + nm = cc.replace("-gcc", "-nm") if cc.endswith("-gcc") else "nm" try: out = subprocess.check_output( [nm, "--defined-only", "--demangle", elf], text=True