Skip to contentSkip to conversation

Fix extern inline in ftrace.h for ARM

PATCH New [email protected] 5 participants 8 messages Aug 14, 2013 – Sep 6, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix extern inline in ftrace.h for ARM

From: Behan Webster <[email protected]>

The LLVMLinux Project is working to be able to build the Linux kernel with clang/LLVM. With the release of LLVM 3.3 clang is now able to compile the Linux kernel with a number of small patches (available from the LLVMLinux git repo).

This patch removes the use of "extern inline" from the ftrace code for ARM. This same work has already been completed for ftrace on x86. Amongst other things this patch is required in order to have the Linux kernel to be able to be compiled with both gcc and clang.

Mark Charlebois (1):
ARM: LLVMLinux: Change "extern inline" to "gnu_inline" in ARM ftrace.h

 arch/arm/include/asm/ftrace.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.1.2
#1 lore raw

PATCH 1/1 ARM: LLVMLinux: Change "extern inline" to "gnu_inline" in ARM ftrace.h

From: Mark Charlebois <[email protected]>

With compilers which follow the C99 standard (like modern versions of gcc and clang), "extern inline" does the wrong thing (emits code for an externally linkable version of the inline function). In this case using the gnu_inline attribute makes inline do the right thing on gcc and on clang.

---
 arch/arm/include/asm/ftrace.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/include/asm/ftrace.h +2 -1
index f89515a..fb7fdc4 100644
@@ -45,7 +45,8 @@ void *return_address(unsigned int);
 
 #else
 
-extern inline void *return_address(unsigned int level)
+extern inline __attribute__((gnu_inline))
+void *return_address(unsigned int level)
 {
 	return NULL;
 }
Signature · 1 line
1.8.1.2
#2 lore raw

Re: [PATCH] ARM: LLVMLinux: Change "extern inline" to "gnu_inline" in ARM ftrace.h

Quoted 18 lines · behanw at converseincode.com

From: Mark Charlebois <[email protected]>

With compilers which follow the C99 standard (like modern versions of gcc and clang), "extern inline" does the wrong thing (emits code for an externally linkable version of the inline function). In this case using the gnu_inline attribute makes inline do the right thing on gcc and on clang.

---
  arch/arm/include/asm/ftrace.h | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/include/asm/ftrace.h +0 -0
index f89515a..fb7fdc4 100644

arch/arm/include/asm/ftrace.h void *return_address(unsigned int); · line 48

Quoted 5 lines
arch/arm/include/asm/ftrace.h +1 -1
@@ -45,7 +45,8 @@ void *return_address(unsigned int);
 
  #else
 
-extern inline void *return_address(unsigned int level)
+extern inline __attribute__((gnu_inline))

That seems very ugly.

Is it possible to put something in linux/compiler.h that encapsulates the desired semantics, and then use that instead?

We already define "inline" that way, if you need something else, put it in compiler.h with a nice symbolic name, and then use it.

Quoted 5 lines
arch/arm/include/asm/ftrace.h +1 -0
+void *return_address(unsigned int level)
  {
  	return NULL;
  }
#3 lore raw

Re: [PATCH] ARM: LLVMLinux: Change "extern inline" to "gnu_inline" in ARM ftrace.h

In reply to [email protected]
Quoted 6 lines · behanw at converseincode.com

From: Mark Charlebois <[email protected]>

With compilers which follow the C99 standard (like modern versions of gcc and clang), "extern inline" does the wrong thing (emits code for an externally linkable version of the inline function). In this case using the gnu_inline attribute makes inline do the right thing on gcc and on clang.

Why not convert these to static inline?

arch/arm/include/asm/ftrace.h

Quoted 1 line
arch/arm/include/asm/ftrace.h +0 -0

[]

Quoted 10 lines
arch/arm/include/asm/ftrace.h +2 -1
@@ -45,7 +45,8 @@ void *return_address(unsigned int);
 
 #else
 
-extern inline void *return_address(unsigned int level)
+extern inline __attribute__((gnu_inline))
+void *return_address(unsigned int level)
 {
 	return NULL;
 }
#4 lore raw

Re: [PATCH] ARM: LLVMLinux: Change "extern inline" to "gnu_inline" in ARM ftrace.h

Quoted 8 lines · Joe Perches
Quoted 6 lines · behanw at converseincode.com

From: Mark Charlebois <[email protected]>

With compilers which follow the C99 standard (like modern versions of gcc and clang), "extern inline" does the wrong thing (emits code for an externally linkable version of the inline function). In this case using the gnu_inline attribute makes inline do the right thing on gcc and on clang.

Why not convert these to static inline?

In this case we should probably just delete the entire thing and make it unconditional in the header. It looks like it compiles with gcc still.

Quoted 14 lines

arch/arm/include/asm/ftrace.h

