dynamic-linking

Symbol Resolution and Dynamic Linking

左心房为你撑大大i 提交于 2019-12-21 18:33:12
问题 I have been reading about the relocation and symbol resolution process and I have a few questions on the same. So the whole process(of loading the exec) starts with exec(BA_OS) command. During exec(BA_OS) , the system retrieves a path name from the PT_INTERP segment and creates the initial process image from the interpreter file’s segments. That is, instead of using the original executable file’s segment images, the system composes a memory image for the interpreter. It then is the interpreter

C: Correct Way to Statically / Dynamically Link with MinGW-w64

不问归期 提交于 2019-12-21 17:53:36
问题 Intuitively: MinGW-w64 is a Windows port of the GNU compiler tools (GCC, etc.). Pre-compiled binaries for Windows are .dll (dynamic linking) / .lib (static linking). However, MinGW-w64 uses the GNU compiler tools, it would follow that .so / .a binaries are required. What I've Found: According to Red Hat Enterprise Linux documentation, seems that MinGW/MinGW-w64/Cygwin linkers look for .dlls and .as According to this tutorial, you should dynamically link to .so and statically link to .a . One

why do we need the shared library during compile time

拈花ヽ惹草 提交于 2019-12-21 03:47:16
问题 Why we need the presence of the shared library during the compile time of my executable? My reasoning is that since shared library is not included into my executable and is loaded during the runtime, it is not supposed to be needed during compile time. Or Am I missing something? #include<stdio.h> int addNumbers(int, int); //prototype should be enough, no? int main(int argc, char* argv[]){ int sum = addNumbers(1,2); printf("sum is %d\n", sum); return 0; } I had the libfoo.so in my current dir

What's going on in __libc_start_main?

匆匆过客 提交于 2019-12-20 11:37:11
问题 I'm really trying to understand the steps from high level code -> executable.. but am having some difficulties. I've written an empty int main() {} C file and am trying to decipher the disassembly via objdump -d . Here's what's going on: in _start , set up alignment, push arguments on stack, call __libc_start_main in __libc_start_main , the first line to execute is jmp *0x8049658 However, upon using objdump -R to check out the relocation records, the value in 0x8049658 is __libc_start_main

What's going on in __libc_start_main?

梦想的初衷 提交于 2019-12-20 11:37:10
问题 I'm really trying to understand the steps from high level code -> executable.. but am having some difficulties. I've written an empty int main() {} C file and am trying to decipher the disassembly via objdump -d . Here's what's going on: in _start , set up alignment, push arguments on stack, call __libc_start_main in __libc_start_main , the first line to execute is jmp *0x8049658 However, upon using objdump -R to check out the relocation records, the value in 0x8049658 is __libc_start_main

GDB “cannot open shared object file” Issue

≯℡__Kan透↙ 提交于 2019-12-20 07:21:54
问题 I've already read gdb says "cannot open shared object file" and gdb can not open shared object file and followed the instructions. I have a binary which is linked to a shared library file ( /zzz/yyy/xxx.so ). After I set LD_LIBRARY_PATH to /zzz/yyy/ and run the binary without GDB, it executes very well. However, when I was trying to use GDB to debug this binary, GDB says: error while loading shared libraries: xxx.so: cannot open shared object file: No such file or directory I already have

Linux C++ trys to load one specific library using an absolute path, while all otheres are linked using a relative one

北慕城南 提交于 2019-12-19 10:51:50
问题 I have the following Problem: I'm trying to create a portable version of my program, so I set rpath to "." so all libraries are linked using the relative file path. And this does work for all libraries except one. For some reason, the program only works if one specific library is present at the same position it was linked when it was compiled. Which is one I wrote myself, which also has its rpath set to ".". So basicly, the program will refuse to start even though the library is at the exact

Compiling a custom malloc

两盒软妹~` 提交于 2019-12-19 06:56:44
问题 I have written a custom library which implements malloc/calloc/realloc/free using the standard C prototypes, and I figured out how to compile it to an so. I want to test the library by linking a standard application against it? What would be a good way to do this? Once I have a working library I assume I can just load it with LD_PRELOAD, but how do I get my functions to co-exist with but take precedence over the system library ones? My functions need to make a call to malloc in order to get

Dynamic Loading Without extern “C”

喜欢而已 提交于 2019-12-19 03:15:37
问题 I'd like to use libdl to dynamically load C++ in general. The problem is identifying symbols at runtime that have been name mangled. As described here, one solution is to remove name mangling by using extern "C". http://www.tldp.org/HOWTO/C++-dlopen/theproblem.html This solution has the drawback of limiting dynamically loaded resources to C style interfaces. Dynamically loaded functions cannot, for instance, be overloaded functions. What is a good way to overcome this limitation? One possible

How to determine if an OS X dylib was linked with -flat_namespace

馋奶兔 提交于 2019-12-18 17:57:28
问题 I have a third party OS X dylib that I'm using in my app and don't have easy access to its creator. I'd like to determine if it was linked with -flat_namespace. Is that possible? If so, how? 回答1: Run otool -hV on the library. If you don't see TWOLEVEL , then it was linked with -flat-namespace . For example: twolevel.dylib: Mach header magic cputype cpusubtype caps filetype ncmds sizeofcmds flags MH_MAGIC_64 X86_64 ALL 0x00 DYLIB 8 672 NOUNDEFS DYLDLINK TWOLEVEL NO_REEXPORTED_DYLIBS versus