Page 3 of 3 FirstFirst 123
Results 21 to 23 of 23

Thread: Initialization sections not being run in Linux so.

  1. #21

    Initialization sections not being run in Linux so.

    OK, I compiled the following code into a shared object

    Code:
    void __attribute__ ((constructor)) lib_init(void)
    {
      printf("lib_init called");
    }
    
    void __attribute__ ((destructor)) lib_quit(void)
    {
      printf("lib_quit called");
    }
    
    void printUPPERCASE( inLine )
    char inLine[];
    {
      char Upstring[256];
      char *inptr, *outptr;
    
      inptr = inLine;
      outptr = Upstring;
      while (*inptr != '\0')
       *outptr++ = toupper(*inptr++);
      *outptr++ = '\0';
      printf(Upstring);
      return;
    }

    I used

    gcc -c -fpic test.c

    then

    gcc -shared -lc -o test.so test.o

    and ran

    objdump -t -x test.so

    Here are the results. after doing a bit of reading it seems the ((constructor)) style stuff ends up in the .ctors section and the ((destructor)) ends up in the .dtors

    Code:
    test.so:     file format elf32-i386
    test.so
    architecture: i386, flags 0x00000150:
    HAS_SYMS, DYNAMIC, D_PAGED
    start address 0x000004f0
    
    Program Header:
        LOAD off    0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**12
             filesz 0x00000710 memsz 0x00000710 flags r-x
        LOAD off    0x00000710 vaddr 0x00001710 paddr 0x00001710 align 2**12
             filesz 0x0000010c memsz 0x00000110 flags rw-
     DYNAMIC off    0x0000072c vaddr 0x0000172c paddr 0x0000172c align 2**2
             filesz 0x000000c0 memsz 0x000000c0 flags rw-
       STACK off    0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**2
             filesz 0x00000000 memsz 0x00000000 flags rw-
    PAX_FLAGS off    0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**2
             filesz 0x00000000 memsz 0x00000000 flags --- 2800
    
    Dynamic Section:
      NEEDED      libc.so.6
      INIT        0x480
      FINI        0x6d0
      HASH        0xd4
      STRTAB      0x314
      SYMTAB      0x184
      STRSZ       0xaa
      SYMENT      0x10
      PLTGOT      0x17f8
      PLTRELSZ    0x20
      PLTREL      0x11
      JMPREL      0x458
      REL         0x420
      RELSZ       0x38
      RELENT      0x8
      VERNEED     0x3f0
      VERNEEDNUM  0x1
      VERSYM      0x3be
      RELCOUNT    0x2
    
    Version References:
      required from libc.so.6:
        0x09691f73 0x00 03 GLIBC_2.1.3
        0x0d696910 0x00 02 GLIBC_2.0
    
    Sections:
    Idx Name          Size      VMA       LMA       File off  Algn
      0 .hash         000000b0  000000d4  000000d4  000000d4  2**2
                      CONTENTS, ALLOC, LOAD, READONLY, DATA
      1 .dynsym       00000190  00000184  00000184  00000184  2**2
                      CONTENTS, ALLOC, LOAD, READONLY, DATA
      2 .dynstr       000000aa  00000314  00000314  00000314  2**0
                      CONTENTS, ALLOC, LOAD, READONLY, DATA
      3 .gnu.version  00000032  000003be  000003be  000003be  2**1
                      CONTENTS, ALLOC, LOAD, READONLY, DATA
      4 .gnu.version_r 00000030  000003f0  000003f0  000003f0  2**2
                      CONTENTS, ALLOC, LOAD, READONLY, DATA
      5 .rel.dyn      00000038  00000420  00000420  00000420  2**2
                      CONTENTS, ALLOC, LOAD, READONLY, DATA
      6 .rel.plt      00000020  00000458  00000458  00000458  2**2
                      CONTENTS, ALLOC, LOAD, READONLY, DATA
      7 .init         00000017  00000480  00000480  00000480  2**4
                      CONTENTS, ALLOC, LOAD, READONLY, CODE
      8 .plt          00000050  00000498  00000498  00000498  2**2
                      CONTENTS, ALLOC, LOAD, READONLY, CODE
      9 .text         000001dc  000004f0  000004f0  000004f0  2**4
                      CONTENTS, ALLOC, LOAD, READONLY, CODE
     10 .fini         0000001b  000006d0  000006d0  000006d0  2**4
                      CONTENTS, ALLOC, LOAD, READONLY, CODE
     11 .rodata       00000020  000006eb  000006eb  000006eb  2**0
                      CONTENTS, ALLOC, LOAD, READONLY, DATA
     12 .eh_frame     00000004  0000070c  0000070c  0000070c  2**2
                      CONTENTS, ALLOC, LOAD, READONLY, DATA
     13 .ctors        0000000c  00001710  00001710  00000710  2**2
                      CONTENTS, ALLOC, LOAD, DATA
     14 .dtors        0000000c  0000171c  0000171c  0000071c  2**2
                      CONTENTS, ALLOC, LOAD, DATA
     15 .jcr          00000004  00001728  00001728  00000728  2**2
                      CONTENTS, ALLOC, LOAD, DATA
     16 .dynamic      000000c0  0000172c  0000172c  0000072c  2**2
                      CONTENTS, ALLOC, LOAD, DATA
     17 .got          0000000c  000017ec  000017ec  000007ec  2**2
                      CONTENTS, ALLOC, LOAD, DATA
     18 .got.plt      0000001c  000017f8  000017f8  000007f8  2**2
                      CONTENTS, ALLOC, LOAD, DATA
     19 .data         00000008  00001814  00001814  00000814  2**2
                      CONTENTS, ALLOC, LOAD, DATA
     20 .bss          00000004  0000181c  0000181c  0000081c  2**2
                      ALLOC
     21 .comment      00000136  00000000  00000000  0000081c  2**0
                      CONTENTS, READONLY
     22 .debug_aranges 00000068  00000000  00000000  00000958  2**3
                      CONTENTS, READONLY, DEBUGGING
     23 .debug_info   00000164  00000000  00000000  000009c0  2**0
                      CONTENTS, READONLY, DEBUGGING
     24 .debug_abbrev 00000020  00000000  00000000  00000b24  2**0
                      CONTENTS, READONLY, DEBUGGING
     25 .debug_line   00000179  00000000  00000000  00000b44  2**0
                      CONTENTS, READONLY, DEBUGGING
    SYMBOL TABLE:
    000000d4 l    d  .hash	00000000              .hash
    00000184 l    d  .dynsym	00000000              .dynsym
    00000314 l    d  .dynstr	00000000              .dynstr
    000003be l    d  .gnu.version	00000000              .gnu.version
    000003f0 l    d  .gnu.version_r	00000000              .gnu.version_r
    00000420 l    d  .rel.dyn	00000000              .rel.dyn
    00000458 l    d  .rel.plt	00000000              .rel.plt
    00000480 l    d  .init	00000000              .init
    00000498 l    d  .plt	00000000              .plt
    000004f0 l    d  .text	00000000              .text
    000006d0 l    d  .fini	00000000              .fini
    000006eb l    d  .rodata	00000000              .rodata
    0000070c l    d  .eh_frame	00000000              .eh_frame
    00001710 l    d  .ctors	00000000              .ctors
    0000171c l    d  .dtors	00000000              .dtors
    00001728 l    d  .jcr	00000000              .jcr
    0000172c l    d  .dynamic	00000000              .dynamic
    000017ec l    d  .got	00000000              .got
    000017f8 l    d  .got.plt	00000000              .got.plt
    00001814 l    d  .data	00000000              .data
    0000181c l    d  .bss	00000000              .bss
    00000000 l    d  .comment	00000000              .comment
    00000000 l    d  .debug_aranges	00000000              .debug_aranges
    00000000 l    d  .debug_info	00000000              .debug_info
    00000000 l    d  .debug_abbrev	00000000              .debug_abbrev
    00000000 l    d  .debug_line	00000000              .debug_line
    00000000 l    d  *ABS*	00000000              .shstrtab
    00000000 l    d  *ABS*	00000000              .symtab
    00000000 l    d  *ABS*	00000000              .strtab
    00000000 l    df *ABS*	00000000              initfini.c
    00000000 l    df *ABS*	00000000              /var/tmp/portage/glibc-2.3.6-r3/work/build-default-i386-pc-linux-gnu-linuxthreads/csu/crti.S
    000004f0 l     F .text	00000000              call_gmon_start
    00000000 l    df *ABS*	00000000              crtstuff.c
    00001710 l     O .ctors	00000000              __CTOR_LIST__
    0000171c l     O .dtors	00000000              __DTOR_LIST__
    00001728 l     O .jcr	00000000              __JCR_LIST__
    00001818 l     O .data	00000000              p.0
    0000181c l     O .bss	00000001              completed.1
    00000518 l     F .text	00000000              __do_global_dtors_aux
    00000574 l     F .text	00000000              frame_dummy
    00000000 l    df *ABS*	00000000              crtstuff.c
    00001718 l     O .ctors	00000000              __CTOR_END__
    00001724 l     O .dtors	00000000              __DTOR_END__
    0000070c l     O .eh_frame	00000000              __FRAME_END__
    00001728 l     O .jcr	00000000              __JCR_END__
    0000069c l     F .text	00000000              __do_global_ctors_aux
    00000000 l    df *ABS*	00000000              initfini.c
    00000000 l    df *ABS*	00000000              /var/tmp/portage/glibc-2.3.6-r3/work/build-default-i386-pc-linux-gnu-linuxthreads/csu/crtn.S
    00000000 l    df *ABS*	00000000              test.c
    00001814 l     O .data	00000000              .hidden __dso_handle
    00000512 l     F .text	00000000              .hidden __i686.get_pc_thunk.bx
    000017f8 l     O *ABS*	00000000              .hidden _GLOBAL_OFFSET_TABLE_
    0000172c g     O *ABS*	00000000              _DYNAMIC
    00000608 g     F .text	00000092              printUPPERCASE
    00000480 g     F .init	00000000              _init
    000005de g     F .text	0000002a              lib_quit
    0000181c g       *ABS*	00000000              __bss_start
    00000000       F *UND*	00000062              toupper@@GLIBC_2.0
    00000000       F *UND*	00000036              printf@@GLIBC_2.0
    000006d0 g     F .fini	00000000              _fini
    00000000  w    F *UND*	0000008c              __cxa_finalize@@GLIBC_2.1.3
    0000181c g       *ABS*	00000000              _edata
    00001820 g       *ABS*	00000000              _end
    000005b4 g     F .text	0000002a              lib_init
    00000000  w      *UND*	00000000              _Jv_RegisterClasses
    00000000  w      *UND*	00000000              __gmon_start__
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  2. #22

    Initialization sections not being run in Linux so.

    Thanks to the help of the dev team at Free Pascal, the issues regarding initialization sections being run in library's under Linux has been resolved in the 2.1.1 version of Free Pascal.

    A big thank you for the help over the last few days to all involved.

    The good news is that ,apart form a few issues my InfinitEnigine framework is now running under Windows (Opengl/DirectX) and Linux (Opengl). for more info check out the post of the InfiniteSpace-Online forum here.

    The engine makes use of a shared memory manager , and exports classes for the host application to use rather than a function API. the code is identical between windows and linux , delphi and free pascal. So good job to all the people at free pascal .
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  3. #23

    Initialization sections not being run in Linux so.

    Excellent news! Can't wait to see it working on MacOS X .
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

Page 3 of 3 FirstFirst 123

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •