public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* gcc-4.0.0 final miscompiles net/ipv4/devinet.c:devinet_sysctl_register()
@ 2005-04-23  9:52 Mikael Pettersson
  2005-04-23 17:37 ` ismail dönmez
  0 siblings, 1 reply; 5+ messages in thread
From: Mikael Pettersson @ 2005-04-23  9:52 UTC (permalink / raw)
  To: linux-kernel

gcc-4.0.0 miscompiles a pointer subtraction operation in
net/ipv4/devinet.c, resulting in oopses from /sbin/sysctl.

Below is a copy of the test case I just sent to gcc bugzilla.

/Mikael

/* gcc4pointersubtractionbug.c
 * Written by Mikael Pettersson, mikpe@csd.uu.se, 2005-04-23.
 *
 * This program illustrates a code optimisation bug in
 * gcc-4.0.0 (final) and gcc-4.0.0-20050417, where a pointer
 * subtraction operation is compiled as a pointer addition.
 * Observed at -O2. gcc was configured for i686-pc-linux-gnu.
 *
 * This bug broke net/ipv4/devinet.c:devinet_sysctl_register()
 * in the linux-2.6.12-rc2 Linux kernel, causing /sbin/sysctl
 * to trigger kernel oopses.
 *
 * gcc-4.0.0-20050416 and earlier prereleases do not have this bug.
 */
#include <stdio.h>
#include <string.h>

#define NRVARS	5

struct ipv4_devconf {
    int var[NRVARS];
};
struct ipv4_devconf ipv4_devconf[2];

struct ctl_table {
    void *data;
};

struct devinet_sysctl_table {
    struct ctl_table devinet_vars[NRVARS];
};

void devinet_sysctl_relocate(struct devinet_sysctl_table *t,
			     struct ipv4_devconf *p)
{
    int i;

    for (i = 0; i < NRVARS; i++)
	/* Initially data points to a field in ipv4_devconf[0].
	   This code relocates it to the corresponding field in *p.
	   At -O2, gcc-4.0.0-20050417 and gcc-4.0.0 (final)
	   miscompile this pointer subtraction as a pointer addition. */
	t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf[0];
}

struct devinet_sysctl_table devinet_sysctl;

int main(void)
{
    struct devinet_sysctl_table t;
    int i;

    for(i = 0; i < NRVARS; i++)
	devinet_sysctl.devinet_vars[i].data = &ipv4_devconf[0].var[i];

    memcpy(&t, &devinet_sysctl, sizeof t);
    devinet_sysctl_relocate(&t, &ipv4_devconf[1]);

    for(i = 0; i < NRVARS; i++)
	if (t.devinet_vars[i].data != &ipv4_devconf[1].var[i]) {
	    fprintf(stderr, "t.devinet_vars[%u].data == %p, should be %p\n",
		    i,
		    t.devinet_vars[i].data,
		    &ipv4_devconf[1].var[i]);
	    return 1;
	}

    printf("all ok\n");
    return 0;
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gcc-4.0.0 final miscompiles net/ipv4/devinet.c:devinet_sysctl_register()
  2005-04-23  9:52 gcc-4.0.0 final miscompiles net/ipv4/devinet.c:devinet_sysctl_register() Mikael Pettersson
@ 2005-04-23 17:37 ` ismail dönmez
  2005-04-23 17:49   ` YOSHIFUJI Hideaki / 吉藤英明
  2005-04-23 17:53   ` Jakub Jelinek
  0 siblings, 2 replies; 5+ messages in thread
From: ismail dönmez @ 2005-04-23 17:37 UTC (permalink / raw)
  To: Mikael Pettersson; +Cc: linux-kernel

Whats the bugzilla # for this so others can track it?


