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

how to get the object file with secure interface

I'm trying to build some sample sources from Keil MDK with GNU embedded compiler.

I have built an secure elf file and tried to make the object file with secure interface like this.

arm-none-eabi-ld ./cm33_s.elf -T linker.ld --out-implib ./cmse_lib.o --cmse-implib

 I can get the library file but some warnings and an error occurred. And the object file size is the same as one from ARM compiler.

arm-none-eabi-ld: ./cm33_s.elf: `Secure_LED_Off_callback' and its special symbol are in different sections.
arm-none-eabi-ld: ./cm33_s.elf: `Secure_printf' and its special symbol are in different sections.
arm-none-eabi-ld: ./cm33_s.elf: `Secure_LED_On_callback' and its special symbol are in different sections.
arm-none-eabi-ld: ./cm33_s.elf: `Secure_LED_Off' and its special symbol are in different sections.
arm-none-eabi-ld: ./cm33_s.elf: `Secure_LED_On' and its special symbol are in different sections.
arm-none-eabi-ld: cannot size stub section: Invalid operation
arm-none-eabi-ld: a.out: warning: allocated section `.text' not in segment
arm-none-eabi-ld: a.out: warning: allocated section `.gnu.sgstubs' not in segment
arm-none-eabi-ld: a.out: warning: allocated section `.data' not in segment
arm-none-eabi-ld: a.out: warning: allocated section `STACK' not in segment
arm-none-eabi-ld: a.out: warning: allocated section `HEAP' not in segment

The linker script file is like this.

ENTRY(Reset_Handler)

MEMORY
{
RAM (xrw) : ORIGIN = 0x10000000, LENGTH = 0x1000000 /* Secure SRAM */
}

