[challenge] Linker surgery

IgorStepanov wazar at mail.ru
Tue May 14 17:17:43 PDT 2013


Do this table linked, if you remove all functions, which use it?
It not, you can try the next method (Another hack).

extern(C) immutable int[] table_ = [1,2,3]; //table_.mangleof ==
"table_";

int foo()
{
        pragma(mangle, "table_") extern immutable int[] table;
        return table[1];
}

In this hack we "fooling" the compiler. We say, that "table_"
doesn't used in foo(). foo() use another extern array "table"
with overrided mangle (new feature)

On Tuesday, 14 May 2013 at 18:36:32 UTC, Dmitry Olshansky wrote:
> 14-May-2013 22:27, Nick Sabalausky пишет:
>> On Tue, 14 May 2013 18:59:22 +0400
>> Dmitry Olshansky <dmitry.olsh at gmail.com> wrote:
>>>
>>> Now is the challenge is how do I make it NOT link in tables 
>>> if I
>>> don't call the corresponding functions.
>>>
>>
>> Don't some linkers do unreferenced symbol removal?
>
> Interestingly it does ... for functions.
>
>> Maybe that's all
>> that's needed?
>>
>
> Might be - if that was my personal need I might set off to 
> search some smart linker. But the thing will end up in the 
> standard library and surely there it's stuck with ld/optlink.


More information about the Digitalmars-d mailing list