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

Explicitly set starting stack pointer with linker script

I'd like to create a program with a special section at the end of Virtual Memory. So I wanted to do a linker script something like this: /* ... */ .section_x 0xffff0000 : { _start_section_x = .; . = . + 0xffff; _end_section_x =…
HardcoreHenry
  • 5,909
  • 2
  • 19
  • 44
7
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
  • 113
  • 8
7
votes
2 answers

Linking with another start-up file

I am trying to link a program with my own start-up file by using the STARTUP directive in a LD script: ... ENTRY(_start) STARTUP(my_crt1.o) ... GCC driver is used to link the program (not to bother with library paths like libgcc, etc.): gcc -T…
Julio Guerra
  • 5,523
  • 9
  • 51
  • 75
6
votes
1 answer

error: PHDR segment not covered by LOAD segment

I was learning about linking scripts from the text "Operating Systems from 0 to 1", and in the text they showed an example of using the keyword PHDRS as so; ENTRY(main); PHDRS { headers PT_PHDR FILEHDR PHDRS; code PT_LOAD FILEHDR; } …
USER149372
  • 103
  • 2
  • 7
6
votes
0 answers

Overriding HIDDEN symbol-visibility with a gnu ld linker script

TL;DR: Can I use a GNU ld linker --version-script or some other method to promote selected symbols with hidden visibility (due to -fvisibility=hidden or an explicit __attribute__) back to default visibility, so they are available in the global…
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
6
votes
0 answers

GNU linker script - how to automatically distribute code to multiple dis-contiguous sections

I'm modifying an existing .ld and I have two flash sections for the code. These two flash sections are not contiguous so I cannot merely extend the definition of one of the sections to include the other. Currently all of the code can fit in sec1 but…
Bob
  • 4,576
  • 7
  • 39
  • 107
6
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
  • 941
  • 8
  • 24
6
votes
2 answers

gcc/ld - create a new libc.so with __isoc99_sscanf@@GLIBC_2.7 symbol from glibc.2.6

I have an application, which does a error when I try to run it: /lib/libc.so.6: version `GLIBC_2.7' not found But the only symbol it needs from glibc 2.7 is __isoc99_sscanf@@GLIBC_2.7 I want to write a small single function "library" with this…
osgx
  • 90,338
  • 53
  • 357
  • 513
6
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,314
  • 19
  • 31
6
votes
1 answer

Is there a way to add comments to a linker script?

My question is very simple. Is there a way to add comments to a linker script? Like for example in a makefile: # Comment
MrCupC4ke
  • 115
  • 3
  • 5
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,773
  • 2
  • 33
  • 58
6
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

Why does a Cortex-M4 include ARM to Thumb glue in the linker script

We are working on some code for ARM Cortex M4 on a STM32 chip. My understanding is that Cortex-M4 has some 32-bit instructions but these are not 32-bit ARM instructions they are just a few special instructions. I thought the glue was for…
Marc
  • 1,159
  • 17
  • 31
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
  • 407
  • 3
  • 10
5
votes
3 answers

Access build-id at runtime

I am trying to figure out how to access the build-id generated by the linker at runtime. From this page, https://linux.die.net/man/1/ld When I build a test program like: % gcc test.c -o test -Wl,--build-id=sha1 I can see that the build ID is…
Todd Freed
  • 877
  • 6
  • 19
1 2
3
30 31