linker-scripts

Extracting archive file in linker script

ぐ巨炮叔叔 提交于 2021-02-19 06:47:06
问题 I am trying to deal with a problem like the following one: Assume that I have a library libxyz.a created from: /* main.c */ int main(void) { int a; } compiled and archived with: gcc -c main.c -o abc.o && ar cr libxyz.a abc.o How do I have to write linker script in order to put abc.o exactly where it is expected to be? I was trying to handle it in such way: /* script.ld */ SEARCH_DIR(.) INPUT(-lxyz) SECTIONS { .text : { xyz:abc(.text) } .data : { xyz:abc(.data) } .bss : { xyz:abc(.bss) } } but

Linking with another start-up file

你说的曾经没有我的故事 提交于 2021-02-19 02:37:09
问题 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 my_script.ld ... Unfortunately, it only works with a GCC compiled for powerpc targets, while arm or i686 targets don't and still include crt0.o in collect2. For example: arm-eabi-g++ -v -T my_script.ld ... gives me: collect2 ... /opt/lib/gcc/arm-eabi/4

How can the --add-section switch of OBJCOPY be used?

僤鯓⒐⒋嵵緔 提交于 2021-02-18 22:53:41
问题 There are really two questions that revolve around the use of --add-section. The simple one is in the title. Based on my reading, I haven't been able to figure out how one could execute --add-section. To use add-section, I have to pass a section name. If I use an existing section name the program responds with "can't add section '.data': File in wrong format." Perhaps I just need to pass another parameter. If I use a new section name, which I would prefer to do, I'm warned that "allocated

How can the --add-section switch of OBJCOPY be used?

旧街凉风 提交于 2021-02-18 22:53:13
问题 There are really two questions that revolve around the use of --add-section. The simple one is in the title. Based on my reading, I haven't been able to figure out how one could execute --add-section. To use add-section, I have to pass a section name. If I use an existing section name the program responds with "can't add section '.data': File in wrong format." Perhaps I just need to pass another parameter. If I use a new section name, which I would prefer to do, I'm warned that "allocated

Understanding ARM relocation (example: str x0, [tmp, #:lo12:zbi_paddr])

左心房为你撑大大i 提交于 2021-02-11 13:21:58
问题 I found this line of assembly in zircon kernel start.S str x0, [tmp, #:lo12:zbi_paddr] for ARM64. I also found that zbi_paddr is defined in C++: extern paddr_t zbi_paddr; So I started looking about what does #:lo12: mean. I found https://stackoverflow.com/a/38608738/6655884 which looks like a great explanation, but it does not explain the very basic: what is a rellocation and why some things are needed. I guess that since zbi_paddrr is defined in start.S and used in C++ code, since start.S

Understanding ARM relocation (example: str x0, [tmp, #:lo12:zbi_paddr])

一个人想着一个人 提交于 2021-02-11 13:21:56
问题 I found this line of assembly in zircon kernel start.S str x0, [tmp, #:lo12:zbi_paddr] for ARM64. I also found that zbi_paddr is defined in C++: extern paddr_t zbi_paddr; So I started looking about what does #:lo12: mean. I found https://stackoverflow.com/a/38608738/6655884 which looks like a great explanation, but it does not explain the very basic: what is a rellocation and why some things are needed. I guess that since zbi_paddrr is defined in start.S and used in C++ code, since start.S

How to convert ld -Ttext option to a linker script?

一个人想着一个人 提交于 2021-01-29 03:02:58
问题 I've found this tutorial on creating an operating system, and I'm trying to convert the linking part in the make file into a linker script. Here is the tutorial: https://github.com/ghaiklor/ghaiklor-os-gcc Here is the make file: SOURCES = $(shell find cpu drivers include kernel libc -name '*.c') HEADERS = $(shell find cpu drivers include kernel libc -name '*.h') OBJ = ${SOURCES:.c=.o cpu/interrupt.o} ASM = nasm CC = gcc LD = ld -m elf_i386 CFLAGS = -g -ffreestanding -Wall -Wextra -fno

How to convert ld -Ttext option to a linker script?

大城市里の小女人 提交于 2021-01-29 03:02:15
问题 I've found this tutorial on creating an operating system, and I'm trying to convert the linking part in the make file into a linker script. Here is the tutorial: https://github.com/ghaiklor/ghaiklor-os-gcc Here is the make file: SOURCES = $(shell find cpu drivers include kernel libc -name '*.c') HEADERS = $(shell find cpu drivers include kernel libc -name '*.h') OBJ = ${SOURCES:.c=.o cpu/interrupt.o} ASM = nasm CC = gcc LD = ld -m elf_i386 CFLAGS = -g -ffreestanding -Wall -Wextra -fno

Keep rodata located with the function that created it

岁酱吖の 提交于 2021-01-27 13:27:50
问题 I'm trying to make .rodata section location stay with its associated function memory location. I'm using the GNU compiler/linker, bare metal, plain-jane c, with an STM32L4A6 micro-controller. I have a custom board using an STM32L4A6 controller with 1Meg of Flash divided into 512 - 2K pages. Each page can be individually erased and programmed from a function running in RAM. I'd like to take advantage of this fine-grained flash organization to create an embedded firmware application that can be

GCC LD NOLOAD linker section generates loadable segment

懵懂的女人 提交于 2021-01-24 18:44:03
问题 I'm working on an Arm bare-metal application and I've marked some sections with NOLOAD . According to the explanation in Understanding linker script NOLOAD sections in embedded software , I expected the resulting ELF file to not have a loadable segment (program header) for these sections, but it does. Is this correct? Why are those sections marked as loadable in the ELF file? This is a part of my linker script: .bss (NOLOAD) : { . = ALIGN(4); __bss_start__ = .; *(.bss_begin .bss_begin.*) *(