что за нулевая строка в скрипте линкера?
От: another_one  
Дата: 11.10.22 08:56
Оценка:
Здравствуйте!

Я пытаюсь создать линкер скрипт и Си рантайм для MIPS64 используя cygwin64 + mips-mti-elf

Вот мой скрипт:
OUTPUT_FORMAT("elf64-tradlittlemips")
SEARCH_DIR(objs)
GROUP(-lc -lgcc)
STARTUP(mcrt.o)
PROVIDE(    _vector_spacing     = 0x00000001    );
PROVIDE(    _ebase_address      = 0xB5000000    );
PROVIDE(     _stack         = 0xB503FFFF    );
PROVIDE(     text_start     = 0xB5000FA0    );
PROVIDE(     data_start     = 0xB500FA00    );
PROVIDE(     bss_start      = 0xB502EE00    );
PROVIDE(     heap_start     = 0xB5032C80    );
PROVIDE(    _RESET_ADDR                     = 0xBFC00000    );
PROVIDE(    _SRAM_ADDR_2_EX = 0xB5000000    );              
PROVIDE(    _GEN_EXCPT_ADDR                 = _ebase_address + 0x180    );

_SIMPLE_TLB_REFILL_EXCPT_ADDR  = _ebase_address + 0;
_CACHE_ERR_EXCPT_ADDR          = _ebase_address + 0x100;
_GEN_EXCPT_ADDR                = _ebase_address + 0x180;

MEMORY
    {
        ram         (rwx) : ORIGIN = 0xB5000000, LENGTH = 0x3FFFF 
    }

ENTRY(_startup)  
SECTIONS

    . = _text_start;
    .text :
    {   
        . = ALIGN(4);
        KEEP(*(.simple_tlb_refill_vector))
        . = _CACHE_ERR_EXCPT_ADDR;
        KEEP(*(.cache_err_vector))
        . = _GEN_EXCPT_ADDR;
        KEEP(*(.gen_handler))
        _startup = .;
        KEEP(*(.init))

        KEEP(*(.text))
        *(.text)
        *(.text.*)  
    } 
    
    . = data_start;
    .data :
    {
        . = ALIGN(4);   
        _gp = . ;
        KEEP(*(.data))
        *(.data)
        *(.data.*)
    } 

    . = bss_start;
    .bss : 
    {
        . = ALIGN(4);
            KEEP(*(.bss))
        *(.bss)
        *(.bss.*)
            
    }

    . = heap_start;
    .heap :
    {
            . = ALIGN(4);
        KEEP(*(.heap))  
            *(.heap)
            *(.heap.*)
        
    } 

    __stack = ORIGIN(ram) + LENGTH(ram);
}


Вот мой Си рантайм:

#include <mips/asm.h>
#include <mips/regdef.h>
#include <mips/mips64.h>
##include <mips.h> 
#  .set nomips16 
        ##################################################################
        # Entry point of the entire application
        ##################################################################
        /* This file contains 32-bit assembly code */
        .set nomips16
        
        ##################################################################
        # Startup code
        ##################################################################
        .section .init
        .align 2
        .set noreorder
        .ent _startup
_startup: .global _startup

        ##################################################################
        # Initialize CP0 registers
        ##################################################################
        # Подготавливаем Cause Register
        mfc0     $26,  $13,  0                  
        lui      $27,  0x0080                  
        or       $26,  $26,  $27            
        mtc0     $26,  $13,   0                 

        
        mfc0     $26,  $12,   1                 
        ori      $27,  $0,   0x20              
        or       $26,  $26,  $27           
        mtc0     $26,  $12,   1                  

        
        mfc0     $26,  $15,   1                 
        lui      $27,  0x1500                   
        or       $26,  $26,  $27           
        mtc0     $27,  $15,   1                 

        
        mfc0     $26,  $12,   0                 
        lui      $27,  0x0040                  
        ori      $27,  $27, 0xFC06           
        nor      $27,  $0, $27               
        and      $26,  $26,  $27           
        mtc0     $26,  $12,   0                  


        ##################################################################
        # EBASE configure
        ##################################################################
        mfc0     $26,  $15,   1
        lui      $27,  0x1500
        or       $26,  $26,  $27
        mtc0     $26,  $15,   1
        ##################################################################
        # Initialize Stack Pointer
        #   _stack is initialized by the linker script to point to the
        #    starting location of the stack in RAM
        ##################################################################
        dla      sp,__stack

        ##################################################################
        # Initialize Global Pointer
        #   _gp is initialized by the linker script to point to "middle"
        #   of the small variables region
        ##################################################################
        dla      gp,_gp


        ##################################################################
        # Fill stack
        # TODO - handle different stack lengths:
        # mulitple of 4, 8, 16, or 32
        ##################################################################
        dla      t0,_stack_start
        dla      t1,_stack
        b       _stack_check

