Is a statically linked executable faster than a dynamically linked executable?

Static linking produces a larger executable file than dynamic linking because it has to compile all of the library code directly into the executable. The benefit is a reduction in overhead from no longer having to call functions from a library, and anywhere from somewhat to noticeably faster load times. A dynamically linked executable will … Read more

Why does the PLT exist in addition to the GOT, instead of just using the GOT?

The problem is that replacing call printf@PLT with call [printf@GOTPLT] requires that the compiler knows that the function printf exists in a shared library and not a static library (or even in just a plain object file). The linker can change call printf into call printf@PLT, jmp printf into jmp printf@PLT or even mov eax, … Read more

use RPATH but not RUNPATH?

When you ship a binary, it’s good to provide means for the users to accommodate the binary to the specifics of their own system, among other things, adjusting library search paths. A user can generally tweak LD_LIBRARY_PATH and /etc/ld.so.conf, both of which are with lower precedence than DT_RPATH, i.e. you can’t override what is hardcoded … Read more

Overriding ‘malloc’ using the LD_PRELOAD mechanism

I always do it this way: #define _GNU_SOURCE #include <stdio.h> #include <dlfcn.h> static void* (*real_malloc)(size_t)=NULL; static void mtrace_init(void) { real_malloc = dlsym(RTLD_NEXT, “malloc”); if (NULL == real_malloc) { fprintf(stderr, “Error in `dlsym`: %s\n”, dlerror()); } } void *malloc(size_t size) { if(real_malloc==NULL) { mtrace_init(); } void *p = NULL; fprintf(stderr, “malloc(%d) = “, size); p = … Read more

Linking two shared libraries with some of the same symbols

There are several ways to solve this: Pass -Bsymbolic or -Bsymbolic-functions to the linker. This has a global effect: every reference to a global symbol (of function type for -Bsymbolic-functions) that can be resolved to a symbol in the library is resolved to that symbol. With this you lose the ability to interpose internal library … Read more

Why does gcc not implicitly supply the -fPIC flag when compiling static libraries on x86_64

See question 3544035. Also discussed here and there. It depends on what use you will have for your static library. If you only want to link it into programs, it doesn’t need PIC code (libtool calls that a convenience library, because you could pretty much do without it, it simply helps get your compilation process … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)