[Bug target/84011] Optimize switch table with -fPIE
hjl.tools at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Jan 24 13:58:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84011
--- Comment #5 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to rguenther@suse.de from comment #4)
> > The question is why run-time relocations aren't allowed.
>
> Probably added to save binary space? An optimization would be to
I don't think so:
text data bss dec hex filename
714 0 0 714 2ca before my change
240 184 0 424 1a8 after my change
My change cuts down size by a wide margin.
> add an indirection by, say, only recording the constant offset
> into an "array of strings" in the table, thus effectively
>
> "case1\0case2\0..."[CSWITCH[i]]
>
> which would require only a relocation to access the single string
> constant. But it would prohibit cases of string merging within
> those strings unless we implement that as well for this optimization.
> Note this might be profitable unconditionally, not just with -fpie/pic
> as the CSWITCH table would be smaller (dependent on the total
> size of the merged string).
True, this is independent of PIE/PIC.
More information about the Gcc-bugs
mailing list