_stack_init:
        sw      zero,0x0(t0)
        sw      zero,0x4(t0)
        sw      zero,0x8(t0)
        sw      zero,0xc(t0)
        addu    t0,16

_stack_check:
        bltu    t0,t1,_stack_init
        nop



        ##################################################################
        # Clear uninitialized data sections
        ##################################################################
        dla      t0,_bss_begin
        dla      t1,_bss_end
        b       _bss_check
        nop

_bss_init:
        sw      zero,0x0(t0)
        sw      zero,0x4(t0)
        sw      zero,0x8(t0)
        sw      zero,0xc(t0)
        addu    t0,16
_bss_check:
        bltu    t0,t1,_bss_init
        nop

 
        ##################################################################
        #   Initializes data section
        #   Warning: _data_image_start, _data_image_end, _data_start 
        #   must be aligned to word address (check linker script)!
        ##################################################################
init_data_section:
        dla     t0, _data_image_start
        dla     t1, _data_image_end
        dla     t2, _data_start
    #init_data_loop:
    #   beq     t0, t1, init_data_done
    #   nop
    #   lw      t3, (t0)
    #   addiu   t0, 4
    #   sw      t3, (t2)
    #   b       init_data_loop
    #   addiu   t2, 4
    #init_data_done:
    #   jr      ra
    #   nop
        .end _startup   
        
        ##################################################################
        # General Exception Vector Handler
        # Jumps to _general_exception_context
        ##################################################################
        .section .gen_handler
        .set noreorder
        .ent _gen_exception
_gen_exception:
/*0:      dla      k0,_general_exception_context
        jr      k0*/
        nop

        .end _gen_exception


        ##################################################################
        # Simple TLB-Refill Exception Vector
        # Jumps to _simple_tlb_refill_exception_context
        ##################################################################
        .section .simple_tlb_refill_vector
        .set noreorder
        .ent simple_tlb_refill_vector
simple_tlb_refill_vector:
       /* dla      k0,_simple_tlb_refill_exception_context
        jr      k0*/
        nop

        .end simple_tlb_refill_vector


   ##################################################################
        # Cache-Error Exception Vector Handler
        # Jumps to _cache_err_exception_context
        ##################################################################
        .section .cache_err_vector
        .set noreorder
        .ent _cache_err_vector
_cache_err_vector:
        /*la      k0,_cache_err_exception_context
        jr      k0*/
        nop

        .end _cache_err_vector

        .section .text
        .ent _main_entry
_main_entry:


        ##################################################################
        # Call main
        ##################################################################
        jal main
        nop


        .end _main_entry


Но в процессе сборки возникают следующие предупреждения:
src/mcrt.S:162: Warning: .ent or .aent not in text section

src/mcrt.S:168: Warning: .end not in text section

src/mcrt.S:177: Warning: .ent or .aent not in text section

src/mcrt.S:183: Warning: .end not in text section

src/mcrt.S:192: Warning: .ent or .aent not in text section

src/mcrt.S:198: Warning: .end not in text section


и также одна ошибка на этапе (APP).elf: $(TOBJS) $(CC) $(LDFLAGS) $^ -o $@" мейкфайла:

c:/tmp/cygwin64/usr/local/mips-mti-elf/2017.10-08/bin/../lib/gcc/mips-mti-elf/6.3.0/../../../..

/mips-mti-elf/bin/ld.exe:script1.ld:0: syntax error

collect2.exe: error: ld returned 1 exit status

make: *** [Makefile:49: mipsoutput.elf] Error 1


Я не понимаю на какую нулевую строку ссылается линкер в моем script1.ld

И также не понимаю почему init секция не в текст секции(согласно предупрежениям), когда как я ее там сохраняю

text
{
...
"KEEP(*(.init))"
...
}

Прошу помочь разобраться

Заранее благодарен
Re: что за нулевая строка в скрипте линкера?
От: Maniacal Россия  
Дата: 14.10.22 06:58
Оценка:
Здравствуйте, another_one, Вы писали:

_>Я пытаюсь создать линкер скрипт и Си рантайм для MIPS64 используя cygwin64 + mips-mti-elf


_>
_>c:/tmp/cygwin64/usr/local/mips-mti-elf/2017.10-08/bin/../lib/gcc/mips-mti-elf/6.3.0/../../../..

