GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
lto.cc

lto.cc: Fix OpenMP offload_handle_link_vars for global variables

Corrects a bug in OpenMP offload handling that caused functions to be called twice, potentially leading to incorrect global variable processing.

This commit fixes an issue in the LTO (Link-Time Optimization) component where the offload_handle_link_vars function was called twice for OpenMP offloads. The previous fix, intended to address renaming issues with static variables, inadvertently left the original call intact. This change removes the duplicated call and adjusts the processing order within offload_handle_link_vars to correctly handle global variables by ensuring declaration finalization occurs after iterating through the variable pool.

In Details

The LTO pass in lto.cc handles OpenMP offloading. This commit corrects a bug where offload_handle_link_vars was invoked twice due to a prior refactoring (r12-7776-g1002a7ace111d7). The fix removes a redundant call and reorders varpool_node::finalize_decl to execute after the FOR_EACH_VARIABLE loop, preventing modification of the varpool during iteration, although current implementations append to the front which doesn't break ->next walks.

For Context
LTO
Link-Time Optimization is a compiler optimization technique where the compiler performs optimizations on the entire program at link time, rather than on individual object files. This allows for more aggressive optimizations, especially inter-procedural ones.
OpenMP
Open Multi-Processing is an API that supports multi-platform shared-memory parallel programming. For GCC, it allows offloading computation to devices like GPUs.
varpool
The variable pool is a data structure within GCC that manages information about variables during compilation. offload_handle_link_vars processes variables relevant to OpenMP offloading.
Filed Under: ltoopenmpoptimization