Bug 105397 - C++ modules vs -fvisibility option
Summary: C++ modules vs -fvisibility option
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-04-26 17:46 UTC by Ben Boeckel
Modified: 2022-12-21 11:32 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Boeckel 2022-04-26 17:46:21 UTC
There is no way to decorate an `export module X;` with an `__attribute__((visibility("default")))` such that it ends up visible in the resulting shared library if `-fvisibility=hidden` is passed. I also tried linker scripts with no luck.
Comment 1 Mathias Stearn 2022-06-09 13:47:50 UTC
Perhaps the best option is to default the visibility of the implicit functions to the widest visibility of any function or object in module purview exposed by the TU. The assumption being that if anything is visibile outside the library, then it is expected to be imported from TUs outside the library and that should Just Work. Conversely, if everything is defined as internal visibility, then it is unlikely that this module was intended to be imported from outside of the library, and so it may be desireable to allow different libs to have their own module with the same name.

Unfortunately that doesn't give any good indication of what to do for importable units that have an empty module purview (or where everything inside it has TU-local internal linkage). While legal, maybe that isn't a case worth optimizing the Just Works experience for?
Comment 2 Ben Boeckel 2022-12-08 20:43:12 UTC
> Perhaps the best option is to default the visibility of the implicit functions to the widest visibility of any function or object in module purview exposed by the TU.

What to do about `extern "C"` APIs made available by a module? Is that even allowed? Imagine a library providing some C API by implementing in C++ modules; should the module initializer be public API too?
Comment 3 Iain Sandoe 2022-12-21 11:32:38 UTC
the import places attributes at the end.

so 
import module Foo [[....]];

it would seem to be symmetrical to have:

export import Foo [[...]];
export module Foo [[...]];

but, ts present, (if I read it correctly) it seems that the WD says

export [[...]] module Foo;
export [[...]] int bar ();

which would then be weird with export [[...]] import Foo [[...]];