Multiple definition of static constexpr data member with C++11 and 17
Mon Aug 16 12:47:07 GMT 2021
* Jonathan Wakely:
> On Mon, 16 Aug 2021 at 10:59, Florian Weimer wrote:
>> * Jonathan Wakely via Gcc-help:
>> > I'm not sure if GCC should change, or if the linker should be changed
>> > to permit a single non-weak non-UNIQUE definition to be merged with
>> > zero or more UNIQUE definitions. As a workaround you can compile the
>> > C++17 code with -fno-gnu-unique so that GCC uses a weak symbol, but
>> > that isn't a good solution in general (the unique binding exists for
>> > good reasons).
>> What are those reasons, exactly?
> I think it was added to ensure uniqueness of static objects across
> libraries opened with RTLD_LOCAL.
Hmm, that makes some sense. The glibc implementation is not really
structured in such a way that it is obvious that this is the goal.
(glibc knows what it has loaded, so it could search just that, and not
construct a separate hash table.)
>> I've been trying to find a rationale and specification of
>> STB_GNU_UNIQUE, but have not been successful.
>> The glibc implementation does not handle symbol versions, it ignores
>> them. It's not entirely clear to me if this is a bug.
> Does anybody use it with more than one symbol version though?
> Using symbol versioning on a STB_GNU_UNIQUE symbol would seem to
> violate its uniqueness.
>> Furthermore, I haven't seen a case yet which would require
>> STB_GNU_UNIQUE and could not have been handled equally well via symbol
> Does that work for RTLD_LOCAL though?
No, I don't think so.
More information about the Gcc-help