diff mbox

[RFC,-next] linux/linkage.h: fix symbol prefix handling

Message ID 1362656642-2693-1-git-send-email-james.hogan@imgtec.com (mailing list archive)
State New, archived
Headers show

Commit Message

James Hogan March 7, 2013, 11:44 a.m. UTC
The commit "consolidate cond_syscall and SYSCALL_ALIAS declarations"
broke the build on blackfin and metag due to the following code:

  #ifndef SYMBOL_NAME
  #ifdef CONFIG_SYMBOL_PREFIX
  #define SYMBOL_NAME(x) CONFIG_SYMBOL_PREFIX ## x
  #else
  #define SYMBOL_NAME(x) x
  #endif
  #endif
  #define __SYMBOL_NAME(x) __stringify(SYMBOL_NAME(x))

__stringify literally stringifies CONFIG_SYMBOL_PREFIX ##x, so you get
lines like this in the assembly output:

  .weak CONFIG_SYMBOL_PREFIXsys_quotactl
  .set
  CONFIG_SYMBOL_PREFIXsys_quotactl,CONFIG_SYMBOL_PREFIXsys_ni_syscall

This is fixed by defining SYMBOL_PREFIX from the command line for c
files in addition to assembly for architectures that set
CONFIG_SYMBOL_PREFIX (scripts/Makefile.lib), and defining __SYMBOL_NAME
as:

  #define __SYMBOL_NAME(x) __stringify(SYMBOL_PREFIX) #x

