On Thursday 04 December 2025 09:32:44 Peter Damianov wrote:
> This patch adds support for compiling Windows resource files
> (.rc) and pre-compiled resource files (.res) directly through the
> GCC driver on PECOFF targets.
>
> Previously, users had to manually invoke windres to compile resource
> files before linking:
>
> windres -o resource.o resource.rc
> gcc main.c resource.o -o program.exe
>
> With this patch, GCC can handle resource files automatically:
>
> gcc main.c resource.rc -o program.exe
> gcc main.c resource.res -o program.exe
>
> Now, for an explanation of each line of the spec:
>
> If any of -E -M or -MM were passed, do nothing. No object files are output.
> "%{!E:%{!M:%{!MM:windres \
>
> For multilib configurations, tell windres to write out the correct COFF format
> %{m32:--target=pe-i386} %{m64:--target=pe-x86-64} \
>
> Pass through -I -D -U on to windres, because it supports them.
> %{I*:-I%*} %{D*:-D%*} %{U*:-U%*} \
>
> If -c is passed, pass through -o to windres, if it was specified. Otherwise,
> output to the input basename with .o suffix. Else, output to a
> temp file that will be deleted after linking.
> %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O} %i}}}",
Hello, what about always passing the "-O coff" parameter to windres?
Just in case if user call gcc with "-o file.ext" parameter and the "ext"
is something not automatically detected as object coff file by windres.
And also what about always passing the "-J" parameter to windres? To
ensure that no autodetection of input file type is done by windres.
> gcc/ChangeLog:
>
> PR driver/108866
> * gcc.cc (default_compilers): Add EXTRA_DEFAULT_COMPILERS so the config
> of a target can add an extra compiler spec to default_compilers.
> * config/i386/cygming.h: Add EXTRA_DEFAULT_COMPILERS spec for windres.
> * config/aarch64/cygming.h: Likewise.
>
> Signed-off-by: Peter Damianov <[email protected]>
> ---
> v3: Remove -m64 from aarch64, it doesn't exist.
>
> gcc/config/aarch64/cygming.h | 10 ++++++++++
> gcc/config/i386/cygming.h | 11 +++++++++++
> gcc/gcc.cc | 5 +++++
> 3 files changed, 26 insertions(+)
>
> diff --git a/gcc/config/aarch64/cygming.h b/gcc/config/aarch64/cygming.h
> index 1c7f8f58e64..d26d65684a5 100644
> --- a/gcc/config/aarch64/cygming.h
> +++ b/gcc/config/aarch64/cygming.h
> @@ -254,4 +254,14 @@ still needed for compilation. */
> #undef TARGET_ASM_LTO_END
> #define TARGET_ASM_LTO_END mingw_pe_asm_lto_end
>
> +/* Support for Windows resource files. */
> +#define EXTRA_DEFAULT_COMPILERS \
> + {".rc", "@windres", 0, 0, 0}, \
> + {".res", "@windres", 0, 0, 0}, \
> + {"@windres", \
> + "%{!E:%{!M:%{!MM:windres \
> + %{I*:-I%*} %{D*:-D%*} %{U*:-U%*} \
> + %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O} %i}}}", \
> + 0, 0, 0},
> +
> #endif
> diff --git a/gcc/config/i386/cygming.h b/gcc/config/i386/cygming.h
> index 0a3173c4e93..23077f4fd52 100644
> --- a/gcc/config/i386/cygming.h
> +++ b/gcc/config/i386/cygming.h
> @@ -474,3 +474,14 @@ do { \
> (ix86_cmodel == CM_LARGE_PIC || ix86_cmodel == CM_MEDIUM_PIC)
>
> #define HAVE_64BIT_POINTERS TARGET_64BIT_DEFAULT
> +
> +/* Support for Windows resource files. */
> +#define EXTRA_DEFAULT_COMPILERS \
> + {".rc", "@windres", 0, 0, 0}, \
> + {".res", "@windres", 0, 0, 0}, \
> + {"@windres", \
> + "%{!E:%{!M:%{!MM:windres \
> + %{m32:--target=pe-i386} %{m64:--target=pe-x86-64} \
> + %{I*:-I%*} %{D*:-D%*} %{U*:-U%*} \
> + %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O} %i}}}", \
> + 0, 0, 0},
> diff --git a/gcc/gcc.cc b/gcc/gcc.cc
> index b5d0f759f14..bfe262bdc2d 100644
> --- a/gcc/gcc.cc
> +++ b/gcc/gcc.cc
> @@ -1517,6 +1517,11 @@ static const struct compiler default_compilers[] =
> #endif
> , 0, 0, 0},
>
> +#ifndef EXTRA_DEFAULT_COMPILERS
> +#define EXTRA_DEFAULT_COMPILERS
> +#endif
> + EXTRA_DEFAULT_COMPILERS
> +
> #include "specs.h"
> /* Mark end of table. */
> {0, 0, 0, 0, 0}
> --
> 2.47.3
>