SECTIONS {
.text :
{
. = ALIGN(4);
*(.RESET*)
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} >RAM

.gnu.sgstubs :
{
. = ALIGN(4);
_start_sg = .;
*(.gnu*)
. = ALIGN(4);
_end_sg = .;
} >RAM

.data :
{
. = ALIGN(4);
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM

. = ALIGN(4);
STACK :
{
KEEP(*(STACK*));
} > RAM

. = ALIGN(4);
HEAP :
{
KEEP(*(HEAP*));
} > RAM

. = ALIGN(4);

.ARM.exidx 0 (NOLOAD) : { *(.ARM.exidx*) }
.ARM.attributes 0 : { *(.ARM.attributes) }
}

 

And if I change the above red line to ".ARM.attributes 0 (NOLOAD) : { *(.ARM.attributes)}", 

there are no errors but the object file size is quite big. 

 

Could you let me know how I can solve the warnings and error? ^^

 

  • The NOLOAD directive will mark a section to not be loaded at run time. The linker will process the section normally, but will mark it so that a program loader will not load it into memory.

    So if you added NOLOAD for red code line, those sections are ignored by program loader; while linker still keeps the sections contents igoring the warning/errors.  
     
    Also did some goolge work, some suggestions for you are:
    1) Upgrade your GNU linker to the latest if possible
    2) Try to add PHDRS header in linker script

    PHDRS
    {
    text PT_LOAD;
    data PT_LOAD;
    bss PT_LOAD;
    STACK PT_NULL;
    HEAP PT_NULL;
    }

    Please refer to www.avrfreaks.net/.../allocated-section-xyz-not-segment-solved

  • Which Keil MDK example are you trying to compile?
  • Thank you for your answer, but it doesn't seem to solve my problem. There's no program headers in the correct object file which has secure interfaces as follows.

    correct one:
    ======================================
    ELF Header:
    Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
    Class: ELF32
    Data: 2's complement, little endian
    Version: 1 (current)
    OS/ABI: UNIX - System V
    ABI Version: 0
    Type: EXEC (Executable file)
    Machine: ARM
    Version: 0x1
    Entry point address: 0x0
    Start of program headers: 0 (bytes into file)
    Start of section headers: 300 (bytes into file)
    Flags: 0x5000200, Version5 EABI, soft-float ABI
    Size of this header: 52 (bytes)
    Size of program headers: 0 (bytes)
    Number of program headers: 0
    Size of section headers: 40 (bytes)
    Number of section headers: 4
    Section header string table index: 3

    Section Headers:
    [Nr] Name Type Addr Off Size ES Flg Lk Inf Al
    [ 0] NULL 00000000 000000 000000 00 0 0 0
    [ 1] .symtab SYMTAB 00000000 000034 000070 10 2 1 4
    [ 2] .strtab STRTAB 00000000 0000a4 00006a 00 0 0 1
    [ 3] .shstrtab STRTAB 00000000 00010e 00001b 00 0 0 1
    Key to Flags:
    W (write), A (alloc), X (execute), M (merge), S (strings)
    I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
    O (extra OS processing required) o (OS specific), p (processor specific)

    There are no section groups in this file.

    There are no program headers in this file.

    There are no relocations in this file.

    There are no unwind sections in this file.

    Symbol table '.symtab' contains 7 entries:
    Num: Value Size Type Bind Vis Ndx Name
    0: 00000000 0 NOTYPE LOCAL DEFAULT UND
    1: 1000ca81 8 FUNC GLOBAL DEFAULT ABS Secure_LED_Off_callback
    2: 1000ca89 8 FUNC GLOBAL DEFAULT ABS Secure_LED_Off
    3: 1000ca91 8 FUNC GLOBAL DEFAULT ABS Secure_printf
    4: 1000ca99 8 FUNC GLOBAL DEFAULT ABS Secure_printf2
    5: 1000caa1 8 FUNC GLOBAL DEFAULT ABS Secure_LED_On_callback
    6: 1000caa9 8 FUNC GLOBAL DEFAULT ABS Secure_LED_On
    ======================================

    wrong one:
    ======================================
    ELF Header:
    Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
    Class: ELF32
    Data: 2's complement, little endian
    Version: 1 (current)
    OS/ABI: UNIX - System V
    ABI Version: 0
    Type: EXEC (Executable file)
    Machine: ARM
    Version: 0x1
    Entry point address: 0x0
    Start of program headers: 52 (bytes into file)
    Start of section headers: 137096 (bytes into file)
    Flags: 0x5000200, Version5 EABI, soft-float ABI
    Size of this header: 52 (bytes)
    Size of program headers: 32 (bytes)
    Number of program headers: 3
    Size of section headers: 40 (bytes)
    Number of section headers: 4
    Section header string table index: 3

    Section Headers:
    [Nr] Name Type Addr Off Size ES Flg Lk Inf Al
    [ 0] NULL 00000000 000000 000000 00 0 0 0
    [ 1] .symtab SYMTAB 00000000 0216b0 000060 10 2 1 4
    [ 2] .strtab STRTAB 00000000 021710 00005b 00 0 0 1
    [ 3] .shstrtab STRTAB 00000000 02176b 00001b 00 0 0 1
    Key to Flags:
    W (write), A (alloc), X (execute), M (merge), S (strings)
    I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
    O (extra OS processing required) o (OS specific), p (processor specific)

    There are no section groups in this file.

    Program Headers:
    Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
    LOAD 0x010000 0x00000000 0x00000000 0x00000 0x00008 R 0x10000
    LOAD 0x010000 0x10000000 0x10000000 0x0ca90 0x0ca90 R E 0x10000
    LOAD 0x020000 0x10100000 0x10100000 0x016b0 0x016b0 RWE 0x10000

    Section to Segment mapping:
    Segment Sections...
    00
    01
    02

    There is no dynamic section in this file.

    There are no relocations in this file.

    There are no unwind sections in this file.

    Symbol table '.symtab' contains 6 entries:
    Num: Value Size Type Bind Vis Ndx Name
    0: 00000000 0 NOTYPE LOCAL DEFAULT UND
    1: 10100001 8 FUNC GLOBAL DEFAULT ABS Secure_LED_Off_callback
    2: 10100009 8 FUNC GLOBAL DEFAULT ABS Secure_LED_Off
    3: 10100011 8 FUNC GLOBAL DEFAULT ABS Secure_printf
    4: 10100019 8 FUNC GLOBAL DEFAULT ABS Secure_LED_On_callback
    5: 10100021 8 FUNC GLOBAL DEFAULT ABS Secure_LED_On
    ======================================
  • IOT-Kit CM33 Secure/Non-Secure sample source
  • Hi Jinha,

    The model used by the GNU linker is to create the SG import library as part of the link process, not after from the secure executable. I would need to look into the cm33_s.elf secure executable to tell you for sure.

    Therefore I would recommend to either create the SG import library with keil or do the link with GNU ld.
  • Hello Thomas,

    Please describe how can we create SG impoty library as part of link process? 

    Regards,

    Deepika

  • Hi Deepika,

    The link should look like ld --start-section=.gnu.sgstubs=0x1000 --out-implib=implib.o --cmse-implib where 0x1000 should be replaced with the start address of your non-secure callable region and implib.o is your import library. If linking with GCC that translates into gcc secure1.c secure2.c -Wl,--start-section=.gnu.sgstubs=0x1000,--out-implib=implib.o,--cmse-implib.

    If you realize after distributing implib.o that you want to add some more entry points in your secure application, then you'll also add --in-implib=implib.o which instructs the linker to keep the addresses unchanged for all the symbol already present in implib.o.

    Best regards.