When a const-qualified object has a section attribute, that
section is set to read-only and clang outputs a LLVM IR constant
for that object. This is incorrect for dynamically initialised
objects.
For example:
int init() { return 15; } __attribute__((section("SA"))) const int a = init();
a is allocated to a read-only section and is left
unintialised (zero-initialised).
This patch adds checks if an initialiser is a constant expression
and allocates objects to sections as follows:
- const-qualified objects
- no initialiser or constant initialiser: .rodata
- dynamic initializer: .bss
- non const-qualified objects
- no initialiser or dynamic initialiser: .bss
- constant initializer: .data
(".rodata", ".data", and ".bss" names used just for explanatory
purpose)