Find the answer to your Linux question:
Results 1 to 8 of 8
Hi, I am working on a project with RedHat. I would like to load a shared dynamic library each time at the same adress. In fact an option for the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2004
    Posts
    13

    [part solved]Loading of shared Libraries


    Hi,

    I am working on a project with RedHat.
    I would like to load a shared dynamic library each time at the same adress. In fact an option for the ld of DEC called "-fixed" does not exists with ld of glibc. It mapped the librairy to its quickstart address and never relocate it. I absolutely need to recreate this option. I've tried to make a ld script but it doesn't work , or I don't do it properly. Have you some informations or links to help me...

    Tks.

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    I very much doubt that it's possible to do something like that. I think ELF specifies that shared objects can be loaded anywhere. Would you mind me asking why you would want to do something like that? There might be another way around it.

  3. #3
    Just Joined!
    Join Date
    Jun 2004
    Posts
    13
    In fact, I have to port code from DEC to RH. It seems that some libraries have to be load at the same address by several exetucable because they communicate via function pointer in SHM.
    After testing several things and read the article http://www-106.ibm.com/developerwork.../l-shared.html, it seems that the only way to have the same library loaded at the same address for two different programs is the link order. If the library is at the same "rank" of linking, it should work....But it is not really sure !
    That's the reason why I wanted to use script ld, but there are not a lot of simple example, or i don't get them.
    For example, the first example of "info ld" says that the following script will load the code at the adress 0x4030000 and the section .text at 0x800000.
    Code:
    SECTIONS
         {
           . = 0x40300000;
           .text : { *(.text) }
           . = 0x8000000;
           .data : { *(.data) }
           .bss : { *(.bss) }
         }
    So I do ld script -shared -verbose -o libExample.so libExample.c
    No pb : tells me that it openned the script and linked it.
    But I do a readelf -a libExample.so and no changement. And when i run the prog, it does not change neither the loading address of my lib (cat /proc/pid/maps for thoose don't know)

    I am quite desesperated.....

  4. #4
    Just Joined!
    Join Date
    Jun 2004
    Posts
    13
    Well, i've succed in solve the pb with the order on linkes librairy, but it's not very clean. If someone has another idea, i take it...

    Angel97

  5. #5
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Wouldn't it be better to use offsets into the library instead of absolute pointers in the SHM?

    That is - declare a reference symbol in the library (or use any existing one), and put the pointers into the SHM as offsets relative to this reference symbol. That way it wouldn't have to be loaded at a specific address.

  6. #6
    Just Joined!
    Join Date
    Jun 2004
    Posts
    13
    yes indeed, but the problem is quite simple :
    the initial program is quite extremly complex, and nobody wrote conception specs.....
    I don't have the time to analyse which functions are used in the SHM, so i really wanted to emulate this "ld DEC" option...
    But for sure, it would be cleaner. And moreover, my solution works for exec. because they all begin to load libraries at the same address. Now, I've a thread created "in" a shared library. I wonder how this thread load needed shared libraries :
    i 've seen that the first adress of the first shared library loaded is the same for all. But tht's not the same thing for dynamic libraries. They're loading their first dynamic library at different adress.
    So (i've a headhache...) what does the thread .... I'll try to analyse this tomorrow...

  7. #7
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Well, I have to admit that I don't know the exact semantics for dynlinking in Linux. I would guess that the best way of finding out would probably be to get the source of /lib/ld-linux.so and check out just what it does to decide the address.

  8. #8
    Just Joined!
    Join Date
    Jun 2004
    Posts
    13
    yes indeed, I will probably do that.
    And an info : this lib (with ld actually)is in the source of glibc.
    In fact i didn't know that, so for ignorant as me....

    PS: it found this forum with google and i don't regret it. congratulations guys, it is really well made. Hop in my favorites

Posting Permissions

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