Skip to contentSkip to conversation

Simple piece of code with unexpected behavior

DISCUSSION Roland Vossen 2 participants 4 messages Aug 11, 2011

lore
Share & tools
lore
#0 lore raw

Hi,

after compiling and insmodding a module on a Sparc64 machine, the following piece of code:

	u8 index;
         for (index = 0; index < 128U; index++) {
                 if (index=129) {
                         printk("fishy...\n");
                         break;
                 }
         }

produces the log message: 'fishy...'.

The same piece of code does not produce this message on x86.

Is this a compiler bug, or am I overlooking something ?

Thanks, Roland.

--- info on my machine

developer@LB-BUN-44:~/code/brcm80211-next-2.6$ uname -a
Linux LB-BUN-44.bun.broadcom.com 3.0.0-rc6+ #2 Fri Jul 22 17:00:50 CEST 
2011 sparc64 GNU/Linux

--- info on my GCC version

developer@LB-BUN-44:~/code/brcm80211-next-2.6$ gcc -v
Using built-in specs.
Target: sparc-linux-gnu
Configured with: ../src/configure -v 
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr 
--enable-shared --with-system-zlib --libexecdir=/usr/lib 
--without-included-gettext --enable-threads=posix --enable-nls 
--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc 
--enable-mpfr --with-cpu=v8 --with-long-double-128 
--enable-checking=release --build=sparc-linux-gnu --host=sparc-linux-gnu 
--target=sparc-linux-gnu
Thread model: posix
gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu4)
#1 lore raw

From: "Roland Vossen" <[email protected]>
Date: Thu, 11 Aug 2011 14:29:03 +0200

Quoted 11 lines

after compiling and insmodding a module on a Sparc64 machine, the following piece of code:

	u8 index;
        for (index = 0; index < 128U; index++) {
                if (index=129) {
                        printk("fishy...\n");
                        break;
                }
        }
Quoted 1 line

produces the log message: 'fishy...'.

Something is very wrong with your build environment:

--------------------

root@firepit:/home/davem# cat Makefile 
obj-m := test_mod.o
root@firepit:/home/davem# cat test_mod.c
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>

static int __init test(void)

{
        u8 index;
        for (index = 0; index < 128U; index++) {
                if (index=129) {
                        printk("fishy...\n");
                        break;
                }
        }
        return 0;
}
module_init(test);
root@firepit:/home/davem# 
root@firepit:/home/davem# make -C /home/davem/src/GIT/linux M=$(pwd)
make: Entering directory `/home/davem/src/GIT/linux'
  CC [M]  /home/davem/test_mod.o
  Building modules, stage 2.
  MODPOST 1 modules
  LD [M]  /home/davem/test_mod.ko
make: Leaving directory `/home/davem/src/GIT/linux'
root@firepit:/home/davem# insmod ./test_mod.ko
--------------------

Generates no warning "fishy" message for me on sparc64.

#2 lore raw
In reply to Roland Vossen
Quoted 1 line

Something is very wrong with your build environment:

Thanks for doing this experiment David. Can you email me some details on the build chain you are using: eg, output of 'gcc -v'? Did you cross compile gcc yourself or did you download a binary ?

Thanks, Roland.

#3 lore raw
In reply to Roland Vossen

From: "Roland Vossen" <[email protected]>
Date: Thu, 11 Aug 2011 16:18:53 +0200

Quoted 5 lines
Quoted 1 line

Something is very wrong with your build environment:

Thanks for doing this experiment David. Can you email me some details on the build chain you are using: eg, output of 'gcc -v'? Did you cross compile gcc yourself or did you download a binary ?

It's native debian unstable which uses gcc-4.6.1