rust-embedded / cortex-m-rt

Minimal startup / runtime for Cortex-M microcontrollers

Home Page:https://rust-embedded.github.io/cortex-m-rt/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

linker not placing __ebss at the end of .bss

Dirbaio opened this issue · comments

This is happening to me when linking with C code. C code is compiled with clang 10 into a static lib and then linked with the crate. This causes the C code to break because globals are filled with garbage on boot, instead of zerofilled.

[dirbaio@mars firmware]$ readelf -s target/thumbv7em-none-eabihf/debug/firmware2
   [snip]
  1851: 20020334     0 NOTYPE  GLOBAL DEFAULT   16 __ebss
   [snip]

[dirbaio@mars firmware]$ readelf target/thumbv7em-none-eabihf/debug/firmware2 -S

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
   [snip]
  [16] .bss              NOBITS          20011e08 01ae08 00e5b2 00  WA  0   0  8
   [snip]

As you can see, .bss is 0x20011e08-0x200203ba but __ebss is at 0x20020334, in the middle of it.

rustc version: 1.44.0-nightly (b2e36e6c2 2020-04-22)

It seems it has to do with INSERT AFTER (see #266). I can't reproduce it without it. I also found that defining __ebss outside the section fixes it.

Thanks @Dirbaio ! I was having the same issue as you and it's now it's working for me after I made the change you mentioned ("defining __ebss outside the section").