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
4
votes
1 answer

Relocation of PE DLLs - Load-time or like ELF?

It's my understanding (mainly from Wikipedia's article on the Portable Executable format), that Windows DLLs don't use position-independent code and instead have a link-time-defined preferred base address. In the event that two libraries' base…
Zane Beckwith
  • 443
  • 2
  • 11
4
votes
1 answer

How to avoid undesired constant folding performed by LLVM's code generator?

What I am trying to achieve is to avoid constant-folding of some constants (which represent addresses in my code) such as the 100000000 constant below. I need this because later the JIT-compiled code might get patched, which changes the constants…
4
votes
0 answers

Strange relocation error occurring within a virtualenv: `python: relocation error: python: symbol Øv�l��⎼�Ø┴�┌��⎼�Ø┴�` (etc...)

I'm encountering a very mysterious error that occurs intermittently whilst I'm working within a virtualenv. Although it has now happened to me 3-4 times, I'm finding it frustratingly difficult to find the conditions that will reproduce the problem.…
ali_m
  • 71,714
  • 23
  • 223
  • 298
4
votes
2 answers

What's the purpose of copy relocation?

BACKGROUND: If an executable file has a external data reference, which is defined in a shared object, the compiler will use copy relocation and place a copy in its .bss section. Copy relocation is detailed in this…
zhebin jin
  • 85
  • 1
  • 6
4
votes
1 answer

How does GDB perform base addresses of shared libraries [ internals of info sharedlibrary command]

I am trying to understand the internal working behind GDB commands. After initial homework of understanding about elf / shared libraries / address space randomization, I attempted to understand how GDB make sense between the executable and…
kspviswa
  • 637
  • 3
  • 13
3
votes
1 answer

Why can't I assemble absolute addresses in the .text section on ARM64 MacOS?

I'm writing in assembly using clang 13.1.6 with MacOS Monterey 12.5 on an ARM64 M1 Pro laptop. If I try to use .dword/.xword in the .text section with the address of a label as its value, my program crashes on startup with a bus error. Minimal…
Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
3
votes
1 answer

Why is .rela.plt necessary for resolving PIC function addresses?

While exploring ELF structure, I see this (this is objdump -d and readelf -r of the binary linked with a PIC .so containing ml_func): 0000000000400480 <_Z7ml_funcii@plt>: 400480: ff 25 92 0b 20 00 jmpq *0x200b92(%rip) # 601018…
deshalder
  • 507
  • 2
  • 13
3
votes
1 answer

Why doesn't Elf64 use Elf64_Rel for relocations on 64-bit x86?

https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-54839.html#chapter7-2 states: 64–bit SPARC and 64–bit x86 use only Elf64_Rela relocation entries. Thus, the r_addend member serves as the relocation addend. x86 uses only Elf32_Rel…
the4naves
  • 333
  • 2
  • 9
3
votes
0 answers

Windows object file COFF relocations explanation

I'm trying to create an x86-64 Windows COFF object file, but I don't entirely understand the different types of relocations described at https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#x64-processors. Specifically, I'm not sure what…
abel1502
  • 955
  • 4
  • 14
3
votes
1 answer

Relocation truncated to fit error when compiling using g++

I am trying to compile a piece of cpp code under linux, and got the following error: /tmp/ccIeh7Ta.o: In function `model::MulPLSA::EStep()': mul_plsa.cpp:(.text+0xb12): relocation truncated to fit: R_X86_64_32S against symbol…
user572138
  • 463
  • 4
  • 6
  • 13
3
votes
1 answer

How are external symbols of a shared library resolved in the main program?

I've been reading a lot about the semantics of load-time linking of shared libraries and one thing that I'm having trouble understanding is how can the main program make references to functions defined in shared libraries? For example, say I have…
GamefanA
  • 1,555
  • 2
  • 16
  • 23
3
votes
1 answer

Static Address vs. Execution Address In An Elf Loader

I am writing an Elf Loader for ARM/ARM64. While processing the dynamic relocations I became a bit confused by some of the terms/symbols in the documentation I am following. On Pg.14 it is stated, "S (when used on its own) is the address of the…
3
votes
1 answer

Disable relocations when linking with LLD

Is there an option for lld that will tell it not to perform relocations. I don't want PIC code, I just want relocations not to be performed. (Yes I know this will result in an executable that doesn't work.)
Timmmm
  • 88,195
  • 71
  • 364
  • 509
3
votes
2 answers

Problems with static local variables with relocatable code

I am building a project which has relocatable code on bare metal. It is a Cortex M3 embedded application. I do not have a dynamic linker and have implemented all the relocations in my startup code. Mostly it is working but my local static…
Dan
  • 261
  • 3
  • 10
3
votes
1 answer

Retrieve symbol name of RELA in ELF executable

I am trying to retrieve the symbol name of RELA jump slots found in an ELF executable. Using libElf, I have managed to retrieve the address of the RELA but still trying to figure out how to get the symbol(-name). According to How can I get the…
Ra'Jiska
  • 979
  • 2
  • 11
  • 23