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]

Re: A bug present in 3.2



On Sun, 26 Oct 2003, Jim Wilson wrote:

> Stelios Xanthakis wrote:
> > In gcc32, if you put a static local variable of 
> > a static inline function into a ".gnu.linkonce.d"
> > section, it crashes.
> 
> How are you putting the local variables in a .gnu.linkonce.d section? 
> We need a testcase, and command line options.
> 
> Also, what exactly is crashing?  The compiler?  Or the linker?
> 

Ops. sorry. The generated a.out file crashes when you run it.
My bad. Too much coffee.

Typescript of problem follows:
-----------------------------
Script started on Tue Oct 21 23:39:20 2003
stan@linux:~/wtmp/inline> cat H.h
#include <stdio.h>

static inline int f ()
{
	static int i __attribute__ ((__section__(".gnu.linkonce.d.i")));
	return i++;
}
stan@linux:~/wtmp/inline> cat M1.c

#include "H.h"

void foo ()
{
	printf ("F=%i\n", f());
	printf ("F=%i\n", f());
	printf ("F=%i\n", f());
}
stan@linux:~/wtmp/inline> cat M2.c
#include "H.h"

extern void foo ();

int main ()
{
	printf ("%i\n", f());
	printf ("%i\n", f());
	printf ("%i\n", f());
	foo ();
}
stan@linux:~/wtmp/inline> gcc -g M1.c M2.c
stan@linux:~/wtmp/inline> ./a.out
Segmentation fault
stan@linux:~/wtmp/inline> valgrind a.out
==4084== valgrind-1.0.4, a memory error detector for x86 GNU/Linux.
==4084== Copyright (C) 2000-2002, and GNU GPL'd, by Julian Seward.
==4084== Estimated CPU clock rate is 535 MHz
==4084== For more details, rerun with: -v
==4084== 
==4084== Invalid read of size 4
==4084==    at 0x804840E: f (H.h:4)
==4084==    by 0x4024C4F2: __libc_start_main (in /lib/libc.so.6)
==4084==    by 0x80482A1: (within /home/stan/wtmp/inline/a.out)
==4084==    Address 0x0 is not stack'd, malloc'd or free'd
Segmentation fault
(gdb) stan@linux:~/wtmp/inline> gdb ./a.out
GNU gdb 5.2.1
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i586-suse-linux"...
(gdb) r
Starting program: /home/stan/wtmp/inline/a.out 

Program received signal SIGSEGV, Segmentation fault.
f () at H.h:6
6		return i++;
(gdb) li
1	#include <stdio.h>
2	
3	static inline int f ()
4	{
5		static int i __attribute__ ((__section__(".gnu.linkonce.d.i")));
6		return i++;
7	}
(gdb) print &i
$1 = (int *) 0x0
(gdb) The program is running.  Exit anyway? (y or n) stan@linux:~/wtmp/inline> 
stan@linux:~/wtmp/inline> gcc --version
gcc (GCC) 3.2
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

stan@linux:~/wtmp/inline> 
Script done on Tue Oct 21 23:42:33 2003


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