rust-embedded / cortex-m-rt

Minimal startup / runtime for Cortex-M microcontrollers
https://rust-embedded.github.io/cortex-m-rt/
Apache License 2.0
359 stars 85 forks source link

linker not placing __ebss at the end of .bss #267

Closed Dirbaio closed 4 years ago

Dirbaio commented 4 years ago

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)

Dirbaio commented 4 years ago

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.

rafaelcaricio commented 4 years ago

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").