This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/25380] application segmentation fault when compiled with "-O2", but not with "-O1"
- From: "amodra at bigpond dot net dot au" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 13 Dec 2005 04:28:07 -0000
- Subject: [Bug target/25380] application segmentation fault when compiled with "-O2", but not with "-O1"
- References: <bug-25380-11872@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from amodra at bigpond dot net dot au 2005-12-13 04:28 -------
The testcase is invalid, because you are compiling libwrapped.so without -fPIC.
Now, powerpc64 code is always PIC, so you might think that -fPIC (or -fpic) is
unnecessary on powerpc64 shared libraries. However, -fPIC/pic also tells gcc
to compile assuming that the object might be for a shared library. One thing
this affects is whether tail calls can be made to global functions. At -O2,
sibling/tail call optimisation is done, so we get a tail call from "wrapped" to
"fn" because -fPIC wasn't specified. This tail call inside the shared lib
destroys r2, the TOC pointer, and an invalid TOC access is the reason for the
segfault.
It might possible to do something about this in the linker, but more
complicated examples are not possible to fix. eg. where the function
tail-called is overridden by a function of the same name in the main app.
--
amodra at bigpond dot net dot au changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |amodra at bigpond dot net
| |dot au
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25380