Home
Support

Knowledge Base

BSPs and drivers
Community resources
Product documentation
Questions?
Contact us

Understanding dynamic linking function calling mechanism
 
________________________________________________________________________

Applicable Environment
________________________________________________________________________
  • Topic: Understanding dynamic linking function calling mechanism
  • SDP: 6.3.2
  • Target: Any supported target
________________________________________________________________________

Recommendation
________________________________________________________________________

For a .so library, the elf linker primarily uses two processor-specific tables for dynamic linking, the Global Offset Table (GOT) and the Procedure Linkage Table (PLT).

The GOT within the application's executable file contains absolute addresses to locations in the shared library which the application references. It redirects address calculations to absolute locations in the shared library. Similarly, the PLT redirects all library function calls to their absolute locations. So a reference to a shared library function will directly transfer control to the function via the PLT without calling the dynamic ELF linker.

However, that said, the ELF linker's behavior can change depending on the state of the environment variables in the process environment. If 'lazy binding' is used by the ELF linker, the linker will then evaluate PLT entries on the first reference to each function in the library. To explain this further, the PLT entry will involve a jump to the GOT entry which contains an address that points back to the next instruction in the PLT. The linker is then called to resolve this function's address and copies it directly into the related GOT entry before executing the function itself. Subsequent calls to the function will not need to be resolved by the linker. But without late binding, all PLT entries are fully evaluated before even transferring control to the application.

So simply, a function call to a dll will behave differently depending on whether or not lazy binding is used by the linker, or whether the function is being referenced the first time in the execution of the program. In all cases though, the PLT and the GOT tables are used to handle dynamic library function calls.

________________________________________________________________________
NOTE: This entry has been validated against the SDP version listed above. Use caution when considering this advice for any other SDP version. For supported releases, please reach out to QNX Technical Support if you have any questions/concerns.
________________________________________________________________________


Related Attachments
 None Found





Please contact us with your questions or concerns.