Gcc-3.4.1 generates wrong code when compiling attached code with '-O2 -fPIC'. Adding -fno-regmove fixes this. Compile: $ sh-linux-gcc -O2 -fPIC -S dl-open.i Miscompiled source code: args.caller_dl_open = __builtin_extract_return_addr (__builtin_return_address (0)); Generated wrong code: mov r4,r11 [snip] sts pr,r0 [snip] mov.l r11,@(12,r14) --- original pr should be stored to @(12,r14) Correct code (-O2 -fPIC -fno-regmove): sts pr,r10 [snip] mov.l r10,@(12,r14)
Created attachment 6496 [details] testcase
FYI, I could find a reduced testcase and analyze it. See http://gcc.gnu.org/ml/gcc/2004-06/msg00721.html
Kazumoto Kojima confirmed and analyzed it already.
KK, is this a regression? In your message you say that mainline and 3.4 exhibit the bug, but can you test it also on an older version?
Yep. I've confirmed that 3.3.4 has the same problem and 3.2.3 doesn't. So this is a regression from 3.2.
Subject: Bug 15886 CVSROOT: /cvs/gcc Module name: gcc Changes by: amylaar@gcc.gnu.org 2004-06-11 18:15:38 Modified files: gcc : ChangeLog Log message: Add PR number in: PR 15886: * sh.h (ALLOCATE_INITIAL_VALUE): Use return_address_pointer_rtx. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.3925&r2=2.3926
Postponed until GCC 3.4.3.
Subject: Bug 15886 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: kkojima@gcc.gnu.org 2004-09-09 02:18:15 Modified files: gcc : ChangeLog gcc/config/sh : sh.h Log message: PR 15886 Backport from mainline: 2004-06-11 J"orn Rennecke <joern.rennecke@superh.com> * sh.h (ALLOCATE_INITIAL_VALUE): Use return_address_pointer_rtx. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.616&r2=2.2326.2.617 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sh/sh.h.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.230.4.3&r2=1.230.4.4
Fixed in 3.4.3.