[Mesa-dev] [PATCH 6/7] glsl: Hide many classes local to individual .cpp files in anon namespaces.
Kenneth Graunke
kenneth at whitecape.org
Mon Sep 23 19:23:26 PDT 2013
On 09/21/2013 08:43 PM, Ian Romanick wrote:
> 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.
We should probably either fix GDB or at least file a bug report.
--Ken
More information about the mesa-dev
mailing list