What’s the difference between .so, .la and .a library files?

File type breakdown .so files are dynamic libraries. The suffix stands for “shared object”, because all the applications that are linked with the library use the same file, rather than making a copy in the resulting executable. .a files are static libraries. The suffix stands for “archive”, because they’re actually just an archive (made with … Read more

Include binary file with GNU ld linker script

You could try using objcopy to convert it to a normal object you can link in, and then reference its symbols in the linker script like you would do to a normal object. From the objcopy manual page: -B bfdarch –binary-architecture=bfdarch Useful when transforming a raw binary input file into an object file. In this … Read more

How to make gcc link strong symbol in static library to overwrite weak symbol?

I am puzzled by the answer given by max.haredoom (and that it was accepted). The answer deals with shared libraries and dynamic linking, whereas the question was clearly about the behavior of static linking using static libraries. I believe this is misleading. When linking static libraries, ld does not care about weak/strong symbols by default: … Read more

Why do I have to define LD_LIBRARY_PATH with an export every time I run my application?

You should avoid setting LD_LIBRARY_PATH in your .bashrc. See “Why LD_LIBRARY_PATH is bad” for more information. Use the linker option -rpath while linking so that the dynamic linker knows where to find libsync.so during runtime. gcc … -Wl,-rpath /path/to/library -L/path/to/library -lsync -o sync_test EDIT: Another way would be to use a wrapper like this #!/bin/bash … Read more

Why Linux/gnu linker chose address 0x400000?

The start address is usually set by a linker script. For example, on GNU/Linux, looking at /usr/lib/ldscripts/elf_x86_64.x we see: … PROVIDE (__executable_start = SEGMENT_START(“text-segment”, 0x400000)); \ . = SEGMENT_START(“text-segment”, 0x400000) + SIZEOF_HEADERS; The value 0x400000 is the default value for the SEGMENT_START() function on this platform. You can find out more about linker scripts by … Read more

Linking against older symbol version in a .so file

I found the following working solution. First create file memcpy.c: #include <string.h> /* some systems do not have newest memcpy@@GLIBC_2.14 – stay with old good one */ asm (“.symver memcpy, memcpy@GLIBC_2.2.5”); void *__wrap_memcpy(void *dest, const void *src, size_t n) { return memcpy(dest, src, n); } No additional CFLAGS needed to compile this file. Then link … Read more

dlopen from memory?

I needed a solution to this because I have a scriptable system that has no filesystem (using blobs from a database) and needs to load binary plugins to support some scripts. This is the solution I came up with which works on FreeBSD but may not be portable. void *dlblob(const void *blob, size_t len) { … Read more

tech