_>/mips-mti-elf/bin/ld.exe:script1.ld:0: syntax error

_>collect2.exe: error: ld returned 1 exit status

_>make: *** [Makefile:49: mipsoutput.elf] Error 1

_>


_>Я не понимаю на какую нулевую строку ссылается линкер в моем script1.ld


Вот тут нечто похожее у человека было:
http://rsdn.org/forum/cpp.applied/8381061
Автор: another_one
Дата: 11.10.22


Ему ответили

Ok Ken, I see what’s going on here. You need to copy the linker_script.ld file from the upper level directory into the directory where your code lives. This will replace the existing linker_script.ld which, as you noticed, simply links back to the file one directory up. The origin of this problem lies with the fact that I write my code on Linux. Linux allows me create symbolic links between files (similar to the concept of a Windows Shortcut). This feature of Linux is lost in translation when you copy to a Windows system.

Re[2]: что за нулевая строка в скрипте линкера?
От: CreatorCray  
Дата: 14.10.22 08:43
Оценка:
Здравствуйте, Maniacal, Вы писали:

M>Linux allows me create symbolic links between files (similar to the concept of a Windows Shortcut).

1. Symlink и shortcut это очень разные вещи.
2. В NTFS давно есть симлинки (см mklink)

M> This feature of Linux is lost in translation when you copy to a Windows system.

Это не фича линукса, это фича файловой системы.
... << RSDN@Home 1.3.110 alpha 5 rev. 62>>
Re[3]: что за нулевая строка в скрипте линкера?
От: another_one  
Дата: 14.10.22 09:06
Оценка:
Здравствуйте, CreatorCray, Вы писали:

CC>Здравствуйте, Maniacal, Вы писали:


M>>Linux allows me create symbolic links between files (similar to the concept of a Windows Shortcut).

CC>1. Symlink и shortcut это очень разные вещи.
CC>2. В NTFS давно есть симлинки (см mklink)

M>> This feature of Linux is lost in translation when you copy to a Windows system.

CC>Это не фича линукса, это фича файловой системы.


Спасибо за поддержку!

В итоге вопрос решился, была проблема с кодировкой и виднелась нулевая строка, я взял уже не из нодпада вновь созданный файл а кописастил в ранее созданный кем то как то работающий
Но сейчас другая проблема
Почему то проблема с областями и памятью


c:/tmp/cygwin64/usr/local/mips-mti-elf/2017.10-08/bin/../lib/gcc/mips-mti-elf/6.3.0/../../../../mips-mti-elf/bin/ld.exe: small-data section exceeds 64KB; lower small-data size limit (see option -G)
objs/main.o: In function `main':
C:\tmp\cygwin64\home\V\free/src/main.c:63:(.text+0x44): relocation truncated to fit: R_MIPS_GPREL16 against `.sbss'
C:\tmp\cygwin64\home\V\free/src/main.c:65:(.text+0x48): relocation truncated to fit: R_MIPS_GPREL16 against `.sbss'
objs/main.o: In function `FillTask':
C:\tmp\cygwin64\home\V\free/src/main.c:168:(.text+0x2f8): relocation truncated to fit: R_MIPS_GPREL16 against `.sbss'
objs/main.o: In function `CheckTask':
C:\tmp\cygwin64\home\V\free/src/main.c:181:(.text+0x364): relocation truncated to fit: R_MIPS_GPREL16 against `.sbss'
objs/tasks.o: In function `prvAddNewTaskToReadyList':
C:\tmp\cygwin64\home\V\free/src/FreeRTOS/tasks.c:999:(.text+0x3c0): relocation truncated to fit: R_MIPS_GPREL16 against `.sbss'
C:\tmp\cygwin64\home\V\free/src/FreeRTOS/tasks.c:999:(.text+0x3c8): relocation truncated to fit: R_MIPS_GPREL16 against `.sbss'
C:\tmp\cygwin64\home\V\free/src/FreeRTOS/tasks.c:1000:(.text+0x3cc): relocation truncated to fit: R_MIPS_GPREL16 against `pxCurrentTCB'
C:\tmp\cygwin64\home\V\free/src/FreeRTOS/tasks.c:1004:(.text+0x3e0): relocation truncated to fit: R_MIPS_GPREL16 against `pxCurrentTCB'
C:\tmp\cygwin64\home\V\free/src/FreeRTOS/tasks.c:1006:(.text+0x3e4): relocation truncated to fit: R_MIPS_GPREL16 against `.sbss'
C:\tmp\cygwin64\home\V\free/src/FreeRTOS/tasks.c:1023:(.text+0x410): relocation truncated to fit: R_MIPS_GPREL16 against `.sbss'
C:\tmp\cygwin64\home\V\free/src/FreeRTOS/tasks.c:1025:(.text+0x420): additional relocation overflows omitted from the output
collect2.exe: error: ld returned 1 exit status


