binutils Newspaper
NOVEMBER 30, 2026
ld/pe — Proposed

ld/pe: only define target-specific variables when needed

Reduces unused global variable warnings in ld/pe by conditionally defining variables based on target.

This patch addresses compiler warnings about unused global variables in the PE (Portable Executable) object file format handling within the linker (ld). Specifically, support_old_code and thumb_entry_symbol are only relevant for ARM PE targets and are now conditionally defined. Similarly, image_base_statement is now only defined when DLL_SUPPORT is enabled. This change cleans up the codebase and resolves [-Wunused-but-set-global] errors reported by Clang.

In the Thread 1 participant
  1. Simon Marchi <simon.marchi@efficios.com> proposer

    Submits a patch to conditionally define target-specific variables in ld/pe to resolve unused variable compiler warnings.

    “Building ld with a recent clang fails with: ei386pe.c:122:12: error: variable 'support_old_code' set but not used [-Werror,-Wunused-but-set-global] ei386pe.c:123:15: error: variable 'thumb_entry_symbol' set but not used [-Werror,-Wunused-but-set-global] ei386pe_posix.c:124:40: error: variable 'image_base_statement' set but not used [-Werror,-Wunused-but-set-global] The same happens…”

In Details

This patch cleans up linker code for the PE object file format. It targets unused global variables that trigger [-Wunused-but-set-global] warnings from Clang. The variables support_old_code and thumb_entry_symbol are ARM-specific, while image_base_statement relates to DLL support. By wrapping their definitions within #if directives tied to TARGET_IS_armpe, TARGET_IS_arm_wince_pe, and DLL_SUPPORT respectively, the linker code becomes cleaner and avoids spurious warnings for non-applicable targets.

For Context
PE
Portable Executable, the file format used for executables, object code, and DLLs on 32-bit and 64-bit versions of Windows. It is also used by the linker for some embedded targets.
ld
The GNU linker, responsible for combining object files and libraries into an executable or shared library.
linker
A program that combines various pieces of code and data (from object files and libraries) into a single executable file.
global variable
A variable declared outside of any function, accessible from any part of the program.
ARM PE targets
Targets that use the Portable Executable (PE) file format, commonly associated with Windows, but also used for certain embedded systems, and specifically here, for ARM architectures.
Filed Under: binutilsldlinkerpecompiler warnings