Skip to contentSkip to conversation

gcc (3.3.5) causing problems in our latest kernel.

parisc-linux Matthew Wilcox 4 participants 5 messages Apr 3, 2005 – Apr 4, 2005 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 1112564457.5858.7.camel@mulgrave

#1 lore raw
Quoted 3 lines · James Bottomley

The problem is that the macros depend on clever optimisation using sizeof(*ptr) as an argument to an inline function. The following program illustrates the issue:

Perhaps there's a difference between an inline function and a macro in terms of constant propagation? If you turn __test_width() into a macro, it should work (see the implementation of __get_user() in asm-parisc/uaccess.h)

Quoted 46 lines

extern void bad_function(void);

static inline void __test_width(char *var, int size) {

	switch (size) {	
	case 1:
	case 2:
	case 4:
	case 8:
		*var++ = 0;
		break;
	default:
		bad_function();
	}
}

#define test_width(x) __test_width((char *)(x), sizeof(x))

main(int argc, char *argv) {
	int test;

	test_width(&test);
}

If I compile this on an ia64 box, everything is fine:

jejb@titanic> gcc -O2 test.c
jejb@titanic> gcc -v
Reading specs from /usr/lib/gcc-lib/ia64-linux/3.3.5/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --with-system-libunwind --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc ia64-linux Thread model: posix
gcc version 3.3.5 (Debian 1:3.3.5-8)

But on a parisc system it fails:

jejb@raven> gcc -O2 test.c
/tmp/cccwaI1E.o(.text+0x60): In function `main':
: undefined reference to `bad_function'
collect2: ld returned 1 exit status
jejb@raven> gcc -v
Reading specs from /usr/lib/gcc-lib/hppa-linux/3.3.5/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-sjlj-exceptions --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc hppa-linux Thread model: posix
gcc version 3.3.5 (Debian 1:3.3.5-5)

Before I have to tell Dave Miller that his clever trick won't work for us, is there a way of fixing it?

Signature · 10 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
_______________________________________________
parisc-linux mailing list
[email protected]
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux
#2 lore raw
Quoted 4 lines · Matthew Wilcox

Perhaps there's a difference between an inline function and a macro in terms of constant propagation? If you turn __test_width() into a macro, it should work (see the implementation of __get_user() in asm-parisc/uaccess.h)

Yes, if I change it to a pure #define, everything works OK.

However, unless we can get the inline function to work, I still have to go back to davem ... Do I just tell him we can't fix our toolchain, so how about this?

James

_______________________________________________
parisc-linux mailing list
[email protected]
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux

#3 lore raw
Quoted 11 lines · James Bottomley
Quoted 4 lines · Matthew Wilcox

Perhaps there's a difference between an inline function and a macro in terms of constant propagation? If you turn __test_width() into a macro, it should work (see the implementation of __get_user() in asm-parisc/uaccess.h)

Yes, if I change it to a pure #define, everything works OK.

However, unless we can get the inline function to work, I still have to go back to davem ... Do I just tell him we can't fix our toolchain, so how about this?

Even if we can fix the toolchain, there's going to be a lot of people out there who'd have to upgrade. I'd prefer it if we didn't have to force an upgrade ...

Signature · 10 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
_______________________________________________
parisc-linux mailing list
[email protected]
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux
#4 lore raw
In reply to a message not in the archive
Quoted 7 lines

The problem is that the macros depend on clever optimisation using sizeof(*ptr) as an argument to an inline function. The following program illustrates the issue:

extern void bad_function(void);

static inline void __test_width(char *var, int size) {

Quoted 11 lines
	switch (size) {	
	case 1:
	case 2:
	case 4:
	case 8:
		*var++ = 0;
		break;
	default:
		bad_function();
	}
}

I think the optimization of switch statements is far from optimal. I suspect that the optimization of if statements is better. A similar issue causes warning from __put_user in a 32-bit build. Probably, this should be a GCC PR.

Dave

Signature · 6 lines
J. David Anglin                                  [email protected]
National Research Council of Canada              (613) 990-0752 (FAX: 952-6602)
_______________________________________________
parisc-linux mailing list
[email protected]
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux
#5 lore raw
Quoted 13 lines
Quoted 12 lines

static inline void __test_width(char *var, int size) {

	switch (size) {	
	case 1:
	case 2:
	case 4:
	case 8:
		*var++ = 0;
		break;
	default:
		bad_function();
	}
}
Quoted 4 lines

I think the optimization of switch statements is far from optimal. I suspect that the optimization of if statements is better. A similar issue causes warning from __put_user in a 32-bit build. Probably, this should be a GCC PR.

Try changing that function to
static inline void __test_width(char *var, const int size) {

willy says it worked for him :)

randolph

Signature · 7 lines
Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports
http://www.tausq.org/
_______________________________________________
parisc-linux mailing list
[email protected]
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux