Skip to contentSkip to conversation

get rid of duplicate exports from string.h

RFC PATCH In review Sam Ravnborg 2 participants 3 messages Mar 11, 2006

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

RFC PATCH 1/1 get rid of duplicate exports from string.h

Following patch implements my suggestion how to get rid of the duplicate exported symbols for the functions defined in lib/string.c and where we often have arch optimised versions.

In lib/string.c export all symbols that are not defines. And remove export from the arch ksyms file.

As an example I've done it for sparc64 but the same applies for most architectures.

The latest version of kbuild - present in -mm - warns about duplicate exported symbols. With this approch the primary offenders will be removed.

Sample output:
WARNING: vmlinux: 'strcpy' exported twice. Previous export was in vmlinux
WARNING: vmlinux: 'strncpy' exported twice. Previous export was in vmlinux
WARNING: vmlinux: 'strcat' exported twice. Previous export was in vmlinux
WARNING: vmlinux: 'strncat' exported twice. Previous export was in vmlinux
WARNING: vmlinux: 'strcmp' exported twice. Previous export was in vmlinux
WARNING: vmlinux: 'strchr' exported twice. Previous export was in vmlinux
WARNING: vmlinux: 'strrchr' exported twice. Previous export was in vmlinux
WARNING: vmlinux: 'strnlen' exported twice. Previous export was in vmlinux
WARNING: vmlinux: 'strpbrk' exported twice. Previous export was in vmlinux
WARNING: vmlinux: 'strstr' exported twice. Previous export was in vmlinux
WARNING: vmlinux: 'memchr' exported twice. Previous export was in vmlinux

I did not find a better way than:

#if !defined(strcpy)
	EXPORT_SYMBOL(strcpy);

#endif
We need to check if the symbol is defined because we cannot export a defined version of say memset as done by sparc64.

But if there is a better way to use the preprocessor I'm all ears.

Comments welcome.

Sam

arch/sparc64/kernel/sparc64_ksyms.c +0 -16
index 3c06bfb..f2b174b 100644
@@ -277,19 +277,8 @@ EXPORT_SYMBOL(__prom_getchild);
 EXPORT_SYMBOL(__prom_getsibling);
 
 /* sparc library symbols */
-EXPORT_SYMBOL(strlen);
-EXPORT_SYMBOL(strnlen);
 EXPORT_SYMBOL(__strlen_user);
 EXPORT_SYMBOL(__strnlen_user);
-EXPORT_SYMBOL(strcpy);
-EXPORT_SYMBOL(strncpy);
-EXPORT_SYMBOL(strcat);
-EXPORT_SYMBOL(strncat);
-EXPORT_SYMBOL(strcmp);
-EXPORT_SYMBOL(strchr);
-EXPORT_SYMBOL(strrchr);
-EXPORT_SYMBOL(strpbrk);
-EXPORT_SYMBOL(strstr);
 
 #ifdef CONFIG_SOLARIS_EMUL_MODULE
 EXPORT_SYMBOL(linux_sparc_syscall);
@@ -323,7 +312,6 @@ EXPORT_SYMBOL(__memscan_zero);
 EXPORT_SYMBOL(__memscan_generic);
 EXPORT_SYMBOL(__memcmp);
 EXPORT_SYMBOL(__memset);
-EXPORT_SYMBOL(memchr);
 
 EXPORT_SYMBOL(csum_partial);
 EXPORT_SYMBOL(csum_partial_copy_nocheck);
@@ -354,11 +342,7 @@ EXPORT_SYMBOL(pfn_to_page);
 EXPORT_SYMBOL(__ret_efault);
 
 /* No version information on these, as gcc produces such symbols. */
-EXPORT_SYMBOL(memcmp);
-EXPORT_SYMBOL(memcpy);
 EXPORT_SYMBOL(memset);
