[Mesa-dev] [PATCH 6/7] glsl: Hide many classes local to individual .cpp files in anon namespaces.
Ian Romanick
idr at freedesktop.org
Sat Sep 21 20:43:15 PDT 2013
On 09/21/2013 03:16 PM, Kenneth Graunke wrote:
> On 09/20/2013 06:52 PM, Eric Anholt wrote:
>> This gives the compiler the chance to inline and not export class symbols
>> even in the absence of LTO. Saves about 60kb on disk.
>
> This is probably worth doing.
> Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
>
> Another important reason for doing this is that it avoids name
> collisions. By default, classes have external linkage, which means that
> if you compile two files together that both define classes with the same
> name, bad things happen. You might get link errors, or it might just
> randomly link code against the wrong one, with no messages whatsoever.
>
> See commit 5cadb3ef7e6c1a67c45b0fdb2b0c2c1a369a97d8 for a bit of history
> where this was actually happening, and we had real bugs as a result.
>
> However, this is also extremely irritating: it prevents you from doing:
>
> (gdb) break builtin_builder::create_shader
>
> Instead, you have to do:
>
> (gdb) break (anonymous namespace)::builtin_builder::create_shader
Oof. Should we avoid the anonymous name space in debug builds? Hmm...
that seems pretty awful too.
> I'm having a really hard time believing that gdb doesn't have a
> better/shorter way of doing this, but I sure can't find one.
>
> If all else fails, you can always resort to line numbers:
> (gdb) break builtin_functions.cpp:599
>
> Apparently, debugging with anonymous namespaces on MSVC is even worse.
>
> The lack of 'static' for forcing internal linkage on classes is simply
> maddening.
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list