[libc-commits] [libc] [libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (PR #98075)
Petr Hosek via libc-commits
libc-commits at lists.llvm.org
Mon Jul 8 14:22:09 PDT 2024
petrhosek wrote:
> > > So, this replaces every single namespace declaration with the following?
> > > ```c
> > > #define LIBC_NAMESPACE_DECL [[gnu::visibility("hidden")]] LIBC_NAMESPACE
> > > ```
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > Before that we need to identify all the entrypoints and make sure they retain default visibility. @frobtech suggested that we split that up into introducing a macro for exporting global variables, then we'd need to make sure that `LIBC_FUNCTION_ATTRS` includes default visibility.
> > > However, that's if we want non-hidden visibility at all. The main effect of everything being hidden is that if someone does `clang -shared foo.c -lc` with our `libc` the symbols won't be visible from the shared library. Maybe that's the desired behavior? The GPU doesn't care because we have no shared libraries.
> >
> >
> > Correct, although it's currently incomplete. Specifically because `LIBC_NAMESPACE_DECL` is declared in `libc/src/__support/macros/config.h`, any file that uses it needs an additional `#include`. I'm trying to see if I can automate this using `clang-include-fixer` rather than doing this manually. Similarly, we also need need to update the CMake files to introduce the additional dependency which I don't yet have a solution for.
>
> Alright, so this is basically the effect of compiling with `-fvisibility=hidden` by manually putting every single declaration into the namespace. Though we also need to fix the clang-tidy rule or else it will be really annoying.
No, `-fvisibility=hidden` doesn't cover everything. The compiler semantics work in layers:
1. `-fvisibility=hidden` means all definitions not affected by attributes, no effect on declarations.
2. `#pragma GCC visibility` applies to all definitions and declarations after it (not widely used, but e.g. in Zircon we use that via a -include file to get everything without using other means).
3. `[[gnu::visibility(...)]]` on namespace, class, struct, union applies to all definitions and declarations within that scope.
4. `[[gnu::visibility(...)]]` on an individual declaration applies to that one declaration.
5. `[[gnu::visibility(...)]]` on an individual definition overrides anything else prior..
That's why `-fvisibility=hidden` is not sufficient and in my testing even with `-fvisibility=hidden` as implemented in #98049 compiler still generates the unnecessary GOT relocs.
https://github.com/llvm/llvm-project/pull/98075
More information about the libc-commits
mailing list