This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/71113] Adding "const" to value in constexpr constructor places const object in .bss instead of .rodata
- From: "freddie_chopin at op dot pl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 14 May 2016 10:25:11 +0000
- Subject: [Bug c++/71113] Adding "const" to value in constexpr constructor places const object in .bss instead of .rodata
- Auto-submitted: auto-generated
- References: <bug-71113-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71113
--- Comment #1 from Freddie Chopin <freddie_chopin at op dot pl> ---
BTW, I've come to the code as above from a slightly different scenario -
initially I tried using references, but it was failing (placed in RAM, not in
flash) no matter what I did. Now I think that the two problems may be related,
so one more example:
-- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 --
class X
{
public:
constexpr X(int& ref) :
ref_{ref}
{
}
private:
int& ref_;
};
#define PERIPHERAL1 (int*)0x20000000
const X xxx1 {*PERIPHERAL1};
int something;
const X xxx2 {something};
int main()
{
}
-- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 --
Test compilation:
-- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 --
$ g++ test.cpp && objdump -x --syms --demangle a.out | grep xxx
0000000000600a70 l O .bss 0000000000000008 xxx1
0000000000400658 l O .rodata 0000000000000008 xxx2
-- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 -- >8 --
The object with reference to "real" int is placed in .rodata, the one with the
reference to "peripheral" - in .bss.