This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Source files order in output image

Hello to all:

How does Linker or Compiler determine that which source file should be located first in base address of device memory? For example we have a project with a startup file.s (stm32f10x_startup.s) and a main.c. We expect that, the object of startup file.s be located in initial address of execute memory (typically ROM) and main.c object, be located after; because, typically, the microcontrollers read address 0x0 after rest to receive MSP base address and then 0x4 to receive Reset handler address, which these information are in startup file corresponding to that microcontroller. So if main.c contents, be located from address 0x0, then the execution encounters with error. Also there maybe another (another.s) file, in this case, how does linker decide which (startup file.s) or (another.s) shouldbe located first?

Parents
  • how linker or compiler knows

    It has command-line options which tell it what type of chip the Target is.

    There are also settings in the Keil project - which tell it memory sizes, etc.

    If you look in the startup file, you will see where the vector table is created:

            MODULE  ?cstartup
    
            ;; Forward declaration of sections.
            SECTION CSTACK:DATA:NOROOT(3)
    
            SECTION .intvec:CODE:NOROOT(2)
    
            EXTERN  __iar_program_start
            EXTERN  SystemInit        
            PUBLIC  __vector_table
    
            DATA
    __vector_table
            DCD     sfe(CSTACK)
            DCD     Reset_Handler             ; Reset Handler
            DCD     NMI_Handler               ; NMI Handler
            DCD     HardFault_Handler         ; Hard Fault Handler
            DCD     MemManage_Handler         ; MPU Fault Handler
            DCD     BusFault_Handler          ; Bus Fault Handler
            DCD     UsageFault_Handler        ; Usage Fault Handler
            
            

Reply
  • how linker or compiler knows

    It has command-line options which tell it what type of chip the Target is.

    There are also settings in the Keil project - which tell it memory sizes, etc.

    If you look in the startup file, you will see where the vector table is created:

            MODULE  ?cstartup
    
            ;; Forward declaration of sections.
            SECTION CSTACK:DATA:NOROOT(3)
    
            SECTION .intvec:CODE:NOROOT(2)
    
            EXTERN  __iar_program_start
            EXTERN  SystemInit        
            PUBLIC  __vector_table
    
            DATA
    __vector_table
            DCD     sfe(CSTACK)
            DCD     Reset_Handler             ; Reset Handler
            DCD     NMI_Handler               ; NMI Handler
            DCD     HardFault_Handler         ; Hard Fault Handler
            DCD     MemManage_Handler         ; MPU Fault Handler
            DCD     BusFault_Handler          ; Bus Fault Handler
            DCD     UsageFault_Handler        ; Usage Fault Handler
            
            

Children
No data