This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

a progression 3.2.2 -> 3.2.3 -- is there a testcase?


I ran into some code today that didn't compile under 3.2.2 but did under
3.2.3.  I am interested to know whether there's been a testcase added for
this code.

Is there any easy way to get a list of added test cases between 3.2.2 and
3.2.3?  Since the combination of -pg and -fPIC is necessary to cause the
bad code to be generated, I tried grepping in testsuite/ from a checkout of
3.2.3, but didn't see any likely matches.  I also didn't see an item in
the gcc/ChangeLog file between the 3.2.2 and 3.2.3 releases that sounded
like it was intended to address this problem.

The code:
/* bug.c */
/* compile with -pg -fPIC -O2 -> wrong code generated by redhat 9's gcc */
typedef struct { void *(*f)(void *, int); } T;
void *g(T *t) { return t->f(t, 0); }

To actually show the problem, you also need this:
/* bug-main.c */
/* compile with -pg (at least) and use with bug.c */
typedef struct { void *(*f)(void *, int); } T;
void *ff(void* a, int b) { return 0; }
int main(void) { T x = {ff}; g(&x); return 0; }

$ gcc -O2 -fPIC -pg -c bug.c
$ gcc -pg -c bug-main.c
$ gcc -pg bug.o bug-main.o
$ ./a.out
Segmentation fault

The problem seems to be that the instructions to load the GOT into %ebx are
completely removed when optimization is enabled.  Without optimization:
        subl    $4, %esp
        call    .L2
.L2:
        popl    %ebx
        addl    $_GLOBAL_OFFSET_TABLE_+[.-.L2], %ebx
        call    *mcount@GOT(%ebx)
        subl    $8, %esp

with optimization:
        subl    $12, %esp
        call    *mcount@GOT(%ebx)
(note that the two 'subl' instructions were also combined into one,
I don't know if this is relevant or not)

Jeff


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]