We first have to ensure SYMBOL_PREFIX is defined (which avoids polluting
the command lines for architectures that don't use symbol prefixes).
Also the definition of SYMBOL_PREFIX in <linux/kernel.h> is removed as
it conflicts, isn't used anywhere, and is defined as a string so differs
from the assembly definition.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
---
This is just one possible way of fixing it. It felt the cleanest out of
the ways I tried, but feel free to suggest something better!

 include/linux/kernel.h  |  7 -------
 include/linux/linkage.h | 12 +++++-------
 scripts/Makefile.lib    |  1 +
 3 files changed, 6 insertions(+), 14 deletions(-)

Comments

Rusty Russell March 8, 2013, 12:03 a.m. UTC | #1
James Hogan <james.hogan@imgtec.com> writes:
> The commit "consolidate cond_syscall and SYSCALL_ALIAS declarations"
> broke the build on blackfin and metag due to the following code:
>
>   #ifndef SYMBOL_NAME
>   #ifdef CONFIG_SYMBOL_PREFIX
>   #define SYMBOL_NAME(x) CONFIG_SYMBOL_PREFIX ## x
>   #else
>   #define SYMBOL_NAME(x) x
>   #endif
>   #endif
>   #define __SYMBOL_NAME(x) __stringify(SYMBOL_NAME(x))
>
> __stringify literally stringifies CONFIG_SYMBOL_PREFIX ##x, so you get
> lines like this in the assembly output:
>
>   .weak CONFIG_SYMBOL_PREFIXsys_quotactl
>   .set
>   CONFIG_SYMBOL_PREFIXsys_quotactl,CONFIG_SYMBOL_PREFIXsys_ni_syscall
>
> This is fixed by defining SYMBOL_PREFIX from the command line for c
> files in addition to assembly for architectures that set
> CONFIG_SYMBOL_PREFIX (scripts/Makefile.lib), and defining __SYMBOL_NAME
> as:
>
>   #define __SYMBOL_NAME(x) __stringify(SYMBOL_PREFIX) #x
>
> We first have to ensure SYMBOL_PREFIX is defined (which avoids polluting
> the command lines for architectures that don't use symbol prefixes).
> Also the definition of SYMBOL_PREFIX in <linux/kernel.h> is removed as
> it conflicts, isn't used anywhere, and is defined as a string so differs
> from the assembly definition.

So now, if CONFIG_SYMBOL_PREFIX, SYMBOL_PREFIX is defined on the cmdline
as a string.  Otherwise it's empty (not the empty string?):

> +/* This helps us to avoid #ifdef SYMBOL_PREFIX */
> +#ifndef SYMBOL_PREFIX
> +#define SYMBOL_PREFIX
>  #endif
> -#define __SYMBOL_NAME(x) __stringify(SYMBOL_NAME(x))
> +
> +#define __SYMBOL_NAME(x) __stringify(SYMBOL_PREFIX) #x

And why are you __stringify()ing a string?

>  #ifndef cond_syscall
>  #define cond_syscall(x) asm(".weak\t" __SYMBOL_NAME(x) \
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index 07125e6..f1cce6a 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -123,6 +123,7 @@ ifdef CONFIG_SYMBOL_PREFIX
>  _sym_flags = -DSYMBOL_PREFIX=$(patsubst "%",%,$(CONFIG_SYMBOL_PREFIX))
>  _cpp_flags += $(_sym_flags)
>  _a_flags += $(_sym_flags)
> +_c_flags += $(_sym_flags)
>  endif

Confused,
Rusty.
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
James Hogan March 8, 2013, 9:15 a.m. UTC | #2
Hi Rusty,

On 08/03/13 00:03, Rusty Russell wrote:
> James Hogan <james.hogan@imgtec.com> writes:
>> Also the definition of SYMBOL_PREFIX in <linux/kernel.h> is removed as
>> it conflicts, isn't used anywhere, and is defined as a string so differs
>> from the assembly definition.
> 
> So now, if CONFIG_SYMBOL_PREFIX, SYMBOL_PREFIX is defined on the cmdline
> as a string.  Otherwise it's empty (not the empty string?):

No, SYMBOL_PREFIX is now defined as a non-string, same as asm files, but
the now unused definition in linux/kernel.h did define it as a string as
it used CONFIG_SYMBOL_PREFIX which is a string. When I said "and is
defined as a string" I was referring to the one in linux/kernel.h that
this removes.

Does that make sense? It's all a bit messy unfortunately (hence RFC).

Cheers
James

--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 80d3687..e13e992 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -723,13 +723,6 @@  static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
 /* Trap pasters of __FUNCTION__ at compile-time */
 #define __FUNCTION__ (__func__)
 
-/* This helps us to avoid #ifdef CONFIG_SYMBOL_PREFIX */
-#ifdef CONFIG_SYMBOL_PREFIX
-#define SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX
-#else
-#define SYMBOL_PREFIX ""
-#endif
-
 /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */
 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
 # define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD
diff --git a/include/linux/linkage.h b/include/linux/linkage.h
index 829d66c..acb869b 100644
--- a/include/linux/linkage.h
+++ b/include/linux/linkage.h
@@ -15,14 +15,12 @@ 
 #define asmlinkage CPP_ASMLINKAGE
 #endif
 
-#ifndef SYMBOL_NAME
-#ifdef CONFIG_SYMBOL_PREFIX
-#define SYMBOL_NAME(x) CONFIG_SYMBOL_PREFIX ## x
-#else
-#define SYMBOL_NAME(x) x
-#endif
+/* This helps us to avoid #ifdef SYMBOL_PREFIX */
+#ifndef SYMBOL_PREFIX
+#define SYMBOL_PREFIX
 #endif
-#define __SYMBOL_NAME(x) __stringify(SYMBOL_NAME(x))
+
+#define __SYMBOL_NAME(x) __stringify(SYMBOL_PREFIX) #x
 
 #ifndef cond_syscall
 #define cond_syscall(x) asm(".weak\t" __SYMBOL_NAME(x) \
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 07125e6..f1cce6a 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -123,6 +123,7 @@  ifdef CONFIG_SYMBOL_PREFIX
 _sym_flags = -DSYMBOL_PREFIX=$(patsubst "%",%,$(CONFIG_SYMBOL_PREFIX))
 _cpp_flags += $(_sym_flags)
 _a_flags += $(_sym_flags)
+_c_flags += $(_sym_flags)
 endif