[AVR] correctly declare __do_copy_data and __do_clear_bss
authorAyke van Laethem <aykevanlaethem@gmail.com>
Mon, 2 Jan 2023 00:21:19 +0000 (01:21 +0100)
committerAyke van Laethem <aykevanlaethem@gmail.com>
Sun, 8 Jan 2023 17:56:06 +0000 (18:56 +0100)
commit167338de9687a8e65672001aa4c4f2e62cf45a76
treed463b4f16e61ad20f98e6c9cb4d517f8fd51ef82
parent91487b2481959aba976cc24b480a4be3784d50d5
[AVR] correctly declare __do_copy_data and __do_clear_bss

These two symbols are declared in object files to indicate whether .data
needs to be copied from flash or .bss needs to be cleared. They are
supported on avr-gcc and reduce firmware size a bit, which is especially
important on very small chips.

I checked the behavior of avr-gcc and matched it as well as possible.
From my investigation, it seems to work as follows:

__do_copy_data is set when the compiler finds a data symbol:
  * without a section name
  * with a section name starting with ".data" or ".gnu.linkonce.d"
  * with a section name starting with ".rodata" or ".gnu.linkonce.r" and
    flash and RAM are in the same address space

__do_clear_bss is set when the compiler finds a data symbol:
  * without a section name
  * with a section name that starts with .bss

Simply checking whether the calculated section name starts with ".data",
".rodata" or ".bss" should result in the same behavior.

Fixes: https://github.com/llvm/llvm-project/issues/58857

Differential Revision: https://reviews.llvm.org/D140830
llvm/lib/Target/AVR/AVRAsmPrinter.cpp
llvm/lib/Target/AVR/AVRDevices.td
llvm/lib/Target/AVR/AVRSubtarget.h
llvm/test/CodeGen/AVR/clear-bss.ll
llvm/test/CodeGen/AVR/no-clear-bss.ll [new file with mode: 0644]
llvm/test/CodeGen/AVR/no-copy-data.ll [new file with mode: 0644]