diff --git a/extra_scripts/ld_response_file.py b/extra_scripts/ld_response_file.py
new file mode 100644
index 000000000..0b91cf862
--- /dev/null
+++ b/extra_scripts/ld_response_file.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python3
+# force linker response file instead of command line arguments
+
+Import("env")
+
+
+def wrap_with_tempfile(command_key):
+ command = env.get(command_key)
+ if not command or not isinstance(command, str):
+ return
+ if "TEMPFILE(" in command:
+ return
+ env.Replace(**{command_key: "${TEMPFILE('%s')}" % command})
+
+
+# Force SCons to spill long commands into response files on this target.
+env.Replace(MAXLINELENGTH=8192)
+
+for key in ("LINKCOM", "CXXLINKCOM", "SHLINKCOM", "SHCXXLINKCOM"):
+ wrap_with_tempfile(key)
diff --git a/variants/esp32p4/esp32p4.ini b/variants/esp32p4/esp32p4.ini
index f51ed1975..d33a93d84 100644
--- a/variants/esp32p4/esp32p4.ini
+++ b/variants/esp32p4/esp32p4.ini
@@ -15,6 +15,10 @@ build_flags =
build_src_filter =
${esp32_common.build_src_filter} - - - - - - -
+extra_scripts =
+ ${esp32p4_base.extra_scripts}
+ extra_scripts/ld_response_file.py
+
; Override esp32_common component pruning: keep esp_hosted + esp_wifi_remote for P4 hosted BT
custom_component_remove =
espressif/esp_modem