Текущий ld:

ENTRY(_start)
OUTPUT_FORMAT("elf64-tradlittlemips")
SEARCH_DIR(objs)
__DYNAMIC  =  0;
GROUP(-lc -lgcc)
STARTUP(minicrt.o)
PROVIDE(    _vector_spacing        = 0x00000001    );
PROVIDE(    _ebase_address        = 0xB5000000    );
PROVIDE(     _stack            = 0xB503FFFF      );
PROVIDE(     text_start        = 0xB5000FA0     );
PROVIDE(     data_start        = 0xB500FA00     );
PROVIDE(     bss_start        = 0xB502EE00    );
PROVIDE(     heap_start        = 0xB5032C80    );
PROVIDE(    _SRAM_ADDR_2_EX    = 0xB5000300    );                


_SIMPLE_TLB_REFILL_EXCPT_ADDR  =  0;
_CACHE_ERR_EXCPT_ADDR          =  0x100;
_GEN_EXCPT_ADDR                =  0x180;



    MEMORY
    {
          ram           (rwx) : ORIGIN = 0xB5000000, LENGTH = 0x3FFFF 
    }



ENTRY(_startup)  
SECTIONS
{
  
    
    .text :
      {    
        
        _text_start = ALIGN(8);    
    
        
        KEEP(*(.simple_tlb_refill_vector))

        
        KEEP(*(.cache_err_vector))
        
        
        KEEP(*(.gen_handler))
         
        KEEP(*(.init))
        
            *(.text)
            *(.text.*)
        
        *(.rodata)
        *(.rodata.*)
        
        
        
        _main_entry = . ;
        KEEP(*(.main_entry))
        
        _text_end = ALIGN(8);
        
        
      } > ram
    
    
       .data :
      {
        _data_start = ALIGN(8);    
                    
            *(.data)
            *(.data.*)
        _gp = ABSOLUTE(. + 0x7ff0); /* Base of small data            */
        *(.sdata)
        *(.sdata.*)
        _data_end = ALIGN(8);    
      } > ram

    
    .bss : 
    {
        
        _bss_start = ALIGN(8);
        *(.bss)
        *(.bss.*)
        *(.sbss)
        *(.sbss.*)    
         _bss_end = ALIGN(8) ;
    }  > ram 
    
     
    
    .heap :
      {
        
        _heap_start = ALIGN(8);
            *(.heap)
            *(.heap.*)
        _heap_end = ALIGN(8);
        
      } > ram 
     _stack_bottom = .;
    PROVIDE( _stack_top = _stack -64  );
    PROVIDE( __stack = _stack - 64);
    PROVIDE( _stack_start = _stack_top);
    PROVIDE( _bss_begin  = _bss_start );
    PROVIDE( _bss_begin  = _bss_start );
    PROVIDE(_data_image_start = _data_start);
      PROVIDE(_data_image_end = _bss_start);

        
    /*/DISCARD/ :
    {
        *.o (.MIPS.options)
        *.o (.MIPS.abiflags)
        *.o (.gnu.attributes)
                
    }*/
    
}
Re[4]: что за нулевая строка в скрипте линкера?
От: CreatorCray  
Дата: 14.10.22 09:21
Оценка:
Здравствуйте, another_one, Вы писали:

_>Спасибо за поддержку!

Да не за что в общем то.

_>ld.exe: small-data section exceeds 64KB; lower small-data size limit (see option -G)

Говорит что данных многовато.
... << RSDN@Home 1.3.110 alpha 5 rev. 62>>
Re[5]: что за нулевая строка в скрипте линкера?
От: another_one  
Дата: 14.10.22 09:29
Оценка:
Здравствуйте, CreatorCray, Вы писали:

CC>Здравствуйте, another_one, Вы писали:


_>>Спасибо за поддержку!

CC>Да не за что в общем то.

_>>ld.exe: small-data section exceeds 64KB; lower small-data size limit (see option -G)

CC>Говорит что данных многовато.

Да, но под этим кроется нечто другое
https://www.microchip.com/forums/m949546-p2.aspx
Но я до сих пор не пойму как ее фиксить
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.