[RFC 2/3] powerpc: export all symbols from the definition file

Previous thread: none

Next thread: [RFC 1/1][PATCH] POSIX SCHED_SPORADIC implementation for tasks and groups by Dario Faggioli on Monday, August 11, 2008 - 7:45 am. (4 messages)
From: Arnd Bergmann
Date: Monday, August 11, 2008 - 7:06 am

I saw this conversation on IRC when I came back to my screen, and
managed to dig out an older patch of mine:

[19:03:13] <willy> at some point we really need to forbid that
[19:03:28] <willy> bit hard at this point with things like memcpy()
[19:04:36] <willy> could do it with a script of some kind and
           either a whitelist of filenames (arch/*/kernel/ksyms.c
           can export anything) or of functions (anywhere can
           EXPORT_SYMBOL(memcpy)).
[Sun Aug 10 2008] [19:07:35] <viro> I suspect that we really want
           to teach *.S how to do exports
[Sun Aug 10 2008] [19:07:58] <viro> and kill ksyms.c
[Sun Aug 10 2008] [19:12:47] <dwmw2_gone> if we do the -fwhole-program
           --combine thing we'll make it hard anyway

I compile-tested this on powerpc, 32 and 64 bit, and it should be usable as
an example for other architectures.
The idea is to provide an EXPORT_SYMBOL macro for assembly that
behaves in the same way as the C version, and then export every
symbol from the file that defines it.

I'm not sure if the macro I used is actually correct or portable across
all supported architectures, so I hope to get some insight about this
from linux-arch. It does not do genksyms versioned symbol generation
from assembly, but that should be fine since they tend to be really
stable.

	Arnd <><

--

From: Arnd Bergmann
Date: Monday, August 11, 2008 - 7:25 am

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---

 arch/powerpc/kernel/Makefile    |    1 -
 arch/powerpc/kernel/ppc_ksyms.c |  193 ---------------------------------------
 2 files changed, 0 insertions(+), 194 deletions(-)

diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index 64f5948..a0cd670 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -74,7 +74,6 @@ obj-$(CONFIG_PPC32)		+= entry_32.o setup_32.o
 obj-$(CONFIG_PPC64)		+= dma_64.o iommu.o
 obj-$(CONFIG_KGDB)		+= kgdb.o
 obj-$(CONFIG_PPC_MULTIPLATFORM)	+= prom_init.o
-obj-$(CONFIG_MODULES)		+= ppc_ksyms.o
 obj-$(CONFIG_BOOTX_TEXT)	+= btext.o
 obj-$(CONFIG_SMP)		+= smp.o
 obj-$(CONFIG_KPROBES)		+= kprobes.o
diff --git a/arch/powerpc/kernel/ppc_ksyms.c b/arch/powerpc/kernel/ppc_ksyms.c
index e1ea4fe..e69de29 100644
--- a/arch/powerpc/kernel/ppc_ksyms.c
+++ b/arch/powerpc/kernel/ppc_ksyms.c
@@ -1,193 +0,0 @@
-#include <linux/module.h>
-#include <linux/threads.h>
-#include <linux/smp.h>
-#include <linux/sched.h>
-#include <linux/elfcore.h>
-#include <linux/string.h>
-#include <linux/interrupt.h>
-#include <linux/screen_info.h>
-#include <linux/vt_kern.h>
-#include <linux/nvram.h>
-#include <linux/irq.h>
-#include <linux/pci.h>
-#include <linux/delay.h>
-#include <linux/bitops.h>
-
-#include <asm/page.h>
-#include <asm/processor.h>
-#include <asm/cacheflush.h>
-#include <asm/uaccess.h>
-#include <asm/io.h>
-#include <asm/atomic.h>
-#include <asm/checksum.h>
-#include <asm/pgtable.h>
-#include <asm/tlbflush.h>
-#include <linux/adb.h>
-#include <linux/cuda.h>
-#include <linux/pmu.h>
-#include <asm/prom.h>
-#include <asm/system.h>
-#include <asm/pci-bridge.h>
-#include <asm/irq.h>
-#include <asm/pmac_feature.h>
-#include <asm/dma.h>
-#include <asm/machdep.h>
-#include <asm/hw_irq.h>
-#include <asm/nvram.h>
-#include <asm/mmu_context.h>
-#include <asm/backlight.h>
-#include <asm/time.h>
-#include <asm/cputable.h>
-#include ...
From: Arnd Bergmann
Date: Monday, August 11, 2008 - 7:18 am

This makes it possible to export symbols from assembly files, instead
of having to export them through an extra ksyms.c file.

I found this nicer to implement using a gas macro than a cpp macro.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -1,5 +1,7 @@
 #ifndef _LINUX_MODULE_H
 #define _LINUX_MODULE_H
+
+#ifndef __ASSEMBLY__
 /*
  * Dynamic loading of modules into the kernel.
  *
@@ -605,4 +607,54 @@ static inline void module_remove_modinfo_attrs(struct module *mod)
 
 #define __MODULE_STRING(x) __stringify(x)
 
+#else /* __ASSEMBLY__ */
+#include <asm/types.h>
+
+#ifdef CONFIG_MODULES
+.macro __EXPORT_SYMBOL sym section symtab strtab
+	.section \section,"a",@progbits
+	.type \symtab, @object
+	.ifeq BITS_PER_LONG-32
+	.align 3
+\symtab:
+	.long \sym
+	.long \strtab
+	.else
+	.align 4
+\symtab:
+	.quad \sym
+	.quad \strtab
+	.endif
+	.size \symtab,.-\symtab
+	.previous
+
+	.section __ksymtab_strings,"a",@progbits
+	.type \strtab, @object
+\strtab:
+	.string "\sym"
+	.size \strtab,.-\strtab
+	.previous
+	.endm
+
+#define EXPORT_SYMBOL(sym) \
+	 __EXPORT_SYMBOL sym,__ksymtab,__ksymtab_ ## sym,__kstrtab_ ## sym
+#define EXPORT_SYMBOL_GPL(sym) \
+	 __EXPORT_SYMBOL sym,__ksymtab_gpl,__ksymtab_ ## sym,__kstrtab_ ## sym
+#define EXPORT_SYMBOL_GPL_FUTURE(sym) \
+	 __EXPORT_SYMBOL sym,__ksymtab_gpl_future,__ksymtab_ ## sym,__kstrtab_ ## sym
+#define EXPORT_UNUSED_SYMBOL(sym) \
+	 __EXPORT_SYMBOL sym,__ksymtab_unused,__ksymtab_ ## sym,__kstrtab_ ## sym
+#define EXPORT_UNUSED_SYMBOL_GPL(sym) \
+	 __EXPORT_SYMBOL sym,__ksymtab_unused_gpl,__ksymtab_ ## sym,__kstrtab_ ## sym
+
+#else /* CONFIG_MODULES... */
+#define EXPORT_SYMBOL(sym)
+#define EXPORT_SYMBOL_GPL(sym)
+#define EXPORT_SYMBOL_GPL_FUTURE(sym)
+#define EXPORT_UNUSED_SYMBOL(sym)
+#define EXPORT_UNUSED_SYMBOL_GPL(sym)
+#endif /* !CONFIG_MODULES... */
+
+#endif /* __ASSEMBLY__ */
+
 #endif /* _LINUX_MODULE_H */

--

From: David Woodhouse
Date: Monday, August 11, 2008 - 7:56 am

Yeah, gas macros can be much nicer. This looks good to me; I don't see
and reason why it can't be used across all architectures, off-hand.

-- 
David Woodhouse                            Open Source Technology Centre
David.Woodhouse@intel.com                              Intel Corporation



--

From: Rusty Russell
Date: Monday, August 11, 2008 - 7:03 pm

Good work!   Hmm, you can .balign BITS_PER_LONG/8 outside the ifeq.  
Unfortunately .long doesn't do the Right Thing on 64 bit, so getting rid of 
the if is harder.

Acked-by: Rusty Russell <rusty@rustcorp.com.au>

Cheers,
Rusty.
--

From: Stephen Rothwell
Date: Monday, August 11, 2008 - 11:43 pm

Hi Arnd,


This won't be portable across architectures as .align is sometimes in
bytes and sometimes a power of two.  You can use .balign or .p2align
portably on gas, though.=20

--=20
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/
From: Arnd Bergmann
Date: Tuesday, August 12, 2008 - 6:58 am

This makes it possible to export symbols from assembly files, instead
of having to export them through an extra ksyms.c file.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>

---


Ok, this version uses the .balign as suggested by rusty, and also
fixes building with modversions turned on, which did not work in the
first version.

	Arnd <><

--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -1,5 +1,7 @@
 #ifndef _LINUX_MODULE_H
 #define _LINUX_MODULE_H
+
+#ifndef __ASSEMBLY__
 /*
  * Dynamic loading of modules into the kernel.
  *
@@ -605,4 +607,72 @@ static inline void module_remove_modinfo_attrs(struct module *mod)
 
 #define __MODULE_STRING(x) __stringify(x)
 
+#else /* __ASSEMBLY__ */
+#include <asm/types.h>
+
+#ifdef CONFIG_MODULES
+.macro __EXPORT_SYMBOL sym section symtab strtab crctab crc
+	.section \section, "a", @progbits
+	.type \symtab, @object
+	.balign BITS_PER_LONG/8
+\symtab:
+	.ifeq BITS_PER_LONG - 32
+	.long \sym
+	.long \strtab
+	.else
+	.quad \sym
+	.quad \strtab
+	.endif
+	.size \symtab, . - \symtab
+	.previous
+
+	.section __ksymtab_strings, "a", @progbits
+	.type \strtab, @object
+\strtab:
+	.string "\sym"
+	.size \strtab, . - \strtab
+	.previous
+
+#ifdef CONFIG_MODVERSIONS
+	/*
+	 * Modversions doesn't work with assembly files,
+	 * so insert a dummy CRC.
+	 */
+	.section __kcrctab, "a", @progbits
+	.balign 4
+	.type \crctab, @object
+\crctab:
+	.long \crc
+	.size \crctab, . - \crctab
+	.set \crc, 0
+	.previous
+#endif
+	.endm
+
+#define EXPORT_SYMBOL(sym) \
+	 __EXPORT_SYMBOL sym, __ksymtab, __ksymtab_ ## sym, \
+		__kstrtab_ ## sym, __kcrctab_ ## sym, __crc_ ## sym
+#define EXPORT_SYMBOL_GPL(sym) \
+	 __EXPORT_SYMBOL sym, __ksymtab_gpl, __ksymtab_ ## sym, \
+		__kstrtab_ ## sym, __kcrctab_ ## sym, __crc_ ## sym
+#define EXPORT_SYMBOL_GPL_FUTURE(sym) \
+	 __EXPORT_SYMBOL sym, __ksymtab_gpl_future, __ksymtab_ ## sym, \
+		__kstrtab_ ## sym, __kcrctab_ ## sym, __crc_ ## sym
+#define ...
From: Arnd Bergmann
Date: Monday, August 11, 2008 - 7:17 am

It's now possible to export symbols from .S files, so move all
exports out of the ppc_ksyms.c file to the definition of the
symbols.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/powerpc/kernel/entry_32.S       |    3 +++
 arch/powerpc/kernel/entry_64.S       |    2 ++
 arch/powerpc/kernel/fpu.S            |    2 ++
 arch/powerpc/kernel/head_32.S        |    6 ++++++
 arch/powerpc/kernel/head_40x.S       |    4 ++++
 arch/powerpc/kernel/head_44x.S       |    5 +++++
 arch/powerpc/kernel/head_64.S        |    2 ++
 arch/powerpc/kernel/head_8xx.S       |    4 ++++
 arch/powerpc/kernel/head_fsl_booke.S |    6 ++++++
 arch/powerpc/kernel/irq.c            |    4 +++-
 arch/powerpc/kernel/misc_32.S        |   12 ++++++++++++
 arch/powerpc/kernel/misc_64.S        |    5 +++++
 arch/powerpc/kernel/pci-common.c     |    2 ++
 arch/powerpc/kernel/pci_32.c         |    3 +++
 arch/powerpc/kernel/process.c        |    2 ++
 arch/powerpc/kernel/setup-common.c   |    1 +
 arch/powerpc/kernel/setup_32.c       |    5 +++++
 arch/powerpc/kernel/signal_32.c      |    2 ++
 arch/powerpc/kernel/smp.c            |    2 ++
 arch/powerpc/kernel/time.c           |    3 +++
 arch/powerpc/kernel/traps.c          |    4 ++++
 arch/powerpc/lib/checksum_32.S       |    6 ++++++
 arch/powerpc/lib/checksum_64.S       |    5 +++++
 arch/powerpc/lib/copy_32.S           |    7 +++++++
 arch/powerpc/lib/copypage_64.S       |    3 +++
 arch/powerpc/lib/copyuser_64.S       |    3 +++
 arch/powerpc/lib/mem_64.S            |    3 +++
 arch/powerpc/lib/memcpy_64.S         |    3 +++
 arch/powerpc/lib/string.S            |   12 ++++++++++++
 arch/powerpc/mm/hash_low_32.S        |    4 ++++
 arch/powerpc/mm/mmu_context_32.c     |    2 ++
 arch/powerpc/mm/tlb_32.c             |    3 +++
 arch/powerpc/sysdev/dcr-low.S        |    3 +++
 drivers/macintosh/adb.c              |    5 +++++
 drivers/macintosh/via-cuda.c         |    3 +++

 35 files changed, 140 insertions(+), 1 deletion(-)

diff --git ...
From: Geert Uytterhoeven
Date: Monday, August 11, 2008 - 7:53 am

I think these 2 belong to patch 3?

With kind regards,

Geert Uytterhoeven
Software Architect

Sony Techsoft Centre Europe
The Corporate Village 
From: Arnd Bergmann
Date: Monday, August 11, 2008 - 8:27 am

I tried to come up with other ways of splitting up the patch,
but since these come from ppc_ksyms, it makes sense to keep
them with the rest.

Maybe I could split the exports for C functions from those
in assember files that depend on patch 1.

	Arnd <><
--

From: Adrian Bunk
Date: Monday, August 11, 2008 - 8:03 am

On some architectures the kernel is linked with libgcc and symbols from 

cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed

--

Previous thread: none

Next thread: [RFC 1/1][PATCH] POSIX SCHED_SPORADIC implementation for tasks and groups by Dario Faggioli on Monday, August 11, 2008 - 7:45 am. (4 messages)