Custom calling conventions

Jacob Carlborg doob at me.com
Wed Feb 22 09:32:14 PST 2012


On 2012-02-22 13:53, Michel Fortin wrote:
> On 2012-02-22 07:41:21 +0000, Jacob Carlborg <doob at me.com> said:
>
>> void foo (T) () {}
>> void main ()
>> {
>> foo!(int);
>> foo!(char);
>> }
>>
>> $ dmd -inline -O -release main.d
>> $ nm main | grep foo
>>
>> 00000001000012b8 T _D4main10__T3fooTaZ3fooFZv
>> 00000001000012b0 T _D4main10__T3fooTiZ3fooFZv
>>
>> Outputs two symbols as expected, one for each instantiation.
>
> That's expected indeed.
>
> This doesn't mean the inliner will not inline the templates. In fact, if
> you correct the example and look at the assembler output you'll see it
> will (in your example there is nothing to inline since you're just
> instantiating the template without calling it).
>
> What doesn't happen is stripping the unreferenced symbols from the
> executable. On OS X, try adding "-L-dead_strip" to DMD's argument to
> instruct the linker to do so.
>

1. The example is correct, you can call a method without parentheses
2. Adding -L-dead_strip does not seem to strip the "foo" symbols
3. Adding -L-dead_strip causes a segmentation fault with this example 
(DMD 2.057)

import std.stdio;

void foo (T) () { writeln("asd"); }
void main ()
{
      foo!(int);
      foo!(char);
}

4. I thought the reason for the big executable using the Objective-C/D 
bridge was due to all these template symbols.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list