dynamic-linking

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

十年热恋 提交于 2019-11-26 20:27:14
问题 I understand that in a typical ELF binary, functions get called through the Procedure Linkage Table (PLT). The PLT entry for a function usually contains a jump to a Global Offset Table (GOT) entry. This entry will first reference some code to load the actual function address into the GOT, and contain the actual function address after the first call (lazy binding). To be precise, before lazy binding the GOT entry points back into the PLT, to the instructions following the jump into the GOT.

Linking GLEW with CMake

不想你离开。 提交于 2019-11-26 18:25:47
问题 How can you link GLEW to a project with CMake? We've been trying to link GLEW to our project using CMake for at least 3 hours without any success so any help is accepted. I'm using the FindGLEW.cmake which comes with CMake 3.1.0 CMakeLists.txt find_package(GLEW REQUIRED) if (GLEW_FOUND) include_directories($(GLEW_INCLUDE_DIRS)) endif() Environment Variables I'm using MinGW w64 to compile the sources and we successfully linked GLFW and GLM just by copying the includes and libs to their

Force GCC to notify about undefined references in shared libraries

蹲街弑〆低调 提交于 2019-11-26 17:23:53
I have a shared library that is linked with another (third-party) shared library. My shared library is then loaded using dlopen in my application. All this works fine (assuming files are in the proper path etc). Now, the problem is that I don't even need to specify to link against the third-party shared library when I link my library. GCC accept it without reporting errors about undefined references. So, the question; how can I force GCC to notify me about undefined references ? If I change my library to be (temporarily) an executable, I get undefined references (when not supplying the library

Is it OK to use DYLD_LIBRARY_PATH on Mac OS X? And, what's the dynamic library search algorithm with it?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 17:22:46
I read some articles discouraging of the use of DYLD_LIBRARY_PATH, as the the path of dynamic library should be fixed using -install_name, @rpath, and @loader_path. In terms of making a program that runs both on Linux and Mac OS X, DYLD_LIBRARY_PATH of Mac OS X does exactly what LD_LIBRARY_PATH of Linux. And, we can share (almost) the same make file that doesn't have the -install_name and @rpath. Is this OK to use DYLD_LIBRARY_PATH on Mac OS X? What's the dynamic library search algorithm with Mac OS X when the binary can't find the dynamic library? current directory -> DYLD_LIBRARY_PATH

How do I do weak linking in Swift?

限于喜欢 提交于 2019-11-26 16:16:41
问题 In Objective-C, if I wanted to use a specific class that's only present in a new version of iOS, I would do something like this: if( [UIBlurEffect class] ) { // do something with UIBlurEffect } else { // gracefully fallback to old behavior } However, the equivalent Swift: if UIBlurEffect.self != nil { let blur: UIBlurEffect = UIBlurEffect(...) // ... else { // ... } // also occurs with NSClassFromString("UIBlurEffect") doesn't have the same functionality. If run on an environment where

iOS is it a static or a dynamic framework?

匆匆过客 提交于 2019-11-26 15:45:29
问题 This might sound like a silly question but If you have a thirdParty.framework file, can you tell if it's static or dynamic? I mean, do they look different if you look inside? 回答1: It can be either. Only iOS8+ will allow dynamic frameworks in the app bundle, however. The way to find out is to look in the .framework and use the file command on the main file: $ cd iOS/Crashlytics.framework $ ls -l total 9984 -rwxr-xr-x 1 andy staff 4710656 11 Sep 17:11 Crashlytics drwxr-xr-x 8 andy staff 272 11

Static and Dynamic/Shared Linking with MinGW

左心房为你撑大大i 提交于 2019-11-26 15:37:57
问题 I want to start with a simple linking usage to explain my problem. Lets assume that there is a library z which could be compiled to shared library libz.dll(D:/libs/z/shared/libz.dll) or to static library libz.a (D:/libs/z/static/libz.a). Let I want to link against it, then I do this: gcc -o main.exe main.o -LD:/libs/z/static -lz According to this documentation, gcc would search for libz.a, which is archive files whose members are object files I also can do the following: gcc -o main.exe main

Linking two shared libraries with some of the same symbols

北城以北 提交于 2019-11-26 14:24:12
I link with two different shared libraries. Both libraries define some symbols that share a name but have different implementations. I can't make each library use its own implementation over the other. For example, both libraries define a global function bar() that each calls internally. Library one calls it from foo1() and library two calls it from foo2() . Lib1.so: T bar T foo1() // calls bar() Lib2.so: T bar T foo2() // calls bar() If I link my application against Lib1.so and then Lib2.so the bar implementation from Lib1.so is called even when calling foo2() . If on the other hand, I link

Call Go functions from C

冷暖自知 提交于 2019-11-26 14:05:46
I am trying to create a static object written in Go to interface with a C program (say, a kernel module or something). I have found documentation on calling C functions from Go, but I haven't found much on how to go the other way. What I've found is that it's possible, but complicated. Here is what I found: Blog post about callbacks between C and Go Cgo documentation Golang mailing list post Does anyone have experience with this? In short, I'm trying to create a PAM module written entirely in Go. You can call Go code from C. it is a confusing proposition though. The process is outlined in the

Overriding 'malloc' using the LD_PRELOAD mechanism

巧了我就是萌 提交于 2019-11-26 12:08:00
I'm trying to write a simple shared library that would log malloc calls to stderr (a sort of 'mtrace' if you will). However, this is not working. Here's what I do: /* mtrace.c */ #include <dlfcn.h> #include <stdio.h> static void* (*real_malloc)(size_t); void *malloc(size_t size) { void *p = NULL; fprintf(stderr, "malloc(%d) = ", size); p = real_malloc(size); fprintf(stderr, "%p\n", p); return p; } static void __mtrace_init(void) __attribute__((constructor)); static void __mtrace_init(void) { void *handle = NULL; handle = dlopen("libc.so.6", RTLD_LAZY); if (NULL == handle) { fprintf(stderr,