gnu/gcc/619a5e5586759a3ed16baf1333728664b06b0451 driver: Spill long COLLECT_GCC_OPTIONS to a response file [PR111527]
Many kernels enforce a per-string length limit on argv and envp
strings passed to execve(). On Linux, MAX_ARG_STRLEN limits each
string to 32 * PAGE_SIZE (~128KB); Windows limits individual
environment variables to 32767 characters. When the assembled
value exceeds such a limit, the build fails.
When the assembled value would exceed COLLECT2_OPTIONS_MAX_LENGTH
(default 1024, host-overridable via defaults.h), the driver writes
the option list to a temporary response file via writeargv() and
exports "COLLECT_GCC_OPTIONS=@<path>" instead. collect2,
lto-wrapper and lto-plugin transparently expand the @file form using
existing expandargv() infrastructure, so the change is invisible to
normal builds.
Bootstrapped and regression tested on x86_64-pc-linux-gnu.
PR driver/111527
gcc/ChangeLog:
* defaults.h (COLLECT2_OPTIONS_MAX_LENGTH): New macro.
* collect-utils.cc (read_collect_gcc_options): New function.
* collect-utils.h (read_collect_gcc_options): Declare.
* collect2.cc (main): Use read_collect_gcc_options instead
of getenv.
* doc/hostconfig.texi (Host Misc): Document
COLLECT2_OPTIONS_MAX_LENGTH.
* doc/invoke.texi (Environment Variables): Document the
@file form of COLLECT_GCC_OPTIONS.
* gcc.cc (xsetenv_collect_gcc_options): New function.
(set_collect_gcc_options): Use xsetenv_collect_gcc_options.
* lto-wrapper.cc (run_gcc): Use read_collect_gcc_options
instead of getenv.
gcc/testsuite/ChangeLog:
* gcc.misc-tests/pr111527.exp: New test.
include/ChangeLog:
* libiberty.h (expandargstr): Declare.
libiberty/ChangeLog:
* argv.c (expandargstr): New function.
lto-plugin/ChangeLog:
* lto-plugin.c (read_collect_gcc_options): New function.
(onload): Use read_collect_gcc_options instead of getenv.
Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
12 files changed