I'm trying to run a simple linker script to understand how linking works and how i can implement function reordering with the linker script
Here is my C code
void A(){
printf("A\n");
}
void B(){
printf("B\n");
}
void main(){
B();
A();
}
Here is the linker script
SECTIONS
{
. = 0x10000;
.text : { *(.text) }
. = 0x8000000;
.data : { *(.data) }
.bss : { *(.bss) }
}
When i try to compile with this external linker script it gives me this error
/usr/lib64/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
(.text+0x14): undefined reference to `__init_array_start'
/usr/lib64/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
(.text+0x1c): undefined reference to `__init_array_end'
/usr/bin/ld: cl: hidden symbol `__init_array_end' isn't defined
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
My compile command is this
gcc -Wl,-no-whole-archive -ffunction-sections -T simple.ld cache_ex.c -o cl
Can you tell me what i'm doing wrong?