C++ Logo

std-discussion

Advanced search

Re: Guarantees over addresses from function pointers created from lambda

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 28 Apr 2025 12:50:31 -0700
On Monday, 28 April 2025 11:53:28 Pacific Daylight Time Federico Kircheis via
Std-Discussion wrote:
> In other words: why cant a static analysis during build process
> determines that the variable is never mutated, helpfully mark it as
> constant/puts it in the rodata section?
> Sounds like a valid transformation to me, I see no way how it could
> change the behavior of a program.
>
> And at that point, the same optimization routine in the linker that
> merges function pointers merges those objects together.
> Back to square one.

If a compiler/linker combo is performing this type of whole-program analysis,
then it should have no problem identifying if two called functions are codegen
identical and could be merged without any observable effects, in particular
because their addresses were never taken. There is no violation of the
standard here, because all optimisations are allowed under as-if rule.

The problem is when the optimisation violates the as-if rule and does produce
observable effects (I'm not counting side-channel effects as effects). This is
what Microsoft is violating and what merging any and all functions could as
well.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2025-04-28 19:50:38