Changes between Version 2 and Version 3 of Commentary/Rts/Storage/HeapAlloced


Ignore:
Timestamp:
Aug 25, 2013 6:16:24 AM (2 years ago)
Author:
ezyang
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Rts/Storage/HeapAlloced

    v2 v3  
    2929ELF sections can be arbitrarily aligned.  So we could put all our static closures in a special section, align the section to 1MB, and arrange that there is space at the beginning of the section for the block descriptors.
    3030
    31 This almost works (see [attachment:eliminate-heap-alloced.patch.gz]), but sadly fails for shared libraries: the system dynamic linker doesn't honour section-alignment requests larger than a page, it seems.
     31This almost works (see [attachment:eliminate-heap-alloced.patch.gz]), but sadly fails for shared libraries: the system dynamic linker doesn't honour section-alignment requests larger than a page, it seems. Here is a simple test program which shows the problem on Linux:
     32
     33{{{
     34// test.S
     35    .section foo,"aw"
     36    .p2align 20
     37    .global foo_start
     38foo_start:
     39    .ascii "A"
     40}}}
     41
     42{{{
     43// main.c
     44#include <stdio.h>
     45extern char foo_start;
     46int main(void) {
     47    printf("%c\n", foo_start); // force libtest.so to be loaded
     48    printf("%p\n", &foo_start);
     49}
     50}}}
     51
     52Compare static linking and dynamic linking:
     53
     54{{{
     55ezyang@javelin:~/Dev/labs/reloc$ gcc test.S main.c -g && ./a.out
     56A
     570x700000
     58ezyang@javelin:~/Dev/labs/reloc$ gcc test.S  -shared -o libtest.so -fPIC
     59ezyang@javelin:~/Dev/labs/reloc$ gcc -Wl,-R`pwd` -L. main.c -ltest -g -O0
     60-fPIC && ./a.out
     61/usr/bin/ld: warning: type and size of dynamic symbol `foo_start' are not
     62defined
     63A
     640x7f012f9e7000
     65}}}
    3266
    3367=== Method 2: copy static closures into a special area at startup ===
     
    3771Disadvantages:
    3872 
    39  * references to static objects go through another indirection.  
     73 * references to static objects go through another indirection. (This includes all of the RTS code!)
    4074   * when doing dynamic linking, references to static objects in another package
    4175     already go through an indirection and we could arrange that only one indirection is required.