Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22248

How to run a linker script for GCC

$
0
0

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?


Viewing all articles
Browse latest Browse all 22248

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>