mirror of
https://github.com/esphome/esphome.git
synced 2026-08-22 22:26:21 +00:00
Quote an overridden ldscript name on the link line; note the deliberate board-derived --flash_size
The -T script name was the one user-controlled token on the link line that skipped shell_token, so a space or dollar sign in a board_build.ldscript override corrupted the emitted linkflags. The elf2bin comment now records that --flash_size deliberately stays board-derived, matching PlatformIO (which reads upload.maximum_size, not the ldscript).
This commit is contained in:
@@ -791,7 +791,8 @@ def write_project(paths: InstalledPaths, ccache: str | None) -> bool:
|
||||
link_flags += project_link_flags
|
||||
link_flags += [_shell_token(flag) for lib in libraries for flag in lib.link_flags]
|
||||
flash_ld = _active_flash_ld_name(flash_ld_name)
|
||||
link_flags += ["-T", flash_ld]
|
||||
# A user-overridden script name re-quotes like every other user token
|
||||
link_flags += ["-T", _shell_token(flash_ld)]
|
||||
|
||||
lib_dirs = [Path("ld"), sdk / "lib", sdk / "ld", sdk / "lib" / config.nonosdk]
|
||||
lib_dirs += project_lib_dirs
|
||||
@@ -850,7 +851,9 @@ def write_project(paths: InstalledPaths, ccache: str | None) -> bool:
|
||||
" description = LINK $out",
|
||||
"rule elf2bin",
|
||||
# --flash_freq 40: every supported board's f_flash is 40 MHz;
|
||||
# re-check on a platform bump
|
||||
# re-check on a platform bump. --flash_size deliberately stays
|
||||
# board-derived, as under PlatformIO (which reads
|
||||
# upload.maximum_size, not the ldscript).
|
||||
f" command = $python {_q(framework / 'tools' / 'elf2bin.py')} --eboot {_q(framework / 'bootloaders' / 'eboot' / 'eboot.elf')} --app $in --flash_mode {esp8266_data[KEY_FLASH_MODE]} --flash_freq 40 --flash_size {_flash_size_str(BOARDS[board][KEY_FLASH_SIZE])} --path {_q(toolchain_bin)} --out $out",
|
||||
" description = BIN $out",
|
||||
"rule copy",
|
||||
|
||||
@@ -1342,3 +1342,14 @@ def test_flash_ld_name_honors_ldscript_override(tmp_path: Path) -> None:
|
||||
CORE.platformio_options = {"board_build.ldscript": "../evil.ld"}
|
||||
with pytest.raises(EsphomeError, match="bare script name"):
|
||||
arduino8266._flash_ld_name("nodemcuv2")
|
||||
|
||||
|
||||
def test_write_project_quotes_spaced_ldscript_override(tmp_path: Path) -> None:
|
||||
"""An overridden script name re-quotes on the link line like every other
|
||||
user token (a space would otherwise split into two argv elements)."""
|
||||
CORE.platformio_options = {"board_build.ldscript": "my script.ld"}
|
||||
paths = _make_framework(tmp_path)
|
||||
_set_flags()
|
||||
content = _write_ninja(paths)
|
||||
assert "'my script.ld'" in content or '"my script.ld"' in content
|
||||
assert "-T my script.ld" not in content
|
||||
|
||||
Reference in New Issue
Block a user