Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
japaric opened this issue Apr 28, 2020 · 0 comments · Fixed by #212
Closed

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

japaric opened this issue Apr 28, 2020 · 0 comments · Fixed by #212

Comments

@japaric
Copy link
Member

japaric commented Apr 28, 2020

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

stianeklund added a commit to stianeklund/cortex-m that referenced this issue Apr 28, 2020
bors bot added a commit that referenced this issue Apr 29, 2020
212: Add symtab (size info) for all external assembly functions r=japaric a=stianeklund

Adds `.size` info for all of the external assembly functions. 
Fixes #211

Co-authored-by: Stian Eklund <[email protected]>
bors bot added a commit that referenced this issue May 5, 2020
212: Add symtab (size info) for all external assembly functions r=japaric a=stianeklund

Adds `.size` info for all of the external assembly functions. 
Fixes #211

Co-authored-by: Stian Eklund <[email protected]>
@bors bors bot closed this as completed in 392eef8 May 5, 2020
@bors bors bot closed this as completed in #212 May 5, 2020
adamgreig pushed a commit that referenced this issue Jan 12, 2022
211: Bump rand dependency to 0.7 r=korken89 a=therealprof

Signed-off-by: Daniel Egger <[email protected]>

Co-authored-by: Daniel Egger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant