Questions tagged [linker-scripts]

The linker command language used to control the memory layout of computer programs and details of the linking process.

Linker scripts contain a command language processed by the linker to determine how sections in input files are mapped into the output file. Most often used to control the memory layout in computer programs, they can also exercise fine control over details of the linking process.

360 questions
6
votes
1 answer

gcc: Can you put function pointers to a different section (not .data)?

For doing Unit Testing of an embedded project on the host, I started to use function pointers to be able to change between the 'real' implementation of a function and a mock at runtime. So, my function 'foo' looks like this in the .c file: // the…
bns
  • 103
  • 8
6
votes
2 answers

Using #defined values before RAM has been initialised

I am writing the boot-up code for an ARM CPU. There is no internal RAM, but there is 1GB of DDRAM connected to the CPU, which is not directly accessible before initialisation. The code is stored in flash, initialises RAM, then copies itself and the…
Étienne
  • 4,131
  • 2
  • 27
  • 49
5
votes
1 answer

Linker: Moving all functions but two to a specific memory region

I am working on firmware for a PIC32MX microcontroller. The program memory should be split into three segments: Section 1: interrupt service routine and main function (startup_region) Section 2: 50% of remaining program memory (program1) Section…
Danish
  • 347
  • 1
  • 9
5
votes
2 answers

GCC for ARM -- ELF output file segment misplaced

Edited to add: I have now cross-posted this to the GNU ARM Embedded Toolchain site, as I am fairly certain that it's a linker bug. Also, I have noticed that it seems to happen when the first program segment fits into the first page in the ELF file…
TonyK
  • 15,585
  • 4
  • 29
  • 65
5
votes
1 answer

Create new segment in linker script while keeping default ones

I have created some special sections in a linked file and I want them to be in separated segments to have different page permissions. In linker script, PHDRS command can specify segments in linked file. However, as the document says, PHDRS will…
xywang
  • 841
  • 5
  • 17
5
votes
0 answers

Linker script: allocation of .bss section

I have a linker script like this: OUTPUT_FORMAT(binary) SECTIONS { . = 0xFFFF800000000000 ; .startup_text : { processor.o(.text) } .text : { *(EXCLUDE_FILE (processor.o) .text) } .data : { *(.data) } .rodata : { *(.rodata) } …
lodo
  • 2,222
  • 14
  • 29
5
votes
2 answers

Splitting embedded program in multiple parts in memory

I am working on an embedded system (Stellaris Launchpad) and writing a simple OS (as a hobby project). The used toolchain is gcc-none-eabi. My next step is to get used to the MPU to allow the kernel to prevent user programs from altering specific…
Cheiron
  • 3,276
  • 4
  • 26
  • 54
5
votes
3 answers

__isr_vectors variable not found when placed inside a static library

As a spin-off of a previous question (sbrk function not found when placed in a static library): I'm creating a bare-metal application for the stm32f407 microcontroller, which has an ARM Cortex M4 core. I'm trying to create a static library…
Richard
  • 202
  • 2
  • 8
5
votes
2 answers

Linker script: insert absolute address of the function to the generated code

I have a question related to gcc's linker. I'm working with embedded stuff (PIC32), but PIC32's compiler and linker are based on gcc, so, main things should be common for "regular" gcc linker and PIC32 linker. In order to save flash space (which is…
Dmitry Frank
  • 9,453
  • 7
  • 55
  • 101
5
votes
1 answer

Is there a linker script directive that allows me to move my stack start address?

I'm trying to change the start location of my stack using a linker script on x86_64. I was able to move my executable start address using this: PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x200000)); . =…
5
votes
1 answer

what is the difference between LD_LIBRARY_PATH and -rpath

When linking libraries, -rpath is used to pass the address of dynamic libraries to ld. My question is if I set the address in LD_LIBRARY_PATH, do I still need -rpath flag in my linking process?
Ju Liu
  • 51
  • 1
  • 2
4
votes
1 answer

How to make a custom section executable (other than .text)

Basic Hello World as seen many times before on x86_64 Linux: global my_start_symbol section .my_section my_start_symbol: mov rax, 1 mov rdi, 1 mov rsi, msg mov rdx, msg_len syscall mov rax, 60 …
Ryan McClue
  • 220
  • 2
  • 14
4
votes
2 answers

Extra bytes at the end of a DOS .COM file, compiled with GCC

I have the following C source file, with some asm blocks that implement a print and exit routine by calling DOS system calls. __asm__( ".code16gcc;" "call dosmain;" "mov $0x4C, %AH;" "int $0x21;" ); void print(char *str) { …
Arjob Mukherjee
  • 337
  • 1
  • 7
4
votes
1 answer

Is accessing the "value" of a linker script variable undefined behavior in C?

The GNU ld (linker script) manual Section 3.5.5 Source Code Reference has some really important information on how to access linker script "variables" (which are actually just integer addresses) in C source code. I used this info. to extensively use…
Gabriel Staples
  • 11,777
  • 3
  • 74
  • 108
4
votes
0 answers

Why does the content of STM32 read-only data set by Rust differ between the target and the ELF file?

I'm trying to print a string through semihosting on STM32F4. I define a variable: let array: &[u8] = &[ 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x6e, 0x65, 0x77, 0x20, 0x77, 0x61, 0x79, 0x00, 0x00, 0x00, ]; This a…
phodina
  • 991
  • 6
  • 22
1 2
3
23 24