C++ Logo

std-proposals

Advanced search

Re: [std-proposals] "shared libraries are outside the scope of the C++ standard"

From: Ofek Shilon <ofekshilon_at_[hidden]>
Date: Wed, 26 Jul 2023 18:01:30 +0300
On Wed, 12 Jul 2023 at 17:56, Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
wrote:

> On Wed, Jul 12, 2023 at 10:34 AM Ofek Shilon via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>> > (1) First, a few general descriptive sections should be reviewed and
>> mostly rephrased, probably introducing a concept like 'linkage-unit':
>>
>
> Maybe you just need to be more specific here, but I think you're probably
> wrong. I don't see why a notion of "linkage-unit" would be *useful*.
> Again compare to instruction encoding: we could introduce a standard notion
> of "encoded-instruction-form," but it wouldn't buy us anything relevant to
> C++. It's not *useful*.
>

There's actually another issue at play here - interposition: the practice
of having a definition from one binary (typically the executable) override
a definition from another binary (a shared library).
The MS implementation doesn't have it, but any ELF system (that I know of)
does.
The existing ODR clause says (http://eel.is/c++draft/basic.def.odr#14) :
"For any definable item D with definitions in multiple translation units
... the program is ill-formed". Interposition is the handling of a
private case of this state: definitions in multiple *linkage* units.
(BTW, in the particular case of replacement-functions (
http://eel.is/c++draft/replacement.functions#3) I'd even say interposition
is blessed by the standard. The replacement-functions clause does link to
the ODR clause, but I can't see how that makes them reconcile.)

This behavior is definitely unfixable, and probably predates the C++
standard.
So to have the standard be pragmatic and take a step towards reality, I
think the way is to introduce a notion of 'linkage-units' and restrict ODR
to one such unit.

On that note, we can take another look at the replacement-function section (
http://eel.is/c++draft/replacement.functions#3) Windows PE doesn't have
interposition and doesn't conform to it, and ELF has interposition (which
as noted violates the existing ODR wording) but doesn't give any special
treatment to replacement-functions: ALL functions supplied by the
implementation can be replaced by a program, not only the specified memory
functions.
I'd dare say this section is pretty much dead-letter, and might be safely
omitted.
WDYT?


>


>
>>
> HTH,
> Arthur
>

Received on 2023-07-26 15:01:44