<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61212>61212</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
constexpr global with constexpr ctor and dtor is stored in the mutable data section
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zmodem
</td>
</tr>
</table>
<pre>
Consider:
```
$ cat /tmp/a.cc
struct S {
constexpr S(int *i) : p(i) {}
constexpr ~S() {}
int *p;
};
static int i = 1;
static constexpr S foo(&i);
const S& f() { return foo; }
$ build/bin/clang -std=c++20 -O2 -c /tmp/a.cc && objdump -t a.o
a.o: file format elf64-x86-64
SYMBOL TABLE:
0000000000000000 l df *ABS* 0000000000000000 a.cc
0000000000000000 l d .text 0000000000000000 .text
0000000000000000 l O .data 0000000000000008 _ZL3foo <------
0000000000000000 l d .data 0000000000000000 .data
0000000000000008 l O .data 0000000000000004 _ZL1i
0000000000000000 g F .text 0000000000000008 _Z1fv
```
The `foo` object ended up in the `.data` section.
However, if we remove the `constexpr ~S() {}` line, or define it as `= default`, Clang puts the object into `.data.rel.ro`, which I think is what we want.
(GCC puts it in `.data.rel.ro.local` for all three versions of the code.)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVM2SqzYTfRqx6YISAmO8YGHsjy-pmtQs5m6STUpIjVEiECUJe5JFnj0lzIx9Zzy5lAsjqc_p0-of7pw6jYgV2dRkc4z47Htjq78HI3GIWiP_qg5mdEqiJdme0COhb--Crr_rkuUguAfCGj9MhDU8EeJ65LydhYcXINv6ugMAIMzoPL5OFl4IK9UYoHtF2A5Itocp7C2LbU22xxV2w_wTQJ_OAWAlmki2-gqn79-rHu6VWCwVkOwI6WODO4XQGbM4LIKoD-aLXYiigO6mCiz62Y4LMqvhXeTtutpZaUlY06qRsEZoPp4gdl6S7CgIqwmrGYX4mUEsvr9WIKwI3kz7h5yHCWIPPDH39GGZ7aFTGqEzduAeUHdFHr-WRVzk96Yvv_5SPz_Bt3399L_3FNMPD-hwt7ILV7uvXwjbA3yyuWX8CzhA4vHVf0Yu2_8FhWdIJPf8k9cSfv_tKeuMAQCSHeLl-ZGIh0z0uv8QW_5ARR5UpOoLv6cF26zBP4og7c6Pm2p5f-sRSEFDIRU0JB2FBxwlSpgnUCP4q8FVf0HBofDKjMk9yU_mgme0hB1AdXBBsDiYM75hv-6sgoJWIwagsSCxUyOC8sBdwIX2kdjxWfuwYgc4LHU8zd4t3KtcNXrzrjGxqBNrVsClV6KHn8H3avwTlINLz31QeOGjT75vmvL_h8OVWwXOj4yJNoLrILkzFrjW4HuLCGe0TpnRgekWUcJITAjbRbLK5C7b8QirtNiWdFduy03UVxukuOEdZl234TlnLS3kpmvzLae5SHe7SFWMsoxmtEhpltFN0qYybVtBs1SWvEw5ySkOXOlE6_OQGHuKlHMzVkXKUhZp3qJ2y9BlbOl8wliYv7YK9nE7nxzJqVbOuxuDV15jdUvVSZuWa7go398NK-FD7KMEGT6UA-eNRflWKMPseasRlkJeKyWara567ycXJgBrCGtOyvdzmwgzENYEBetfPFkTMkpYswTkCGuWmP4NAAD__9P4voU">