flat assembler
Message board for the users of flat assembler.

Index > Linux > Best DLL import practice?

Author
Thread Post new topic Reply to topic
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
So, what is the best practice of importing functions from Linux shared libraries?
To import from particular version, for example "libX11.so.6" or to use symlink to the latest version and to import from it - for example "libX11.so"?

I don't talk about the "special cases", but the best common practice.

_________________
Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9
Post 20 Sep 2012, 16:44
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Good question.

I would suspect libname.so.{majorversion} (I suppose) symlinked to libname.so.{majorversion}.{minorversion} - at least that has been the layout of /lib on the distros where I've bothered to look Smile
Post 20 Sep 2012, 19:33
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Ah, I missed this major - minor particularity.
So, the major version is important, right?
Post 20 Sep 2012, 21:52
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
randall



Joined: 03 Dec 2011
Posts: 155
Location: Poland
randall
The best way in my opinion is to use dlsym, dlopen.
Only external symbol you need is dlsym. Then you can get dlopen like this:

dlopen = dlsym(0, "dlopen")

From there you can load any shared library. With this approach you can first try to load libname.so.x.y and if it is not found you can load libname.so.x

I have simple OpenGL 4.2 program which works like this if you want an example.
Post 20 Sep 2012, 21:57
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
randall, I am talking about static import tables. Importing in runtime has its advantages sometimes, but it is "special case" IMHO.
Post 21 Sep 2012, 05:10
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
randall



Joined: 03 Dec 2011
Posts: 155
Location: Poland
randall
JohnFound wrote:
randall, I am talking about static import tables. Importing in runtime has its advantages sometimes, but it is "special case" IMHO.


Yes I know you are talking about static import tables. I just encourage you to consider this approach. It is more flexible, faster and executable file is smaller.
Post 21 Sep 2012, 08:15
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
randall wrote:
It is more flexible, faster and executable file is smaller.


Hm, I am not sure at all. Any arguments? You still need to keep list with imported functions in your executable.

_________________
Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9
Post 21 Sep 2012, 08:45
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
randall



Joined: 03 Dec 2011
Posts: 155
Location: Poland
randall
JohnFound wrote:
randall wrote:
It is more flexible, faster and executable file is smaller.


Hm, I am not sure at all. Any arguments? You still need to keep list with imported functions in your executable.


You need to store only name and pointer per function in your executable. Static import table stores a lot more.

Also this is interesting read:
http://timothylottes.blogspot.com/2012/07/dynamic-linking-and-run-time-recompile.html
Post 21 Sep 2012, 09:16
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Randall, this idea is not so bad actually. I need to think more about it. It even seems to be more portable, because the same "simple import tables" can be used on Windows, Linux and even on OSes that have no dynamic linker at all.

BTW, where this "dlsym" function is located?
Post 21 Sep 2012, 10:25
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
randall



Joined: 03 Dec 2011
Posts: 155
Location: Poland
randall
dlsym is located in libdl.so.2
Post 21 Sep 2012, 11:09
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.