Skip to content

add (.symtab) size info to external assembly functions #211

Closed
@japaric

Description

@japaric

Our external assembly subroutines (e.g. __nop) are not properly reporting their size in the .symtab section. If you build the cortex-m-quickstart template and print the contents of the symbol table (.symtab) you'll see that those assembly subroutines report their size as 0.

$ arm-none-eabi-readelf -s target/thumbv7m-none-eabi/release/app
(..)
     8: 0000040b    10 FUNC    LOCAL  DEFAULT    2 _ZN3app18__cortex_m_rt_ma
(..)
    21: 00000415   154 FUNC    GLOBAL DEFAULT    2 Reset
(..)
    30: 000004b3     0 FUNC    GLOBAL DEFAULT    2 __nop

The first two lines (Rust functions) are correct. The last line (__nop) is wrongly reporting its size as 0.

This bug won't affect linking or the runtime behavior of the program but may cause ELF post-processing tools to incorrectly interpret these functions as tags (e.g. $t.0), which are also zero sized, and discard them which may result in invalid output binaries.

To add size info you need to add the following line to the existing subroutines in the asm*.s files:

   .section .text.__bkpt
   .global __bkpt
   .thumb_func
 __bkpt:
   bkpt
   bx lr
+  .size __bkpt, . - __bkpt

Note that the name of the subroutine needs to be used in the .size directive (__bkpt in the example)

After modifying those files you'll need to re-assemble the files by running the ./assemble.sh script.

After making those changes you should see the correct size in the output of readelf:

$ arm-none-eabi-readelf -s target/thumbv7m-none-eabi/release/app
(..)
    30: 000004b3     4 FUNC    GLOBAL DEFAULT    2 __nop

P.S. many other crates that use external assembly (cortex-m-rt, cortex-m-semihosting, etc.) need this fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions