Motivation
I'm learning how to use and write my own linker scripts.
The problem
Currently, I have 2 simple functions in a .c
file and I'd like to put each of those functions in separate sections, but I couldn't found out how to "access" those functions in the linker script.
Reproduction steps
Those two files are all in the same directory:
file1.c
int func1() {
return 10;
}
char * func3() {
return (void *) 0;
}
linker.ld
SECTIONS {
.text 0xDEADBEEF : {
file1.o (.text.func1)
}
.data 0x4 : {
file1.o (.text.func3)
}
}
Now do the following:
gcc -c file1.c
ld -T linker.ld file1.o
Expected/Desired output
What I expect to get from objdump -d a.out
:
a.out: file format elf64-x86-64
Disassembly of section .text:
00000000deadbeef <func1>:
deadbeef: 55 push %rbp
deadbef0: 48 89 e5 mov %rsp,%rbp
deadbef3: b8 0a 00 00 00 mov $0xa,