Quoted 2 lines
arch/arm/include/asm/ftrace.h +0 -0

[]

Quoted 10 lines
arch/arm/include/asm/ftrace.h +2 -1
@@ -45,7 +45,8 @@ void *return_address(unsigned int);
 
 #else
 
-extern inline void *return_address(unsigned int level)
+extern inline __attribute__((gnu_inline))
+void *return_address(unsigned int level)
 {
 	return NULL;
 }
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#5 lore raw

Re: [PATCH] ARM: LLVMLinux: Change "extern inline" to "gnu_inline" in ARM ftrace.h

In reply to [email protected]
Quoted 18 lines · behanw at converseincode.com

From: Mark Charlebois <[email protected]>

With compilers which follow the C99 standard (like modern versions of gcc and clang), "extern inline" does the wrong thing (emits code for an externally linkable version of the inline function). In this case using the gnu_inline attribute makes inline do the right thing on gcc and on clang.

---
 arch/arm/include/asm/ftrace.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/include/asm/ftrace.h +0 -0
index f89515a..fb7fdc4 100644

arch/arm/include/asm/ftrace.h void *return_address(unsigned int); · line 49

Quoted 6 lines
arch/arm/include/asm/ftrace.h +2 -1
@@ -45,7 +45,8 @@ void *return_address(unsigned int);
 
 #else
 
-extern inline void *return_address(unsigned int level)
+extern inline __attribute__((gnu_inline))
+void *return_address(unsigned int level)

Well, that should be static inline, not extern inline in any case. Does clang work if that's static inline?

#6 lore raw

Re: [PATCH] ARM: LLVMLinux: Change "extern inline" to "gnu_inline" in ARM ftrace.h

Sorry for the delay. A mistake in my email filters ate all your replies. Doh!

Quoted 6 lines · Russell King - ARM Linux

arch/arm/include/asm/ftrace.h void *return_address(unsigned int); · line 49

Quoted 3 lines · behanw at converseincode.com
arch/arm/include/asm/ftrace.h +2 -1
-extern inline void *return_address(unsigned int level)
+extern inline __attribute__((gnu_inline))
+void *return_address(unsigned int level)

Well, that should be static inline, not extern inline in any case. Does clang work if that's static inline?

Actually, neither gcc nor clang work with it merely changed to "static inline".

Which is why we left it with the explicit GNU89 meaning of "extern inline" which is gnu_inline. C99 changed the meaning of what "extern inline" means. One of the major issues we've had with the clang kernel port is that clang defaults to gnu99 (which is mostly just C99) while until recently gcc defaulted to gnu89.

For recent versions of gcc:

http://gcc.gnu.org/onlinedocs/gcc/Standards.html

"The default, if no C language dialect options are given, is -std=gnu90; this will change to -std=gnu99 or -std=gnu11 in some future release when the C99 or C11 support is complete. Some features that are part of the C99 standard are accepted as extensions in C90 mode, and some features that are part of the C11 standard are accepted as extensions in C90 and C99 modes."

However, having said all that, it seems if I remove the corresponding NULL definition for return_address in arch/arm/kernel/return_address.c, I can make it "static inline" and it seems to work for both gcc and clang.

I'll send a new patch. :)

Incidentally the LLVMLinux project tests all the project's patches with both gcc and clang. The idea is to make it work with both compilers after all.

Behan

Signature · 2 lines
Behan Webster
behanw at converseincode.com
#7 lore raw

PATCH v2 1/1 arm: LLVMLinux: use static inline in ARM ftrace.h

From: Behan Webster <[email protected]>

With compilers which follow the C99 standard (like modern versions of gcc and clang), "extern inline" does the wrong thing (emits code for an externally linkable version of the inline function). In this case using static inline and removing the NULL version of return_address in return_address.c does the right thing.

---
 arch/arm/include/asm/ftrace.h    | 2 +-
 arch/arm/kernel/return_address.c | 5 -----
 2 files changed, 1 insertion(+), 6 deletions(-)
arch/arm/include/asm/ftrace.h +1 -1
index f89515a..2bb8cac 100644
@@ -45,7 +45,7 @@ void *return_address(unsigned int);
 
 #else
 
-extern inline void *return_address(unsigned int level)
+static inline void *return_address(unsigned int level)
 {
 	return NULL;
 }
arch/arm/kernel/return_address.c +0 -5
index fafedd8..f6aa84d 100644
@@ -63,11 +63,6 @@ void *return_address(unsigned int level)
 #warning "TODO: return_address should use unwind tables"
 #endif
 
-void *return_address(unsigned int level)
-{
-	return NULL;
-}
-
 #endif /* if defined(CONFIG_FRAME_POINTER) && !defined(CONFIG_ARM_UNWIND) / else */
 
 EXPORT_SYMBOL_GPL(return_address);
Signature · 1 line
1.8.1.2