On 4/23/05, Mikael Pettersson <mikpe@csd.uu.se> wrote:
> gcc-4.0.0 miscompiles a pointer subtraction operation in
> net/ipv4/devinet.c, resulting in oopses from /sbin/sysctl.
> 
> Below is a copy of the test case I just sent to gcc bugzilla.
> 
> /Mikael
> 
> /* gcc4pointersubtractionbug.c
>  * Written by Mikael Pettersson, mikpe@csd.uu.se, 2005-04-23.
>  *
>  * This program illustrates a code optimisation bug in
>  * gcc-4.0.0 (final) and gcc-4.0.0-20050417, where a pointer
>  * subtraction operation is compiled as a pointer addition.
>  * Observed at -O2. gcc was configured for i686-pc-linux-gnu.
>  *
>  * This bug broke net/ipv4/devinet.c:devinet_sysctl_register()
>  * in the linux-2.6.12-rc2 Linux kernel, causing /sbin/sysctl
>  * to trigger kernel oopses.
>  *
>  * gcc-4.0.0-20050416 and earlier prereleases do not have this bug.
>  */
> #include <stdio.h>
> #include <string.h>
> 
> #define NRVARS	5
> 
> struct ipv4_devconf {
>     int var[NRVARS];
> };
> struct ipv4_devconf ipv4_devconf[2];
> 
> struct ctl_table {
>     void *data;
> };
> 
> struct devinet_sysctl_table {
>     struct ctl_table devinet_vars[NRVARS];
> };
> 
> void devinet_sysctl_relocate(struct devinet_sysctl_table *t,
> 			     struct ipv4_devconf *p)
> {
>     int i;
> 
>     for (i = 0; i < NRVARS; i++)
> 	/* Initially data points to a field in ipv4_devconf[0].
> 	   This code relocates it to the corresponding field in *p.
> 	   At -O2, gcc-4.0.0-20050417 and gcc-4.0.0 (final)
> 	   miscompile this pointer subtraction as a pointer addition. */
> 	t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf[0];
> }
> 
> struct devinet_sysctl_table devinet_sysctl;
> 
> int main(void)
> {
>     struct devinet_sysctl_table t;
>     int i;
> 
>     for(i = 0; i < NRVARS; i++)
> 	devinet_sysctl.devinet_vars[i].data = &ipv4_devconf[0].var[i];
> 
>     memcpy(&t, &devinet_sysctl, sizeof t);
>     devinet_sysctl_relocate(&t, &ipv4_devconf[1]);
> 
>     for(i = 0; i < NRVARS; i++)
> 	if (t.devinet_vars[i].data != &ipv4_devconf[1].var[i]) {
> 	    fprintf(stderr, "t.devinet_vars[%u].data == %p, should be %p\n",
> 		    i,
> 		    t.devinet_vars[i].data,
> 		    &ipv4_devconf[1].var[i]);
> 	    return 1;
> 	}
> 
>     printf("all ok\n");
>     return 0;
> }
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 

-- 
Time is what you make of it

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gcc-4.0.0 final miscompiles net/ipv4/devinet.c:devinet_sysctl_register()
  2005-04-23 17:37 ` ismail dönmez
@ 2005-04-23 17:49   ` YOSHIFUJI Hideaki / 吉藤英明
  2005-04-23 17:53   ` Jakub Jelinek
  1 sibling, 0 replies; 5+ messages in thread
From: YOSHIFUJI Hideaki / 吉藤英明 @ 2005-04-23 17:49 UTC (permalink / raw)
  To: ismail.donmez; +Cc: mikpe, linux-kernel, yoshfuji

In article <2a4f155d05042310375d99994b@mail.gmail.com> (at Sat, 23 Apr 2005 20:37:23 +0300), ismail dönmez <ismail.donmez@gmail.com> says:

> Whats the bugzilla # for this so others can track it?

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21173

--yoshfuji

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gcc-4.0.0 final miscompiles net/ipv4/devinet.c:devinet_sysctl_register()
  2005-04-23 17:37 ` ismail dönmez
  2005-04-23 17:49   ` YOSHIFUJI Hideaki / 吉藤英明
@ 2005-04-23 17:53   ` Jakub Jelinek
  2005-04-23 18:18     ` ismail dönmez
  1 sibling, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2005-04-23 17:53 UTC (permalink / raw)
  To: ismail donmez; +Cc: Mikael Pettersson, linux-kernel

On Sat, Apr 23, 2005 at 08:37:23PM +0300, ismail d?nmez wrote:
> Whats the bugzilla # for this so others can track it?

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21167
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21173

	Jakub

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gcc-4.0.0 final miscompiles net/ipv4/devinet.c:devinet_sysctl_register()
  2005-04-23 17:53   ` Jakub Jelinek
@ 2005-04-23 18:18     ` ismail dönmez
  0 siblings, 0 replies; 5+ messages in thread
From: ismail dönmez @ 2005-04-23 18:18 UTC (permalink / raw)
  To: linux-kernel; +Cc: Mikael Pettersson, yoshfuji, jakub

Thanks

ismail


On 4/23/05, Jakub Jelinek <jakub@redhat.com> wrote:
> On Sat, Apr 23, 2005 at 08:37:23PM +0300, ismail d?nmez wrote:
> > Whats the bugzilla # for this so others can track it?
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21167
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21173
> 
> 	Jakub
> 

-- 
Time is what you make of it

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-04-23 18:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-23  9:52 gcc-4.0.0 final miscompiles net/ipv4/devinet.c:devinet_sysctl_register() Mikael Pettersson
2005-04-23 17:37 ` ismail dönmez
2005-04-23 17:49   ` YOSHIFUJI Hideaki / 吉藤英明
2005-04-23 17:53   ` Jakub Jelinek
2005-04-23 18:18     ` ismail dönmez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox