[Bug middle-end/91899] Merge constant literals
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91899 Andrew Pinski changed: What|Removed |Added Resolution|--- |WONTFIX Status|NEW |RESOLVED --- Comment #6 from Andrew Pinski --- You need to use -fmerge-all-constants and the linker will merge them.
[Bug middle-end/91899] Merge constant literals
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91899 --- Comment #5 from joseph at codesourcery dot com --- Note that you can use -fmerge-all-constants to tell the compiler to allow merging named constant objects (I haven't checked if that helps in this case, however).
[Bug middle-end/91899] Merge constant literals
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91899 --- Comment #4 from Antony Polukhin --- (In reply to Alexander Monakov from comment #3) > unless the compiler somehow proves that overlap is not > observable? Oh, now I see. Here's a valid example: static const char data1[] = "test"; static const char data2[] = "test test"; char lookup1(int i) { return data1[i]; } char lookup2(int i) { return data2[i]; } data1/2 are internal linkage symbols and pointers to them or their content are not returned or passed to any other function. So the overlap is not observable. The above case could be found in std::to_chars, where different internal functions have overlapping `static constexpr char __digits[]` arrays.
[Bug middle-end/91899] Merge constant literals
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91899 Alexander Monakov changed: What|Removed |Added CC||amonakov at gcc dot gnu.org --- Comment #3 from Alexander Monakov --- (In reply to Richard Biener from comment #2) > The question is why data1/2 live in .rodata rather than in the mergeable > strings section. Because they are named constant objects, not unnamed string literals, and therefore GCC cannot allow them to overlap at runtime by emitting them to a mergeable section... unless the compiler somehow proves that overlap is not observable?
[Bug middle-end/91899] Merge constant literals
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91899 Richard Biener changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2019-09-25 Ever confirmed|0 |1 --- Comment #2 from Richard Biener --- The question is why data1/2 live in .rodata rather than in the mergeable strings section.
[Bug middle-end/91899] Merge constant literals
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91899 --- Comment #1 from Antony Polukhin --- Godbolt playground: https://godbolt.org/z/UA_Xsm