https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114158
Bug ID: 114158 Summary: Wrong FDPIC special-casing in crtstuff produces invalid pointer in init_array Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libgcc Assignee: unassigned at gcc dot gnu.org Reporter: bugdal at aerifal dot cx Target Milestone: --- Commit 11189793b6ef60645d5d1126d0bd9d0dd83e6583 introduced wrong special-casing of FDPIC to __do_global_dtors_aux handling in crtstuff.c. For some reason, it was assumed that, on FDPIC targets, init/fini arrays would contain instruction addresses rather than function addresses (which are addresses of descriptors, on FDPIC targets). This is NOT the case. The gABI contract of the init/fini arrays is that they contain ABI-callable function pointers, and in fact GCC correctly emits FUNCDESC-type relocations referencing then when translating ctors/dtors, on ARM as well as sh. It seems to have been realized that this was not working, as 6bcbf80c6e2bd8a60d88bbcac3d70ffb67f4888f disabled initfini arrays on ARM/FDPIC, but didn't identify the root cause. Commit 11189793b6ef60645d5d1126d0bd9d0dd83e6583 should be reverted ASAP, and backported to all maintained versions, as it's actively breaking other targets by putting an invalid function pointer in the init_array. Commit 6bcbf80c6e2bd8a60d88bbcac3d70ffb67f4888f should also be reverted in theory, but may need coordination with uclibc if they want to work around binaries built with broken versions. Further discussion of the issue can be found on the musl mailing list, in this thread where myself and the author of the in-progress xtensa/fdpic port were trying to figure out what's going on here: https://www.openwall.com/lists/musl/2024/02/28/12