-EXPORT_SYMBOL(memmove);
-EXPORT_SYMBOL(strncmp);
 
 /* Delay routines. */
 EXPORT_SYMBOL(__udelay);
lib/string.c +72 -25

239 lines not on this page · raw message

#1 lore raw
Quoted 4 lines · Sam Ravnborg

In lib/string.c export all symbols that are not defines.
...
As an example I've done it for sparc64 but the same applies for most architectures.

A few comments:

1. it'd be nice to use #ifndef blah instead of #if !defined(blah)

2. I don't think we normally indent for preprocessor conditionals - if we did, would we not have these function definitions indented?

3. I don't understand how these !defined things are supposed to solve the problem. There are three cases, and use strcpy as an example:

a) an architecture decides to override the lib/string.c definition with its own static inline function. In this case, it must define __HAVE_ARCH_STRCPY to exclude the lib/string.c version.

In this case, the architecture may decide against exporting the named function because it'll always be inlined.

b) an architecture decides to override the lib/string.c definition with its own macro version. This case is essentially the same as case (a).

c) an architecture decides to override the lib/string.c definition with its own out of line version. It must define __HAVE_ARCH_STRCPY as per (a), but it wants an export.

d) an architecture wishes to use the lib/string.c definition. It must not define __HAVE_ARCH_STRCPY.

With these changes, case (a) requires an additional #define strcpy strcpy to prevent the EXPORT_SYMBOL being used.

Since we have case (a) in the kernel sources, I don't see any additional #defines being added to prevent these exports. Maybe you decided to always cause lib/string.c to export them except for case (b) ?

All in all, I think this is a complex solution to something which should be simple. We have the general rule that EXPORT_SYMBOLs should be local to the code which provides the function - at least within the same file. This change seems to be a step away from that.

I much prefer the current implementation where, if you define __HAVE_ARCH_foo then foo is not defined nor exported by the core kernel.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#2 lore raw
Quoted 9 lines · Russell King
Quoted 4 lines · Sam Ravnborg

In lib/string.c export all symbols that are not defines.
...
As an example I've done it for sparc64 but the same applies for most architectures.

A few comments:

1. it'd be nice to use #ifndef blah instead of #if !defined(blah)

OK

Quoted 2 lines

2. I don't think we normally indent for preprocessor conditionals - if we did, would we not have these function definitions indented?

OK

Quoted 18 lines

3. I don't understand how these !defined things are supposed to solve the problem. There are three cases, and use strcpy as an example:

a) an architecture decides to override the lib/string.c definition with its own static inline function. In this case, it must define __HAVE_ARCH_STRCPY to exclude the lib/string.c version.

In this case, the architecture may decide against exporting the named function because it'll always be inlined.

b) an architecture decides to override the lib/string.c definition with its own macro version. This case is essentially the same as case (a).

c) an architecture decides to override the lib/string.c definition with its own out of line version. It must define __HAVE_ARCH_STRCPY as per (a), but it wants an export.

Quoted 5 lines

d) an architecture wishes to use the lib/string.c definition. It must not define __HAVE_ARCH_STRCPY.

With these changes, case (a) requires an additional #define strcpy strcpy to prevent the EXPORT_SYMBOL being used.

I did not consider the a) case at all. Did not hit it with sparc64 that I'm playing with,

Quoted 9 lines

Since we have case (a) in the kernel sources, I don't see any additional #defines being added to prevent these exports. Maybe you decided to always cause lib/string.c to export them except for case (b) ?

All in all, I think this is a complex solution to something which should be simple. We have the general rule that EXPORT_SYMBOLs should be local to the code which provides the function - at least within the same file. This change seems to be a step away from that.

Thought of it as the exception from the rule thing.

Quoted 3 lines

I much prefer the current implementation where, if you define __HAVE_ARCH_foo then foo is not defined nor exported by the core kernel.

I will go for this one and submit changes to lkml+arch maintainer as I get crosscompile suites up and running.

Thanks for the feedback!

Sam