Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overhead of DLL function call

How big is a performance penalty when calling functions from DLL? Loading DLL is not an issue for us, number of calls to our highperf library will not be big.

Approximately, how many instructions/clock-cycles does one call take over a static library call?

like image 639
Cartesius00 Avatar asked Sep 03 '11 14:09

Cartesius00


People also ask

How do I get a list of functions in a DLL?

You can list function names for a specific DLL, such as user32. dll, by running a variety of command-line tools. For example, you can use dumpbin /exports user32. dll or link /dump /exports user32.

Can a DLL call another DLL?

It will include the exported DLL2 header file and the DLL2 . lib file in its project. It can then call any DLL2 function. This is the cleanest way to have 2 DLLs working together.


1 Answers

My answer is based on how the Linux/glibc/ELF dynamic linker works, but I would assume the overall answer is the same for other platforms:

There is a difference between the first call to a dynamically loaded symbol and the next calls. The first call is expensive, can involve many cycles. All other calls are more or less 1 - 2 instruction away.

The way it works is that the linker set up an entry in the Procedure Linkage Table that grabs an address for that outside function from the Global Offset Table. At first call the address of the GOT points to a stub that runs the dynamic linker to resolve the real address of the function in the DLL. This can take a lot of cycles, but once it is done once, the dynamic linker will path the GOT entry to point directly to the function, so the next time the PLT code is called is will call directly to the function.

Here is a link to a fairly good walk through of this process: http://www.technovelty.org/linux/pltgot.html

like image 90
gby Avatar answered Sep 21 '22 05:09

gby