C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Make side effects in static initialization more consistent
From: Thiago Macieira (thiago_at_[hidden])
Date: 2020-12-21 07:21:01


On Monday, 21 December 2020 08:05:07 -03 kh via Std-Proposals wrote:
> The main problem is that the linker could remove unused variables. The
> linker then also eliminates any side effects of the initialization.
> This might cause problems in some cases when the side effect is
> expected. The problem is strongly related to static linking. I
> couldn't observe it when linking the object files directly into an
> executable or in a shared library. This inconsistency is also
> problematic.

This is your problem: you've stepped out of the standard when you mentioned
"libraries".

The standard does not recognise the existence of them today. Either we need to
update the standard so it does, or we punt the problem by saying "modules will
solve everything", or this is an implementation issue.

Currently, it is the latter. This happens because of the way linkers have
worked for 40 years. I doubt you're going to get linkers to change much. But
since this is a platform issue, maybe all we need are platform solutions too.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DPG Cloud Engineering

STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups