dynamic-linking

Why doesn't the linker complain of duplicate symbols?

此生再无相见时 提交于 2019-11-29 16:57:09
I have a dummy.hpp #ifndef DUMMY #define DUMMY void dummy(); #endif and a dummy.cpp #include <iostream> void dummy() { std::cerr << "dummy" << std::endl; } and a main.cpp which use dummy() #include "dummy.hpp" int main(){ dummy(); return 0; } Then I compiled dummy.cpp to three libraries, libdummy1.a , libdummy2.a , libdummy.so : g++ -c -fPIC dummy.cpp ar rvs libdummy1.a dummy.o ar rvs libdummy2.a dummy.o g++ -shared -fPIC -o libdummy.so dummy.cpp When I try compile main and link the dummy libs g++ -o main main.cpp -L. -ldummy1 -ldummy2 There is no duplicate symbol error produced by linker. Why

load time relocation and virtual memory

為{幸葍}努か 提交于 2019-11-29 15:43:56
问题 I am wondering what load-time relocation actually means on a system with virtual memory support.I was thinking that in a system with virtual memory every executable will have addresses starting from zero and at run-time the addresses will be translated into physical addresses using page tables.Therefore the executable can be loaded anywhere in memory without the need of any relocation. However this article on shared libraries mentions that linker specifies an address in the executable where

Is it possible to statically link against a shared object?

荒凉一梦 提交于 2019-11-29 14:13:30
My question is not the same as this question . I'm working on a project with a standalone binary that has no dynamic/external linkage, and runs in a *nix environment. I'm attempting to move to a newer toolset to build with, but some of the static libraries that are available with the older toolset aren't available now -- for example, the crt libraries that provided _start aren't provided in this toolset. I've been digging through the files provided with the vendor's toolset and found some shared objects with the symbols I needed from the crt libraries (eg, _start, _fini , etc) but I'm unsure

How does linker resolves duplicate symbols in dynamically loadable libraries?

此生再无相见时 提交于 2019-11-29 12:14:33
I have two dynamically loadable libraries lib_smtp.so and and libpop.so etc. Both have a global variable named protocol which is initialized to "SMTP" and "POP" respectively. I have another static library libhttp.a where protocol is initialized to "HTTP". Now for some reason i need to compile all dynamic linkable and loadable libraries statically and include in the executable. Doing so i am getting error " multiple definition of symbol " during linking of static libraries. I am curious to know how linker resolves duplicate symbols during dynamic linking where all three mentioned libraries are

Linking shared library in linux kernel

纵然是瞬间 提交于 2019-11-29 11:54:10
I would like to modify the linux kernel. I would like to use functions from a shared library (an .so file) in file kernel/panic.c . Unfortunately I don't know how to compile it. When I put it in to the Makefile I receive the following error: ld: attempted static link of dynamic object . Is there a way to put the shared library file to the Linux kernel or do I need to recompile my library to gain an object file. It is not possible to link shared library into kernel code ( ELF shared objects are a user-space thing, using ld-linux(8) ...) You should consider making a kernel module (and use

What are possible causes of “failed to map segment from shared object: operation not permitted”, and how to debug?

巧了我就是萌 提交于 2019-11-29 09:36:14
I have two executables, both cross compiled to run in Android. I have put both on the device in the same directory. I have put all the shared libraries that they are dependent on in the same directory, including ld-linux.so.3. I run the executables by using: ld-linux.so.3 --library-path /path/to/libraries executable_name both work on older versions of Android when running as any user. The both work on the latest version of Android if running as root. Only one works on the latest version of android when running as any user. Instead it gives: failed to map segment from shared object: executable

Create .SO files on Linux without using PIC (position independent code) (x86 32bit)

余生长醉 提交于 2019-11-29 08:39:44
As far as I know, x86 assembly code is very much constrained by the limited amount of registers. When I learnt that on Linux, to create a .so file, one has to specify the -fPIC command line argument to gcc in order to create position independent code, I couldn't believe it first. As far as I know, the elf file format supports relocations, just like the - in my eyes much better - Windows DLL system works: On Windows the linker relocates all the offsets in the DLLs, if this is necessary. I think that the time needed to load a SO-file or DLL-file, and also the amount of memory used to keep

Mixing static libraries and shared libraries

不羁岁月 提交于 2019-11-29 07:22:21
I have a project where I have one static library libhelper.a and another with my actual shared object library, libtestlib.so . My goal is to link libhelper.a into libtestlib.so . Is that possible on Linux/BSD? When I tried and created a test program I got the following errors: ./prog1:/usr/local/lib/libtestlib.so.1.0: undefined symbol '' My guess is that this is occurring because libhelper.a was not compiled with -fPIC while libtestlib.so was. What is the proper way to build programs that use shared libraries that also have dependancies on static libraries? Thanks! My goal is to link libhelper

LD_PRELOAD only working for malloc, not free

瘦欲@ 提交于 2019-11-29 04:39:27
I'm trying to interpose malloc/free/calloc/realloc etc with some interposers via LD_PRELOAD. In my small test, only malloc seems to be interposed, even though free is detected (see output). I'd expect the output to contain a line "NANO: free(x)" - but this line is missing. Given // compile with: gcc test.cc #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { void* p = malloc(123); printf("HOST p=%p\n", p); free(p); } And // compile with: g++ -O2 -Wall -fPIC -ldl -o libnano.so -shared main.cc #include <stdio.h> #include <dlfcn.h> typedef void *(*MallocFunc)(size_t size);

Linking boost library with Boost_USE_STATIC_LIB OFF on Windows

…衆ロ難τιáo~ 提交于 2019-11-29 03:59:53
My CMakeFiles.txt looks like this: cmake_minimum_required ( VERSION 2.6 ) # Set warnings on and enable debugging SET( CMAKE_C_FLAGS "-Wall -q" ) include(FindBoost) set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) find_package( Boost 1.57.0 COMPONENTS system filesystem REQUIRED ) if( Boost_FOUND ) message( STATUS "Boost found!" ) include_directories(${Boost_INCLUDE_DIRS}) add_executable(foo main.cpp) # Needed for asio if(WIN32) target_link_libraries(foo wsock32 ws2_32) endif() target_link_libraries(foo ${Boost_LIBRARIES}) endif() I render the