Questions tagged [relocation]

Relocation is the adaptation of a piece of code assembled on a certain address in memory to another address It is a typical task of dynamic linkers and program loaders, and thus last step in a standard development toolchain.

Relocation is the adaptation of a piece of code assembled on a certain address in memory to another address. It is a typical task of dynamic linkers and program loaders, and thus last step in a standard development toolchain. (typically make - preprocessor - compiler - assembler - archiver - linker - loader)

Relocations can be symbolic or by just adding the base load address of the module (binary/library), the latter is often called a fixup. The object code of some executable formats is assembled to start at 0, making the normal linking process have some relocation aspects also.

The standard book about this subject is "Linkers and Loaders" by John R. Levine.

247 questions
10
votes
8 answers

Why is a function executed from the same memory address each time?

I'm disassembling an executable: (gdb) disas main Dump of assembler code for function main: 0x004012d0 : push %ebp 0x004012d1 : mov %esp,%ebp ... Each time the memory address is the same:0x004012d0. Isn't the memory…
Mask
  • 33,129
  • 48
  • 101
  • 125
10
votes
2 answers

How are PE Base Relocations build up?

I'm currently having trouble understanding how PE Base Relocations are build up. I understand there can be more then one relocation, I understand also why and how this is done, but I just don't understand it programmatically: Which of the following…
John Smith
  • 965
  • 1
  • 9
  • 22
9
votes
1 answer

with RIP-addressing, why x86-64 still need relocations?

So x86-64 has the RIP-relative addressings which makes PIC codes easy to write and relocations needed much less. Why is relocations still needed then on x86-64? For what features? I can try to explore with objdump but what C/C++ code patterns to…
zaharpopov
  • 16,882
  • 23
  • 75
  • 93
9
votes
1 answer

Relative-to-executable path to ld-linux dynamic linker/interpreter

I want to ship and archive binaries (executables with libraries) which are backward and forward compatible with as many Linux distributions as possible and the whole package relocatable. As I understand system libraries like libc also need to be…
mariusm
  • 1,483
  • 1
  • 11
  • 26
9
votes
1 answer

Compile error: relocation R_X86_64_PC32 against undefined symbol

I try to make functions in assembly language and put them in a dynamic library so I create .o with .S with this command: nasm -f elf64 hello.S -o hello.o but when I want to create the lib with gcc: gcc -fPIC -shared hello.o -o libasm.so and it…
killmat
  • 113
  • 1
  • 4
8
votes
1 answer

Relocation Error when Inserting External Cross-Compiled SPARC Linux Module

First off: I am not an expert, so please excuse any mistakes I make trying to explain myself. I am trying to cross-compile an external Linux module for a SPARC machine using Sparc-Linux-GCC-4.4.2. The version of the Linux kernel is…
Stuart
  • 1,733
  • 4
  • 21
  • 34
7
votes
1 answer

meaning of an entry in a relocation table of an object file

I met some problems in understanding the entries of relocation tables compiled from C source files. My programs are as below: //a.c extern int shared; int main(){ int a = 100; swap(&a, &shared); a = 200; shared = 1; swap(&a,…
BecomeBetter
  • 433
  • 1
  • 6
  • 18
7
votes
2 answers

How to apply DOP and keep a nice user interface?

Currently I want to optimize my 3d engine for consoles a bit. More precisely I want to be more cache friendly and align my structures more data oriented, but also want to keep my nice user interface. For example: bool Init() { // Create a node …
VitaminCpp
  • 314
  • 1
  • 4
  • 11
7
votes
1 answer

Resolve relative relocations in partial link

I've noticed that using -r to do a partial link doesn't actually resolve any relocations, it seems, even if they could be resolved via relative addressing. For example, consider f.o and g.o, with f.o containing f() which calls g() within g.o. Before…
kec
  • 2,099
  • 11
  • 17
7
votes
2 answers

GCC linker: move a symbol in a specified section

It is possible to move some of the functions in the code in a specific section on the executable? If so, how? For an application compiled with gcc, we have more source files, including X.c. Each object is compiled from the associated source (X.o is…
MathPlayer
  • 194
  • 3
  • 20
7
votes
1 answer

How to read the relocation records of an object file

I'm trying to understand the linking stage of C toolchain. I wrote a sample program and dissected the resulting object file. While this helped me to get a better understanding of the processes involved, there are some things which remain unclear to…
Multisync
  • 767
  • 6
  • 25
7
votes
1 answer

How do relocations work in COFF object (not image) files

What steps exactly are taken by the linker while resolving relocations in an object file before creating the final image? More specifically, how does the linker treat the value which is already stored at the relocation site? Does it always add it to…
6
votes
2 answers

Why does the -r option (relocatable) make ld not find any libraries?

Running Debian/Linux x86_64 with GNU ld 2.21. Quite simply, if I link with ld -o main main.o /usr/lib/crti.o /usr/lib/crt1.o /usr/lib/crtn.o -lc -lm It works, but when I link with ld -r -o main1.o main.o /usr/lib/crti.o /usr/lib/crt1.o…
Jeremy Salwen
  • 8,061
  • 5
  • 50
  • 73
6
votes
1 answer

Understanding ARM Cortex-M0+ relocation

I'm just getting started with embedded arm development, and there's a snippet of code that's really bugging me: /* Initialize the relocate segment */ pSrc = &_etext; pDest = &_srelocate; if (pSrc != pDest) { while (pDest < &_erelocate) { …
David Freitag
  • 2,252
  • 2
  • 16
  • 18
6
votes
0 answers

Weird linker behavior: relocation truncated to fit

I have a linker script for a kernel with two absolute symbols: _kernel_start and _kernel_end. However, I get a linker relocation error for only _kernel_end: In function…
Daniel A.A. Pelsmaeker
  • 47,471
  • 20
  • 111
  • 157
1
2
3
16 17