0

I am a little bit confused with ENTRY and STARTUP commands in GCC linker script.

As stated here: http://wiki.osdev.org/Linker_Scripts

ENTRY() makes any symbol to be linked as first item in .text section. STARTUP() on the other hand makes whole compiled file to be placed as first item in .text section.

In my project however it behaves strange.

I am using gnu-arm-none-eabi toolchain and in my linker script command ENTRY(asm_start) makes no effect. Linker script:

ENTRY(asm_start)


MEMORY
{
    RAM : ORIGIN = 0x10000, LENGTH = 0x1000000
    PIC_BUFF : ORIGIN = 0x10000 + LENGTH(RAM), LENGTH = 200M
}

SECTIONS
{
    .text : {*(.text)} > RAM
    .data : {*(.data)} > PIC_BUFF
// etc.

assembly function:

.text

.global asm_start
.global exc_stack
.global supervisor_sp

asm_start:

   # initialize Stack pointer for exception modes
   mrs r4, cpsr
   bic r4, r4, #0x1f

   #FIQ Mode
   orr r3, r4, #0x11
   msr cpsr_c, r3
   ldr sp, =exc_stack

   #IRQ Mode
   orr r3, r4, #0x12
   msr cpsr_c, r3
   // etc.

and asm_start finishes in some random place in memory.

On the other hand STARTUP() function works fine and desired file ends in proper place in .text section.

Could some please explain what exactly is happening in this case?

2
  • I'm not 100% sure about this, but looks like ENTRY() set's the PC starting point on the execution, and STARTUP() the first linked object in the .text Commented May 31, 2016 at 18:07
  • oh, that's so true. " be the very first byte of your loaded program(or the first byte of the .text section in ELF and PE binaries). " but my program is neither ELF nor PE binary. Thanks a lot. Make it as answer and I will accept it. Commented May 31, 2016 at 18:10

1 Answer 1

1

ENTRY() sets the PC starting point on the execution, and STARTUP() the first linked object in the .text

BTW, for baremental cortex ARM gnu-arm-none-eabi, ENTRY() is usually set to the Reset_Handler vector and .text must start with the interrupt vector table.

I've always seen it manually set. but it might be possible to use STARTUP() for that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.