Skip to contentSkip to conversation

gcc 3.x, -ansi and "static inline"

DISCUSSION Jun Sun 3 participants 7 messages Feb 1, 2002 – Feb 4, 2002 MIPS

lore
Share & tools
lore

Jun Sun

author
#0 lore raw

We are trying to build userland apps with the newer kernel headers. Unexpected problems occur with the "static inline" declaration when "-ansi" option is used.

Anybody else is having the problem?

Also, what are the reasons for us to switch to "static inline" in the kernel header?

Here is an example I am talking about:

In 2.4.2, we have in bitops.h:

extern __inline__ unsigned long ffz(unsigned long word)

In 2.4.17, we have instead:

static inline unsigned long ffz(unsigned long word)

This problem seems only happening with gcc 3.x. I start to wonder whether we should fix kernel header. In some case, the fix seems to be not exposing to userland (by #ifdef __KERNEL__). In others, the fix might be using __inline__.

However, I really like to know what was the original motivation to do such a change.

BTW, the inclusion of "mipsregs.h" file in bitops.h seems unnecessary and caused a bunch of similar errors.

Jun

#1 lore raw
Quoted 15 lines · Jun Sun

We are trying to build userland apps with the newer kernel headers. Unexpected problems occur with the "static inline" declaration when "-ansi" option is used.

Anybody else is having the problem?

Also, what are the reasons for us to switch to "static inline" in the kernel header?

Here is an example I am talking about:

In 2.4.2, we have in bitops.h:

extern __inline__ unsigned long ffz(unsigned long word)

Quoted 8 lines

In 2.4.17, we have instead:

static inline unsigned long ffz(unsigned long word)

This problem seems only happening with gcc 3.x. I start to wonder whether we should fix kernel header. In some case, the fix seems to be not exposing to userland (by #ifdef __KERNEL__). In others, the fix might be using __inline__.

Yes, #ifdef __KERNEL__ is the right fix.

Quoted 2 lines

However, I really like to know what was the original motivation to do such a change.

See linux-kernel

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#2 lore raw
In reply to Jun Sun
Quoted 2 lines · Jun Sun

BTW, the inclusion of "mipsregs.h" file in bitops.h seems unnecessary and caused a bunch of similar errors.

Indeed, it was pointless and I therefore removed it.

Ralf

author
#3 lore raw
Quoted 8 lines · Ralf Baechle
Quoted 2 lines · Jun Sun

BTW, the inclusion of "mipsregs.h" file in bitops.h seems unnecessary and caused a bunch of similar errors.

Indeed, it was pointless and I therefore removed it.

What about ffz()? We can do:

asm-mips/bitops.h Mon Feb 4 11:21:14 2002 renamed from asm-mips/bitops.h.orig Mon Feb 4 11:07:31 2002 +1 -1
diff -Nru include/asm-mips/bitops.h.orig include/asm-mips/bitops.h
@@ -675,7 +675,7 @@
  *
  * Undefined if no zero exists, so code should check against ~0UL first.
  */
-static inline unsigned long ffz(unsigned long word)
+static __inline__ unsigned long ffz(unsigned long word)
 {
        int b = 0, s;
 

or

asm-mips/bitops.h Mon Feb 4 11:27:55 2002 renamed from asm-mips/bitops.h.orig Mon Feb 4 11:07:31 2002 +2 -2
diff -Nru include/asm-mips/bitops.h.orig include/asm-mips/bitops.h
@@ -669,6 +669,8 @@
 
 #endif /* !(__MIPSEB__) */
 
+#ifdef __KERNEL__
+
 /*
  * ffz - find first zero in word.
  * @word: The word to search
@@ -689,8 +691,6 @@
        return b;
 }
 
-
-#ifdef __KERNEL__
 
 /**
  * ffs - find first bit set

Jun

#4 lore raw
Quoted 8 lines · Jun Sun
Quoted 6 lines · Jun Sun
Quoted 3 lines

BTW, the inclusion of "mipsregs.h" file in bitops.h seems unnecessary and caused a bunch of similar errors.

Indeed, it was pointless and I therefore removed it.

What about ffz()? We can do:

Including kernel header files into user code is the actual bug but if you think fixing that isn't an option I can certainly so a s/inline/__inline__/

Ralf

author
#5 lore raw
Quoted 5 lines · Ralf Baechle
Quoted 2 lines · Jun Sun
Quoted 2 lines · Jun Sun
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

BTW, the inclusion of "mipsregs.h" file in bitops.h seems unnecessary and caused a bunch of similar errors.

Indeed, it was pointless and I therefore removed it.

What about ffz()? We can do:

Including kernel header files into user code is the actual bug

In theory, yes. In practice, kernel head is all a big mesh where we don't have a clear division as which part can go to userland and which part can't.

The inline function makes mesh even meshier.

Quoted 4 lines

but if
you think fixing that isn't an option I can certainly so a s/inline/__inline__/

I think this is the case. See the inclusion chain below. BTW, the app is libcap.

In file included from /opt/hardhat/devkit/mips/sb1_fp_be/target/usr/include/linux/fs.h:26,
from
/opt/hardhat/devkit/mips/sb1_fp_be/target/usr/include/linux/capability.h:17,
from
/var/tmp/BUILD/libcap-1.10.orig/libcap/include/sys/capability.h:24,

                 from libcap.h:19,
                 from cap_alloc.c:12:

/opt/hardhat/devkit/mips/sb1_fp_be/target/usr/include/asm/bitops.h:678: syntax error before "unsigned"

Jun

#6 lore raw
Quoted 2 lines · Jun Sun

In theory, yes. In practice, kernel head is all a big mesh where we don't have a clear division as which part can go to userland and which part can't.

The answer is already l-k faq probably - copy the kernel header to userspace and hack it into your favorite shape. I'm not a fan of this policy but ...

Ralf