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.

453 questions
4
votes
2 answers

How to place a variable at the end of a section (with GCC)

I want to place a specific variable at the end of its memory section. So if I have: file1.cpp: __attribute__((section(".mysection"))) char var1[] = "var1"; and in another file2.cpp: __attribute__((section(".mysection"))) char var2[] = "var2"; How…
Eldad
  • 1,067
  • 16
  • 36
4
votes
2 answers

Section load address and execution address in linker script

I'm writing a customized linker script for a bare-metal ARM application. The application is stored in a flash memory, at the moment I have a bootup code copying the whole application in SDRAM, and continuing execution in SDRAM for speed purpose. I…
Étienne
  • 4,773
  • 2
  • 33
  • 58
4
votes
3 answers

ld linker script producing huge binary

I'm using binutils-2.21.53.0.1-6.fc16.x86_64. I have a small object file, hello.o with just enough "stuff" to have contents in all sections: Section Headers: [Nr] Name Type Address Offset Size …
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
3
votes
1 answer

Default GNU Linker Script name so VIM does Syntax Highlighting

What is the usual suffix for a linker script so that VIM will use syntax-highlighting on it?
Matthew Hoggan
  • 7,402
  • 16
  • 75
  • 140
3
votes
2 answers

linker script load vs. virtual address

I've got the following linker script that is supposed to link code to run on a flash based micrcontroller. The uC has flash at address 0x0, and RAM at 0x40000000. I want to put the data section into flash, but link the program so that access to the…
Chris H
  • 6,433
  • 5
  • 33
  • 51
3
votes
3 answers

Member variable allocated at start of memory

I'm trying to use c++ on an STM32 device compiling with gcc. The device loads the code and start executing it but hard faults on any member variable write. I can see with GDB that member variables are stored at beginnning of memory (0x7 to be…
3
votes
0 answers

What does HIDDEN and PROVIDE_HIDDEN in linker scripts exactly do?

I have gone through the linker documentation for HIDDEN and PROVIDE_HIDDEN multiple times, but I am not really able to understand what they exactly do. For example, if I write a linker script with an assignment like this : naveen = 10; SECTIONS …
Naveen
  • 7,944
  • 12
  • 78
  • 165
3
votes
1 answer

Linker script: mixing memory regions and location assignments

I have been looking at some linker scripts for embedded ARM processors. In one of them, there's something like this (minimal example): MEMORY { REGION : ORIGIN = 0x1000, LENGTH = 0x1000 } SECTIONS { .text : { /* ... */ . = 0x20; /*…
user4945014
3
votes
0 answers

Why does GNU ld default linker script NOT have 'MEMORY'?

I checked the output of ld --verbose on both x86_64 as well as on armv7l (beaglebone black rev C). The default linker script does not contain 'MEMORY' command. Why is that?
ZeZNiQ
  • 612
  • 7
  • 14
3
votes
0 answers

How to define C-like register macro in C++

I always fancy MODULE_INIT macro in linux kernel source code. So I try to make similar macro in C++. AFAIK, MODULE_INIT will put a function into a memory section. So I try, void __attribute__((section("mysec")) func(); This works fine when compile…
Silver
  • 406
  • 2
  • 12
3
votes
1 answer

Is there a reason I am unable to specify the start offset of a Rust program in a linker script?

I am trying to compile a Rust program for a Raspberry Pi. I am under the impression that the start address needs to be 0x8000, so I am using a custom linker script to lay out the program to follow this requirement: SECTIONS { .text 0x8000 : { …
Someone
  • 800
  • 1
  • 7
  • 25
3
votes
2 answers

What are data segment initializers?

I'm constructing a linker script for a bare metal application running on the STM32F3Discovery board. It uses the startup code from the CMSIS drivers located in the STM32Cube_FW_F3 package, precisely the stm32f303xc.s file. The above file, a…
bartlomiej.n
  • 500
  • 6
  • 19
3
votes
0 answers

Calling an external program, downloaded in runtime and getting return data on bare metal

I have a system with an MPC8548 processor. My job is to send a second (external) program to the running firmware and execute it. I have a cross compiler set up to build the base firmware and the external code. I was able to send a separate program…
Zoltán
  • 678
  • 4
  • 15
3
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
  • 387
  • 1
  • 10
3
votes
2 answers

Does the linker script always determine at what addresses code is placed

I've spent most of my time developing for microcontrollers using tools and IDEs such as Atmel Studio, and abstracted from as to what goes on behind the scenes exactly. Let's say in this case we are executing the code directly from flash which can be…
Engineer999
  • 3,683
  • 6
  • 33
  • 71