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

From: James Hogan <[email-masked]>
Date: Wed, 13 Mar 2013 09:21:01 +0000

Hi Sam,

On 13/03/13 06:31, Sam Ravnborg wrote:
>>  /* Some toolchains use a `_' prefix for all user symbols. */
>> -#ifdef CONFIG_SYMBOL_PREFIX
>> -#define MODULE_SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX
>> +#ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX
>> +#define __VMLINUX_SYMBOL(x) _##x
>> +#define __VMLINUX_SYMBOL_STR(x) "_" #x
>> +#define VMLINUX_SYMBOL_PREFIX_STR "_"
>>  #else
>> -#define MODULE_SYMBOL_PREFIX ""
>> +#define __VMLINUX_SYMBOL(x) x
>> +#define __VMLINUX_SYMBOL_STR(x) #x
>> +#define VMLINUX_SYMBOL_PREFIX_STR ""
>>  #endif
> 
> We know the prefix is an underscore. No benefits from defining
> VMLINUX_SYMBOL_PREFIX_STR.

scripts/modpost.c uses the actual prefix string though:

>	if (memcmp(symname, MODULE_SYMBOL_PREFIX,
>		   strlen(MODULE_SYMBOL_PREFIX)) == 0) {
>		mod->unres =
>		  alloc_symbol(symname +
>		               strlen(MODULE_SYMBOL_PREFIX),
> 		               ELF_ST_BIND(sym->st_info) == STB_WEAK,
> 		               mod->unres);

See also my "module: fix symbol versioning with symbol prefixes" patch
for an additional use in modpost.

Having a MODULE_SYMBOL_PREFIX/VMLINUX_SYMBOL_PREFIX_STR seems like the
simplest way to keep this code clean and readable without special cases.

Cheers
James