[challenge] Linker surgery

Dmitry Olshansky dmitry.olsh at gmail.com
Fri May 17 05:29:02 PDT 2013


15-May-2013 04:17, IgorStepanov пишет:
> Do this table linked, if you remove all functions, which use it?

Thanks for this try, but they DO link in always.
And I believe this is a key problem - each function goes into a separate 
object but globals are always pulled in!

Anyone ever used digits, letter or similar arrays in std.ascii ?
I doubt that - yet they are almost (next to everything depends on 
std.uni and that depends on std.ascii) always there in the binary.

These bits do add up and now with the full spectrum of Unicode...

Hm... now if we go with the shared library route I'd only do a 
disservice by make tables into templates. But in static linked one 
surely nobody wants these e.g. extra ~20K of normalization tables (and 
there is way more) for next to *every* program.

P.S. I'm coming to hate developing std stuff, so little space for 
maneuvers ;)

> 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.


-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list