Skip to contentSkip to conversation

Make most arch asm/module.h files use asm-generic/module.h

PATCH In review David Howells 7 participants 10 messages Jul 18, 2012 – Jul 19, 2012

Subsystems (12)
Arm (32-bit) x86 PowerPC MIPS +8 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make most arch asm/module.h files use asm-generic/module.h

Hi Rusty, Arnd,

Here's a patch to asm-genericise the arch asm/module.h files. It allows four of them to be deleted outright. MIPS is the only weirdo of the bunch.

The patch can also be found here:

http://git.kernel.org/?p=linux/kernel/git/dhowells/linux-modsign.git;a=shortlog;h=refs/heads/for-rusty

David
---
commit 4ef65a8a753f6fee4436dfa369e7471d3496b3ae

Author: David Howells <[email protected]>
Date:   Wed Jul 18 13:26:21 2012 +0100

Make most arch asm/module.h files use asm-generic/module.h

Use the mapping of Elf_[SPE]hdr, Elf_Sym, Elf_Dyn, Elf_Rel/Rela, ELF_R_TYPE() and ELF_R_SYM() to either the 32-bit version or the 64-bit version into asm-generic/module.h for all arches bar MIPS.

Also, use the generic definition mod_arch_specific where possible.

To this end, I've defined three new config bools:

(*) HAVE_MOD_ARCH_SPECIFIC

Arches define this if they don't want to use the empty generic mod_arch_specific struct.

(*) MODULES_USE_RELA_ONLY

Arches define this if their modules will only contain RELA records (and not REL records). This causes the Elf_Rel mapping not to be emitted.

(*) MODULES_USE_REL_ONLY

Arches define this if their modules will only contain REL records (and not RELA records). This causes the Elf_Rela mapping not to be emitted.

With this, some arch asm/module.h files can be deleted entirely and replaced with a generic-y marker in the arch Kbuild file.

arch/alpha/Kconfig +1 -0
index 3de74c9..0ff4c87 100644
@@ -17,6 +17,7 @@ config ALPHA
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	select GENERIC_SMP_IDLE_THREAD
 	select GENERIC_CMOS_UPDATE
+	select HAVE_MOD_ARCH_SPECIFIC
 	help
 	  The Alpha is a 64-bit general-purpose processor designed and
 	  marketed by the Digital Equipment Corporation of blessed memory,
arch/alpha/include/asm/module.h +2 -8
index 7b63743..9cd13b5 100644
@@ -1,19 +1,13 @@
 #ifndef _ALPHA_MODULE_H
 #define _ALPHA_MODULE_H
 
+#include <asm-generic/module.h>
+
 struct mod_arch_specific
 {
 	unsigned int gotsecindex;
 };
 
-#define Elf_Sym Elf64_Sym
-#define Elf_Shdr Elf64_Shdr
-#define Elf_Ehdr Elf64_Ehdr
-#define Elf_Phdr Elf64_Phdr
-#define Elf_Dyn Elf64_Dyn
-#define Elf_Rel Elf64_Rel
-#define Elf_Rela Elf64_Rela
-
 #define ARCH_SHF_SMALL SHF_ALPHA_GPREL
 
 #ifdef MODULE
arch/arm/Kconfig +1 -0
index a91009c..3499e79 100644
@@ -45,6 +45,7 @@ config ARM
 	select GENERIC_SMP_IDLE_THREAD
 	select KTIME_SCALAR
 	select GENERIC_CLOCKEVENTS_BROADCAST if SMP
+	select HAVE_MOD_ARCH_SPECIFIC if ARM_UNWIND
 	help
 	  The ARM series is a line of low-power-consumption RISC chip designs
 	  licensed by ARM Ltd and targeted at embedded applications and
arch/arm/include/asm/module.h +2 -6
index 6c6809f..0d3a28d 100644
@@ -1,9 +1,7 @@
 #ifndef _ASM_ARM_MODULE_H
 #define _ASM_ARM_MODULE_H
 
-#define Elf_Shdr	Elf32_Shdr
-#define Elf_Sym		Elf32_Sym
-#define Elf_Ehdr	Elf32_Ehdr
+#include <asm-generic/module.h>
 
 struct unwind_table;
 
@@ -16,13 +14,11 @@ enum {
 	ARM_SEC_DEVEXIT,
 	ARM_SEC_MAX,
 };
-#endif
 
 struct mod_arch_specific {
-#ifdef CONFIG_ARM_UNWIND
 	struct unwind_table *unwind[ARM_SEC_MAX];
-#endif
 };
+#endif
 
 /*
  * Add the ARM architecture version to the version magic string
arch/avr32/Kconfig +1 -0
index 71d38c7..01f9ecb 100644
@@ -14,6 +14,7 @@ config AVR32
 	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	select GENERIC_CLOCKEVENTS
+	select HAVE_MOD_ARCH_SPECIFIC
 	help
 	  AVR32 is a high-performance 32-bit RISC microprocessor core,
 	  designed for cost-sensitive embedded applications, with particular
arch/avr32/include/asm/module.h +2 -4
index 4514445..3f083d3 100644
@@ -1,6 +1,8 @@
 #ifndef __ASM_AVR32_MODULE_H
 #define __ASM_AVR32_MODULE_H
 
+#include <asm-generic/module.h>
+
 struct mod_arch_syminfo {
 	unsigned long got_offset;
 	int got_initialized;
@@ -17,10 +19,6 @@ struct mod_arch_specific {
 	struct mod_arch_syminfo *syminfo;
 };
 
-#define Elf_Shdr		Elf32_Shdr
-#define Elf_Sym			Elf32_Sym
-#define Elf_Ehdr		Elf32_Ehdr
-
 #define MODULE_PROC_FAMILY "AVR32v1"
 
 #define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
arch/blackfin/Kconfig +1 -0
index fef96f4..08f5ca1 100644
@@ -40,6 +40,7 @@ config BLACKFIN
 	select HAVE_NMI_WATCHDOG if NMI_WATCHDOG
 	select GENERIC_SMP_IDLE_THREAD
 	select ARCH_USES_GETTIMEOFFSET if !GENERIC_CLOCKEVENTS
+	select HAVE_MOD_ARCH_SPECIFIC
 
 config GENERIC_CSUM
 	def_bool y
arch/blackfin/include/asm/module.h +1 -3
index ed5689b..231a149 100644
@@ -7,9 +7,7 @@
 #ifndef _ASM_BFIN_MODULE_H
 #define _ASM_BFIN_MODULE_H
 
-#define Elf_Shdr        Elf32_Shdr
-#define Elf_Sym         Elf32_Sym
-#define Elf_Ehdr        Elf32_Ehdr
+#include <asm-generic/module.h>
 
 struct mod_arch_specific {
 	Elf_Shdr	*text_l1;
arch/c6x/include/asm/module.h +1 -11
index a453f97..5c7269c 100644
@@ -13,17 +13,7 @@
 #ifndef _ASM_C6X_MODULE_H
 #define _ASM_C6X_MODULE_H
 
-#define Elf_Shdr	Elf32_Shdr
-#define Elf_Sym		Elf32_Sym
-#define Elf_Ehdr	Elf32_Ehdr
-#define Elf_Addr	Elf32_Addr
-#define Elf_Word	Elf32_Word
-
-/*
- * This file contains the C6x architecture specific module code.
- */
-struct mod_arch_specific {
-};
+#include <asm-generic/module.h>
 
 struct loaded_sections {
 	unsigned int new_vaddr;
arch/cris/include/asm/Kbuild +2 -0
index 04d02a5..28b690d 100644
@@ -7,3 +7,5 @@ header-y += ethernet.h
 header-y += etraxgpio.h
 header-y += rs485.h
 header-y += sync_serial.h
+
+generic-y += module.h
arch/cris/include/asm/module.h deleted +0 -9
deleted file mode 100644
index 7ee7231..0000000
@@ -1,9 +0,0 @@
-#ifndef _ASM_CRIS_MODULE_H
-#define _ASM_CRIS_MODULE_H
-/* cris is simple */
-struct mod_arch_specific { };
-
-#define Elf_Shdr Elf32_Shdr
-#define Elf_Sym Elf32_Sym
-#define Elf_Ehdr Elf32_Ehdr
-#endif /* _ASM_CRIS_MODULE_H */
arch/frv/include/asm/module.h +1 -7
index 3d5c636..a8848f0 100644
@@ -11,13 +11,7 @@
 #ifndef _ASM_MODULE_H
 #define _ASM_MODULE_H
 
-struct mod_arch_specific
-{
-};
-
-#define Elf_Shdr	Elf32_Shdr
-#define Elf_Sym		Elf32_Sym
-#define Elf_Ehdr	Elf32_Ehdr
+#include <asm-generic/module.h>
 
 /*
  * Include the architecture version.
arch/h8300/include/asm/Kbuild +2 -0
index c68e168..871382d 100644
@@ -1 +1,3 @@
 include include/asm-generic/Kbuild.asm
+
+generic-y	+= module.h
arch/h8300/include/asm/module.h deleted +0 -11
deleted file mode 100644
index 8e46724..0000000
@@ -1,11 +0,0 @@
-#ifndef _ASM_H8300_MODULE_H
-#define _ASM_H8300_MODULE_H
-/*
- * This file contains the H8/300 architecture specific module code.
- */
-struct mod_arch_specific { };
-#define Elf_Shdr Elf32_Shdr
-#define Elf_Sym Elf32_Sym
-#define Elf_Ehdr Elf32_Ehdr
-
-#endif /* _ASM_H8/300_MODULE_H */
arch/ia64/Kconfig +1 -0
index 8186ec5..217386c 100644
@@ -39,6 +39,7 @@ config IA64
 	select ARCH_THREAD_INFO_ALLOCATOR
 	select ARCH_CLOCKSOURCE_DATA
 	select GENERIC_TIME_VSYSCALL
+	select HAVE_MOD_ARCH_SPECIFIC
 	default y
 	help
 	  The Itanium Processor Family is Intel's 64-bit successor to
arch/ia64/include/asm/module.h +2 -4
index 908eaef..dfba22a 100644
@@ -1,6 +1,8 @@
 #ifndef _ASM_IA64_MODULE_H
 #define _ASM_IA64_MODULE_H
 
+#include <asm-generic/module.h>
+
 /*
  * IA-64-specific support for kernel module loader.
  *
@@ -29,10 +31,6 @@ struct mod_arch_specific {
 	unsigned int next_got_entry;	/* index of next available got entry */
 };
 
-#define Elf_Shdr	Elf64_Shdr
-#define Elf_Sym		Elf64_Sym
-#define Elf_Ehdr	Elf64_Ehdr
-
 #define MODULE_PROC_FAMILY	"ia64"
 #define MODULE_ARCH_VERMAGIC	MODULE_PROC_FAMILY \
 	"gcc-" __stringify(__GNUC__) "." __stringify(__GNUC_MINOR__)
arch/m32r/include/asm/Kbuild +2 -0
index c68e168..871382d 100644
@@ -1 +1,3 @@
 include include/asm-generic/Kbuild.asm
+
+generic-y	+= module.h
arch/m32r/include/asm/module.h deleted +0 -10
deleted file mode 100644
index eb73ee0..0000000
@@ -1,10 +0,0 @@
-#ifndef _ASM_M32R_MODULE_H
-#define _ASM_M32R_MODULE_H
-
-struct mod_arch_specific { };
-
-#define Elf_Shdr	Elf32_Shdr
-#define Elf_Sym		Elf32_Sym
-#define Elf_Ehdr	Elf32_Ehdr
-
-#endif /* _ASM_M32R_MODULE_H */
arch/m68k/Kconfig +1 -0
index 1471201..7d2a2f3 100644
@@ -11,6 +11,7 @@ config M68K
 	select GENERIC_STRNLEN_USER if MMU
 	select FPU if MMU
 	select ARCH_USES_GETTIMEOFFSET if MMU && !COLDFIRE
+	select HAVE_MOD_ARCH_SPECIFIC
 
 config RWSEM_GENERIC_SPINLOCK
 	bool
arch/m68k/include/asm/module.h +2 -4
index edffe66..8b58fce 100644
@@ -1,6 +1,8 @@
 #ifndef _ASM_M68K_MODULE_H
 #define _ASM_M68K_MODULE_H
 
+#include <asm-generic/module.h>
+
 enum m68k_fixup_type {
 	m68k_fixup_memoffset,
 	m68k_fixup_vnode_shift,
@@ -36,8 +38,4 @@ struct module;
 extern void module_fixup(struct module *mod, struct m68k_fixup_info *start,
 			 struct m68k_fixup_info *end);
 
-#define Elf_Shdr Elf32_Shdr
-#define Elf_Sym Elf32_Sym
-#define Elf_Ehdr Elf32_Ehdr
-
 #endif /* _ASM_M68K_MODULE_H */
arch/mips/Kconfig +1 -0
index 09ab87e..cf0ff5b 100644
@@ -34,6 +34,7 @@ config MIPS
 	select BUILDTIME_EXTABLE_SORT
 	select GENERIC_CLOCKEVENTS
 	select GENERIC_CMOS_UPDATE
+	select HAVE_MOD_ARCH_SPECIFIC
 
 menu "Machine selection"
 
arch/mips/include/asm/module.h +8 -2
index 5300080..2c6a4f21 100644
@@ -34,11 +34,14 @@ typedef struct {
 } Elf64_Mips_Rela;
 
 #ifdef CONFIG_32BIT
-
 #define Elf_Shdr	Elf32_Shdr
 #define Elf_Sym		Elf32_Sym
 #define Elf_Ehdr	Elf32_Ehdr
 #define Elf_Addr	Elf32_Addr
+#define Elf_Rel		Elf32_Rel
+#define Elf_Rela	Elf32_Rela
+#define ELF_R_TYPE(X)	ELF32_R_TYPE(X)
+#define ELF_R_SYM(X)	ELF32_R_SYM(X)
 
 #define Elf_Mips_Rel	Elf32_Rel
 #define Elf_Mips_Rela	Elf32_Rela
@@ -49,11 +52,14 @@ typedef struct {
 #endif
 
 #ifdef CONFIG_64BIT
-
 #define Elf_Shdr	Elf64_Shdr
 #define Elf_Sym		Elf64_Sym
 #define Elf_Ehdr	Elf64_Ehdr
 #define Elf_Addr	Elf64_Addr
+#define Elf_Rel		Elf64_Rel
+#define Elf_Rela	Elf64_Rela
+#define ELF_R_TYPE(X)	ELF64_R_TYPE(X)
+#define ELF_R_SYM(X)	ELF64_R_SYM(X)
 
 #define Elf_Mips_Rel	Elf64_Mips_Rel
 #define Elf_Mips_Rela	Elf64_Mips_Rela
arch/mn10300/include/asm/module.h +1 -6
index 5d7057d..6571103 100644
@@ -12,12 +12,7 @@
 #ifndef _ASM_MODULE_H
 #define _ASM_MODULE_H
 
-struct mod_arch_specific {
-};
-
-#define Elf_Shdr	Elf32_Shdr
-#define Elf_Sym		Elf32_Sym
-#define Elf_Ehdr	Elf32_Ehdr
+#include <asm-generic/module.h>
 
 /*
  * Include the MN10300 architecture version.
arch/parisc/Kconfig +1 -0
index 3ff21b5..86c6ebd 100644
@@ -19,6 +19,7 @@ config PARISC
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	select GENERIC_SMP_IDLE_THREAD
 	select GENERIC_STRNCPY_FROM_USER
+	select HAVE_MOD_ARCH_SPECIFIC
 
 	help
 	  The PA-RISC microprocessor is designed by Hewlett-Packard and used
arch/parisc/include/asm/module.h +3 -13
index 1f41234..bab37e9 100644
@@ -1,21 +1,11 @@
 #ifndef _ASM_PARISC_MODULE_H
 #define _ASM_PARISC_MODULE_H
+
+#include <asm-generic/module.h>
+
 /*
  * This file contains the parisc architecture specific module code.
  */
-#ifdef CONFIG_64BIT
-#define Elf_Shdr Elf64_Shdr
-#define Elf_Sym Elf64_Sym
-#define Elf_Ehdr Elf64_Ehdr
-#define Elf_Addr Elf64_Addr
-#define Elf_Rela Elf64_Rela
-#else
-#define Elf_Shdr Elf32_Shdr
-#define Elf_Sym Elf32_Sym
-#define Elf_Ehdr Elf32_Ehdr
-#define Elf_Addr Elf32_Addr
-#define Elf_Rela Elf32_Rela
-#endif
 
 struct unwind_table;
 
arch/powerpc/Kconfig +1 -0
index 050cb37..8a8b0a9 100644
@@ -137,6 +137,7 @@ config PPC
 	select GENERIC_CLOCKEVENTS
 	select GENERIC_STRNCPY_FROM_USER
 	select GENERIC_STRNLEN_USER
+	select HAVE_MOD_ARCH_SPECIFIC
 
 config EARLY_PRINTK
 	bool
arch/powerpc/include/asm/module.h +1 -6
index 0192a4e..c1df590 100644
@@ -11,6 +11,7 @@
 
 #include <linux/list.h>
 #include <asm/bug.h>
+#include <asm-generic/module.h>
 
 
 #ifndef __powerpc64__
@@ -60,16 +61,10 @@ struct mod_arch_specific {
  */
 
 #ifdef __powerpc64__
-#    define Elf_Shdr	Elf64_Shdr
-#    define Elf_Sym	Elf64_Sym
-#    define Elf_Ehdr	Elf64_Ehdr
 #    ifdef MODULE
 	asm(".section .stubs,\"ax\",@nobits; .align 3; .previous");
 #    endif
 #else
-#    define Elf_Shdr	Elf32_Shdr
-#    define Elf_Sym	Elf32_Sym
-#    define Elf_Ehdr	Elf32_Ehdr
 #    ifdef MODULE
 	asm(".section .plt,\"ax\",@nobits; .align 3; .previous");
 	asm(".section .init.plt,\"ax\",@nobits; .align 3; .previous");
arch/s390/Kconfig +1 -0
index a39b469..61fb321 100644
@@ -121,6 +121,7 @@ config S390
 	select GENERIC_TIME_VSYSCALL
 	select GENERIC_CLOCKEVENTS
 	select KTIME_SCALAR if 32BIT
+	select HAVE_MOD_ARCH_SPECIFIC
 
 config SCHED_OMIT_FRAME_POINTER
 	def_bool y
arch/s390/include/asm/module.h +3 -15
index f0b6b26..df1f861 100644
@@ -1,5 +1,8 @@
 #ifndef _ASM_S390_MODULE_H
 #define _ASM_S390_MODULE_H
+
+#include <asm-generic/module.h>
+
 /*
  * This file contains the s390 architecture specific module code.
  */
@@ -28,19 +31,4 @@ struct mod_arch_specific
 	struct mod_arch_syminfo *syminfo;
 };
 
-#ifdef CONFIG_64BIT
-#define ElfW(x) Elf64_ ## x
-#define ELFW(x) ELF64_ ## x
-#else
-#define ElfW(x) Elf32_ ## x
-#define ELFW(x) ELF32_ ## x
-#endif
-
-#define Elf_Addr ElfW(Addr)
-#define Elf_Rela ElfW(Rela)
-#define Elf_Shdr ElfW(Shdr)
-#define Elf_Sym ElfW(Sym)
-#define Elf_Ehdr ElfW(Ehdr)
-#define ELF_R_SYM ELFW(R_SYM)
-#define ELF_R_TYPE ELFW(R_TYPE)
 #endif /* _ASM_S390_MODULE_H */
arch/score/Kconfig +1 -0
index ba0f412..ceeeb5a 100644
@@ -10,6 +10,7 @@ config SCORE
        select ARCH_DISCARD_MEMBLOCK
        select GENERIC_CPU_DEVICES
        select GENERIC_CLOCKEVENTS
+       select HAVE_MOD_ARCH_SPECIFIC
 
 choice
 	prompt "System type"
arch/score/include/asm/module.h +1 -5
index f0b5dc0..abf395b 100644
@@ -3,6 +3,7 @@
 
 #include <linux/list.h>
 #include <asm/uaccess.h>
+#include <asm-generic/module.h>
 
 struct mod_arch_specific {
 	/* Data Bus Error exception tables */
@@ -13,11 +14,6 @@ struct mod_arch_specific {
 
 typedef uint8_t Elf64_Byte;		/* Type for a 8-bit quantity. */
 
-#define Elf_Shdr	Elf32_Shdr
-#define Elf_Sym		Elf32_Sym
-#define Elf_Ehdr	Elf32_Ehdr
-#define Elf_Addr	Elf32_Addr
-
 /* Given an address, look for it in the exception tables. */
 #ifdef CONFIG_MODULES
 const struct exception_table_entry *search_module_dbetables(unsigned long addr);
arch/sh/Kconfig +1 -0
index 31d9db7..23de034 100644
@@ -34,6 +34,7 @@ config SUPERH
 	select GENERIC_CMOS_UPDATE if SH_SH03 || SH_DREAMCAST
 	select GENERIC_STRNCPY_FROM_USER
 	select GENERIC_STRNLEN_USER
+	select HAVE_MOD_ARCH_SPECIFIC if DWARF_UNWINDER
 	help
 	  The SuperH is a RISC processor targeted for use in embedded systems
 	  and consumer electronics; it was also used in the Sega Dreamcast
arch/sh/include/asm/module.h +3 -11
index b7927de..81300d8b 100644
@@ -1,21 +1,13 @@
 #ifndef _ASM_SH_MODULE_H
 #define _ASM_SH_MODULE_H
 
-struct mod_arch_specific {
+#include <asm-generic/module.h>
+
 #ifdef CONFIG_DWARF_UNWINDER
+struct mod_arch_specific {
 	struct list_head fde_list;
 	struct list_head cie_list;
-#endif
 };
-
-#ifdef CONFIG_64BIT
-#define Elf_Shdr Elf64_Shdr
-#define Elf_Sym Elf64_Sym
-#define Elf_Ehdr Elf64_Ehdr
-#else
-#define Elf_Shdr Elf32_Shdr
-#define Elf_Sym Elf32_Sym
-#define Elf_Ehdr Elf32_Ehdr
 #endif
 
 #ifdef CONFIG_CPU_LITTLE_ENDIAN
arch/sparc/Kconfig +1 -0
index e74ff13..f5cecb3 100644
@@ -36,6 +36,7 @@ config SPARC
 	select GENERIC_CLOCKEVENTS
 	select GENERIC_STRNCPY_FROM_USER
 	select GENERIC_STRNLEN_USER
+	select MODULES_USE_RELA_ONLY
 
 config SPARC32
 	def_bool !64BIT
arch/sparc/include/asm/Kbuild +1 -0
index 67f83e0..fbe1cb5 100644
@@ -21,4 +21,5 @@ generic-y += div64.h
 generic-y += local64.h
 generic-y += irq_regs.h
 generic-y += local.h
+generic-y += module.h
 generic-y += word-at-a-time.h
arch/sparc/include/asm/module.h deleted +0 -24
deleted file mode 100644
index ff8e02d..0000000
@@ -1,24 +0,0 @@
-#ifndef __SPARC_MODULE_H
-#define __SPARC_MODULE_H
-struct mod_arch_specific { };
-
-/*
- * Use some preprocessor magic to define the correct symbol
- * for sparc32 and sparc64.
- * Elf_Addr becomes Elf32_Addr for sparc32 and Elf64_Addr for sparc64
- */
-#define ___ELF(a, b, c) a##b##c
-#define __ELF(a, b, c)  ___ELF(a, b, c)
-#define  _Elf(t)        __ELF(Elf, CONFIG_BITS, t)
-#define  _ELF(t)        __ELF(ELF, CONFIG_BITS, t)
-
-#define Elf_Shdr     _Elf(_Shdr)
-#define Elf_Sym      _Elf(_Sym)
-#define Elf_Ehdr     _Elf(_Ehdr)
-#define Elf_Rela     _Elf(_Rela)
-#define Elf_Addr     _Elf(_Addr)
-
-#define ELF_R_SYM    _ELF(_R_SYM)
-#define ELF_R_TYPE   _ELF(_R_TYPE)
-
-#endif /* __SPARC_MODULE_H */
arch/x86/Kconfig +2 -0
index c70684f..3cebb96 100644
@@ -95,6 +95,8 @@ config X86
 	select KTIME_SCALAR if X86_32
 	select GENERIC_STRNCPY_FROM_USER
 	select GENERIC_STRNLEN_USER
+	select MODULES_USE_REL_ONLY if X86_32
+	select MODULES_USE_RELA_ONLY if X86_64
 
 config INSTRUCTION_DECODER
 	def_bool (KPROBES || PERF_EVENTS || UPROBES)
arch/xtensa/include/asm/module.h +1 -8
index d9b34be..488b40c 100644
@@ -13,15 +13,8 @@
 #ifndef _XTENSA_MODULE_H
 #define _XTENSA_MODULE_H
 
-struct mod_arch_specific
-{
-	/* No special elements, yet. */
-};
-
 #define MODULE_ARCH_VERMAGIC "xtensa-" __stringify(XCHAL_CORE_ID) " "
 
-#define Elf_Shdr Elf32_Shdr
-#define Elf_Sym Elf32_Sym
-#define Elf_Ehdr Elf32_Ehdr
+#include <asm-generic/module.h>
 
 #endif	/* _XTENSA_MODULE_H */
include/asm-generic/module.h +33 -7
index ed5b44d..479feb0 100644
@@ -5,18 +5,44 @@
  * Many architectures just need a simple module
  * loader without arch specific data.
  */
+#ifndef CONFIG_HAVE_MOD_ARCH_SPECIFIC
 struct mod_arch_specific
 {
 };
+#endif
 
 #ifdef CONFIG_64BIT
-#define Elf_Shdr Elf64_Shdr
-#define Elf_Sym Elf64_Sym
-#define Elf_Ehdr Elf64_Ehdr
-#else
-#define Elf_Shdr Elf32_Shdr
-#define Elf_Sym Elf32_Sym
-#define Elf_Ehdr Elf32_Ehdr
+#define Elf_Shdr	Elf64_Shdr
+#define Elf_Phdr	Elf64_Phdr
+#define Elf_Sym		Elf64_Sym
+#define Elf_Dyn		Elf64_Dyn
+#define Elf_Ehdr	Elf64_Ehdr
+#define Elf_Addr	Elf64_Addr
+#ifndef CONFIG_MODULES_USE_RELA_ONLY
+#define Elf_Rel		Elf64_Rel
+#endif
+#ifndef CONFIG_MODULES_USE_REL_ONLY
+#define Elf_Rela	Elf64_Rela
+#endif
+#define ELF_R_TYPE(X)	ELF64_R_TYPE(X)
+#define ELF_R_SYM(X)	ELF64_R_SYM(X)
+
+#else /* CONFIG_64BIT */
+
+#define Elf_Shdr	Elf32_Shdr
+#define Elf_Phdr	Elf32_Phdr
+#define Elf_Sym		Elf32_Sym
+#define Elf_Dyn		Elf32_Dyn
+#define Elf_Ehdr	Elf32_Ehdr
+#define Elf_Addr	Elf32_Addr
+#ifndef CONFIG_MODULES_USE_RELA_ONLY
+#define Elf_Rel		Elf32_Rel
+#endif
+#ifndef CONFIG_MODULES_USE_REL_ONLY
+#define Elf_Rela	Elf32_Rela
+#endif
+#define ELF_R_TYPE(X)	ELF32_R_TYPE(X)
+#define ELF_R_SYM(X)	ELF32_R_SYM(X)
 #endif
 
 #endif /* __ASM_GENERIC_MODULE_H */
init/Kconfig +20 -0
index d07dcf9..39a6753 100644
@@ -1570,6 +1570,26 @@ config MODULE_SRCVERSION_ALL
 	  the version).  With this option, such a "srcversion" field
 	  will be created for all modules.  If unsure, say N.
 
+config HAVE_MOD_ARCH_SPECIFIC
+	bool
+	help
+	  The arch uses struct mod_arch_specific to store data.  Many arches
+	  just need a simple module loader without arch specific data - those
+	  should not enable this.
+
+config MODULES_USE_RELA_ONLY
+	bool
+	help
+	  Modules only use ELF RELA relocations.  Modules with ELF REL
+	  relocations can be ignored.
+
+config MODULES_USE_REL_ONLY
+	bool
+	depends on !MODULES_USE_RELA_ONLY
+	help
+	  Modules only use ELF REL relocations.  Modules with ELF RELA
+	  relocations can be ignored.
+
 endif # MODULES
 
 config INIT_ALL_POSSIBLE
maintainer
#1 lore raw
Quoted 5 lines · David Howells

Hi Rusty, Arnd,

Here's a patch to asm-genericise the arch asm/module.h files. It allows four of them to be deleted outright. MIPS is the only weirdo of the bunch.

Good idea!

Quoted 10 lines

commit 4ef65a8a753f6fee4436dfa369e7471d3496b3ae

Author: David Howells <[email protected]>
Date:   Wed Jul 18 13:26:21 2012 +0100

Make most arch asm/module.h files use asm-generic/module.h

Use the mapping of Elf_[SPE]hdr, Elf_Sym, Elf_Dyn, Elf_Rel/Rela, ELF_R_TYPE() and ELF_R_SYM() to either the 32-bit version or the 64-bit version into asm-generic/module.h for all arches bar MIPS.

Quoted 8 lines

Also, use the generic definition mod_arch_specific where possible.

To this end, I've defined three new config bools:

(*) HAVE_MOD_ARCH_SPECIFIC

Arches define this if they don't want to use the empty generic mod_arch_specific struct.

The method I try to use for architectures overriding asm-generic definitions is to make the architecture define the same symbol, like

#ifdef CONFIG_ARM_UNWIND

struct mod_arch_specific {
	struct unwind_table *unwind[ARM_SEC_MAX];
};

#define mod_arch_specific mod_arch_specific
#endif

and then let the asm-generic version test that using

#ifndef mod_arch_specific
struct mod_arch_specific {};
#endif

Quoted 9 lines

(*) MODULES_USE_RELA_ONLY

Arches define this if their modules will only contain RELA records (and not REL records). This causes the Elf_Rel mapping not to be emitted.

(*) MODULES_USE_REL_ONLY

Arches define this if their modules will only contain REL records (and not RELA records). This causes the Elf_Rela mapping not to be emitted.

I believe all architectures have either one or the other, but never both or neither of the two, right? If so, we only need one symbol here.

We also introduced

int __weak apply_relocate(Elf_Shdr *sechdrs,
const char *strtab,
unsigned int symindex,
unsigned int relsec,
struct module *me)

{
        pr_err("module %s: REL relocation unsupported\n", me->name);
        return -ENOEXEC;
}

int __weak apply_relocate_add(Elf_Shdr *sechdrs,
const char *strtab, unsigned int symindex, unsigned int relsec, struct module *me)

{
        pr_err("module %s: RELA relocation unsupported\n", me->name);
        return -ENOEXEC;
}

some time back to provide a default so architectures no longer need to provide the apply_relocate function for both cases. If we have the Kconfig symbol you introduce, we can turn this into an nice inline function and do

#ifdef CONFIG_MODULES_USE_RELA_ONLY
static inline int __weak apply_relocate(Elf_Shdr *sechdrs,
const char *strtab, unsigned int symindex, unsigned int relsec, struct module *me)

{
        pr_err("module %s: REL relocation unsupported\n", me->name);
        return -ENOEXEC;
}

int __weak apply_relocate_add(Elf_Shdr *sechdrs,
const char *strtab, unsigned int symindex, unsigned int relsec, struct module *me);
#else
int __weak apply_relocate(Elf_Shdr *sechdrs,
const char *strtab, unsigned int symindex, unsigned int relsec, struct module *me);
static inline int __weak apply_relocate_add(Elf_Shdr *sechdrs,
const char *strtab, unsigned int symindex, unsigned int relsec, struct module *me)

{
        pr_err("module %s: RELA relocation unsupported\n", me->name);
        return -ENOEXEC;
}

#endif

and consequently kill off the remaining empty functions.

Arnd

#4 lore raw
In reply to David Howells
Quoted 10 lines · David Howells

Hi Rusty, Arnd,

Here's a patch to asm-genericise the arch asm/module.h files. It allows four of them to be deleted outright. MIPS is the only weirdo of the bunch.

The patch can also be found here:

http://git.kernel.org/?p=linux/kernel/git/dhowells/linux-modsign.git;a=shortlog;h=refs/heads/for-rusty

David

No sooner had I pushed that than Fengguang Wu found a bug in it. I've pushed a new version to the GIT tree which will find its way to gitweb at some point.

The problem was that I defined the new config options within the:

	if MODULES
	...
	endif # MODULES

section within init/Kconfig - but they're statements of fact about the arch and are not dependent on whether or not modules are configured.

Moving them to before the if-statement should have fixed that, I think.

David
---
commit 297c65c1e46cd6048f6dd8b45be68cd8ebfd438a

Author: David Howells <[email protected]>
Date:   Wed Jul 18 14:16:25 2012 +0100

Make most arch asm/module.h files use asm-generic/module.h

Use the mapping of Elf_[SPE]hdr, Elf_Sym, Elf_Dyn, Elf_Rel/Rela, ELF_R_TYPE() and ELF_R_SYM() to either the 32-bit version or the 64-bit version into asm-generic/module.h for all arches bar MIPS.

Also, use the generic definition mod_arch_specific where possible.

To this end, I've defined three new config bools:

(*) HAVE_MOD_ARCH_SPECIFIC

Arches define this if they don't want to use the empty generic mod_arch_specific struct.

(*) MODULES_USE_RELA_ONLY

Arches define this if their modules will only contain RELA records (and not REL records). This causes the Elf_Rel mapping not to be emitted.

(*) MODULES_USE_REL_ONLY

Arches define this if their modules will only contain REL records (and not RELA records). This causes the Elf_Rela mapping not to be emitted.

With this, some arch asm/module.h files can be deleted entirely and replaced with a generic-y marker in the arch Kbuild file.

arch/alpha/Kconfig +1 -0
index 3de74c9..0ff4c87 100644
@@ -17,6 +17,7 @@ config ALPHA
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	select GENERIC_SMP_IDLE_THREAD
 	select GENERIC_CMOS_UPDATE
+	select HAVE_MOD_ARCH_SPECIFIC
 	help
 	  The Alpha is a 64-bit general-purpose processor designed and
 	  marketed by the Digital Equipment Corporation of blessed memory,
arch/alpha/include/asm/module.h +2 -8
index 7b63743..9cd13b5 100644
@@ -1,19 +1,13 @@
 #ifndef _ALPHA_MODULE_H
 #define _ALPHA_MODULE_H
 
+#include <asm-generic/module.h>
+
 struct mod_arch_specific
 {
 	unsigned int gotsecindex;
 };
 
-#define Elf_Sym Elf64_Sym
-#define Elf_Shdr Elf64_Shdr
-#define Elf_Ehdr Elf64_Ehdr
-#define Elf_Phdr Elf64_Phdr
-#define Elf_Dyn Elf64_Dyn
-#define Elf_Rel Elf64_Rel
-#define Elf_Rela Elf64_Rela
-
 #define ARCH_SHF_SMALL SHF_ALPHA_GPREL
 
 #ifdef MODULE
arch/arm/Kconfig +1 -0
index a91009c..3499e79 100644
@@ -45,6 +45,7 @@ config ARM
 	select GENERIC_SMP_IDLE_THREAD
 	select KTIME_SCALAR
 	select GENERIC_CLOCKEVENTS_BROADCAST if SMP
+	select HAVE_MOD_ARCH_SPECIFIC if ARM_UNWIND
 	help
 	  The ARM series is a line of low-power-consumption RISC chip designs
 	  licensed by ARM Ltd and targeted at embedded applications and
arch/arm/include/asm/module.h +2 -6
index 6c6809f..0d3a28d 100644
@@ -1,9 +1,7 @@
 #ifndef _ASM_ARM_MODULE_H
 #define _ASM_ARM_MODULE_H
 
-#define Elf_Shdr	Elf32_Shdr
-#define Elf_Sym		Elf32_Sym
-#define Elf_Ehdr	Elf32_Ehdr
+#include <asm-generic/module.h>
 
 struct unwind_table;
 
@@ -16,13 +14,11 @@ enum {
 	ARM_SEC_DEVEXIT,
 	ARM_SEC_MAX,
 };
-#endif
 
 struct mod_arch_specific {
-#ifdef CONFIG_ARM_UNWIND
 	struct unwind_table *unwind[ARM_SEC_MAX];
-#endif
 };
+#endif
 
 /*
  * Add the ARM architecture version to the version magic string
arch/avr32/Kconfig +1 -0
index 71d38c7..01f9ecb 100644
@@ -14,6 +14,7 @@ config AVR32
 	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	select GENERIC_CLOCKEVENTS
+	select HAVE_MOD_ARCH_SPECIFIC
 	help
 	  AVR32 is a high-performance 32-bit RISC microprocessor core,
 	  designed for cost-sensitive embedded applications, with particular
arch/avr32/include/asm/module.h +2 -4
index 4514445..3f083d3 100644
@@ -1,6 +1,8 @@
 #ifndef __ASM_AVR32_MODULE_H
 #define __ASM_AVR32_MODULE_H
 
+#include <asm-generic/module.h>
+
 struct mod_arch_syminfo {
 	unsigned long got_offset;
 	int got_initialized;
@@ -17,10 +19,6 @@ struct mod_arch_specific {
 	struct mod_arch_syminfo *syminfo;
 };
 
-#define Elf_Shdr		Elf32_Shdr
-#define Elf_Sym			Elf32_Sym
-#define Elf_Ehdr		Elf32_Ehdr
-
 #define MODULE_PROC_FAMILY "AVR32v1"
 
 #define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
arch/blackfin/Kconfig +1 -0
index fef96f4..08f5ca1 100644
@@ -40,6 +40,7 @@ config BLACKFIN
 	select HAVE_NMI_WATCHDOG if NMI_WATCHDOG
 	select GENERIC_SMP_IDLE_THREAD
 	select ARCH_USES_GETTIMEOFFSET if !GENERIC_CLOCKEVENTS
+	select HAVE_MOD_ARCH_SPECIFIC
 
 config GENERIC_CSUM
 	def_bool y
arch/blackfin/include/asm/module.h +1 -3
index ed5689b..231a149 100644
@@ -7,9 +7,7 @@
 #ifndef _ASM_BFIN_MODULE_H
 #define _ASM_BFIN_MODULE_H
 
-#define Elf_Shdr        Elf32_Shdr
-#define Elf_Sym         Elf32_Sym
-#define Elf_Ehdr        Elf32_Ehdr
+#include <asm-generic/module.h>
 
 struct mod_arch_specific {
 	Elf_Shdr	*text_l1;
arch/c6x/include/asm/module.h +1 -11
index a453f97..5c7269c 100644
@@ -13,17 +13,7 @@
 #ifndef _ASM_C6X_MODULE_H
 #define _ASM_C6X_MODULE_H
 
-#define Elf_Shdr	Elf32_Shdr
-#define Elf_Sym		Elf32_Sym
-#define Elf_Ehdr	Elf32_Ehdr
-#define Elf_Addr	Elf32_Addr
-#define Elf_Word	Elf32_Word
-
-/*
- * This file contains the C6x architecture specific module code.
- */
-struct mod_arch_specific {
-};
+#include <asm-generic/module.h>
 
 struct loaded_sections {
 	unsigned int new_vaddr;
arch/cris/include/asm/Kbuild +2 -0
index 04d02a5..28b690d 100644
@@ -7,3 +7,5 @@ header-y += ethernet.h
 header-y += etraxgpio.h
 header-y += rs485.h
 header-y += sync_serial.h
+
+generic-y += module.h
arch/cris/include/asm/module.h deleted +0 -9
deleted file mode 100644
index 7ee7231..0000000
@@ -1,9 +0,0 @@
-#ifndef _ASM_CRIS_MODULE_H
-#define _ASM_CRIS_MODULE_H
-/* cris is simple */
-struct mod_arch_specific { };
-
-#define Elf_Shdr Elf32_Shdr
-#define Elf_Sym Elf32_Sym
-#define Elf_Ehdr Elf32_Ehdr
-#endif /* _ASM_CRIS_MODULE_H */
arch/frv/include/asm/module.h +1 -7
index 3d5c636..a8848f0 100644
@@ -11,13 +11,7 @@
 #ifndef _ASM_MODULE_H
 #define _ASM_MODULE_H
 
-struct mod_arch_specific
-{
-};
-
-#define Elf_Shdr	Elf32_Shdr
-#define Elf_Sym		Elf32_Sym
-#define Elf_Ehdr	Elf32_Ehdr
+#include <asm-generic/module.h>
 
 /*
  * Include the architecture version.
arch/h8300/include/asm/Kbuild +2 -0
index c68e168..871382d 100644
@@ -1 +1,3 @@
 include include/asm-generic/Kbuild.asm
+
+generic-y	+= module.h
arch/h8300/include/asm/module.h deleted +0 -11
deleted file mode 100644
index 8e46724..0000000
@@ -1,11 +0,0 @@
-#ifndef _ASM_H8300_MODULE_H
-#define _ASM_H8300_MODULE_H
-/*
- * This file contains the H8/300 architecture specific module code.
- */
-struct mod_arch_specific { };
-#define Elf_Shdr Elf32_Shdr
-#define Elf_Sym Elf32_Sym
-#define Elf_Ehdr Elf32_Ehdr
-
-#endif /* _ASM_H8/300_MODULE_H */
arch/ia64/Kconfig +1 -0
index 8186ec5..217386c 100644
@@ -39,6 +39,7 @@ config IA64
 	select ARCH_THREAD_INFO_ALLOCATOR
 	select ARCH_CLOCKSOURCE_DATA
 	select GENERIC_TIME_VSYSCALL
+	select HAVE_MOD_ARCH_SPECIFIC
 	default y
 	help
 	  The Itanium Processor Family is Intel's 64-bit successor to
arch/ia64/include/asm/module.h +2 -4
index 908eaef..dfba22a 100644
@@ -1,6 +1,8 @@
 #ifndef _ASM_IA64_MODULE_H
 #define _ASM_IA64_MODULE_H
 
+#include <asm-generic/module.h>
+
 /*
  * IA-64-specific support for kernel module loader.
  *
@@ -29,10 +31,6 @@ struct mod_arch_specific {
 	unsigned int next_got_entry;	/* index of next available got entry */
 };
 
-#define Elf_Shdr	Elf64_Shdr
-#define Elf_Sym		Elf64_Sym
-#define Elf_Ehdr	Elf64_Ehdr
-
 #define MODULE_PROC_FAMILY	"ia64"
 #define MODULE_ARCH_VERMAGIC	MODULE_PROC_FAMILY \
 	"gcc-" __stringify(__GNUC__) "." __stringify(__GNUC_MINOR__)
arch/m32r/include/asm/Kbuild +2 -0
index c68e168..871382d 100644
@@ -1 +1,3 @@
 include include/asm-generic/Kbuild.asm
+
+generic-y	+= module.h
arch/m32r/include/asm/module.h deleted +0 -10
deleted file mode 100644
index eb73ee0..0000000
@@ -1,10 +0,0 @@
-#ifndef _ASM_M32R_MODULE_H
-#define _ASM_M32R_MODULE_H
-
-struct mod_arch_specific { };
-
-#define Elf_Shdr	Elf32_Shdr
-#define Elf_Sym		Elf32_Sym
-#define Elf_Ehdr	Elf32_Ehdr
-
-#endif /* _ASM_M32R_MODULE_H */
arch/m68k/Kconfig +1 -0
index 1471201..7d2a2f3 100644
@@ -11,6 +11,7 @@ config M68K
 	select GENERIC_STRNLEN_USER if MMU
 	select FPU if MMU
 	select ARCH_USES_GETTIMEOFFSET if MMU && !COLDFIRE
+	select HAVE_MOD_ARCH_SPECIFIC
 
 config RWSEM_GENERIC_SPINLOCK
 	bool
arch/m68k/include/asm/module.h +2 -4
index edffe66..8b58fce 100644
@@ -1,6 +1,8 @@
 #ifndef _ASM_M68K_MODULE_H
 #define _ASM_M68K_MODULE_H
 
+#include <asm-generic/module.h>
+
 enum m68k_fixup_type {
 	m68k_fixup_memoffset,
 	m68k_fixup_vnode_shift,
@@ -36,8 +38,4 @@ struct module;
 extern void module_fixup(struct module *mod, struct m68k_fixup_info *start,
 			 struct m68k_fixup_info *end);
 
-#define Elf_Shdr Elf32_Shdr
-#define Elf_Sym Elf32_Sym
-#define Elf_Ehdr Elf32_Ehdr
-
 #endif /* _ASM_M68K_MODULE_H */
arch/mips/Kconfig +1 -0
index 09ab87e..cf0ff5b 100644
@@ -34,6 +34,7 @@ config MIPS
 	select BUILDTIME_EXTABLE_SORT
 	select GENERIC_CLOCKEVENTS
 	select GENERIC_CMOS_UPDATE
+	select HAVE_MOD_ARCH_SPECIFIC
 
 menu "Machine selection"
 
arch/mips/include/asm/module.h +8 -2
index 5300080..2c6a4f21 100644
@@ -34,11 +34,14 @@ typedef struct {
 } Elf64_Mips_Rela;
 
 #ifdef CONFIG_32BIT
-
 #define Elf_Shdr	Elf32_Shdr
 #define Elf_Sym		Elf32_Sym
 #define Elf_Ehdr	Elf32_Ehdr
 #define Elf_Addr	Elf32_Addr
+#define Elf_Rel		Elf32_Rel
+#define Elf_Rela	Elf32_Rela
+#define ELF_R_TYPE(X)	ELF32_R_TYPE(X)
+#define ELF_R_SYM(X)	ELF32_R_SYM(X)
 
 #define Elf_Mips_Rel	Elf32_Rel
 #define Elf_Mips_Rela	Elf32_Rela
@@ -49,11 +52,14 @@ typedef struct {
 #endif
 
 #ifdef CONFIG_64BIT
-
 #define Elf_Shdr	Elf64_Shdr
 #define Elf_Sym		Elf64_Sym
 #define Elf_Ehdr	Elf64_Ehdr
 #define Elf_Addr	Elf64_Addr
+#define Elf_Rel		Elf64_Rel
+#define Elf_Rela	Elf64_Rela
+#define ELF_R_TYPE(X)	ELF64_R_TYPE(X)
+#define ELF_R_SYM(X)	ELF64_R_SYM(X)
 
 #define Elf_Mips_Rel	Elf64_Mips_Rel
 #define Elf_Mips_Rela	Elf64_Mips_Rela
arch/mn10300/include/asm/module.h +1 -6
index 5d7057d..6571103 100644
@@ -12,12 +12,7 @@
 #ifndef _ASM_MODULE_H
 #define _ASM_MODULE_H
 
-struct mod_arch_specific {
-};
-
-#define Elf_Shdr	Elf32_Shdr
-#define Elf_Sym		Elf32_Sym
-#define Elf_Ehdr	Elf32_Ehdr
+#include <asm-generic/module.h>
 
 /*
  * Include the MN10300 architecture version.
arch/parisc/Kconfig +1 -0
index 3ff21b5..86c6ebd 100644
@@ -19,6 +19,7 @@ config PARISC
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
 	select GENERIC_SMP_IDLE_THREAD
 	select GENERIC_STRNCPY_FROM_USER
+	select HAVE_MOD_ARCH_SPECIFIC
 
 	help
 	  The PA-RISC microprocessor is designed by Hewlett-Packard and used
arch/parisc/include/asm/module.h +3 -13
index 1f41234..bab37e9 100644
@@ -1,21 +1,11 @@
 #ifndef _ASM_PARISC_MODULE_H
 #define _ASM_PARISC_MODULE_H
+
+#include <asm-generic/module.h>
+
 /*
  * This file contains the parisc architecture specific module code.
  */
-#ifdef CONFIG_64BIT
-#define Elf_Shdr Elf64_Shdr
-#define Elf_Sym Elf64_Sym
-#define Elf_Ehdr Elf64_Ehdr
-#define Elf_Addr Elf64_Addr
-#define Elf_Rela Elf64_Rela
-#else
-#define Elf_Shdr Elf32_Shdr
-#define Elf_Sym Elf32_Sym
-#define Elf_Ehdr Elf32_Ehdr
-#define Elf_Addr Elf32_Addr
-#define Elf_Rela Elf32_Rela
-#endif
 
 struct unwind_table;
 
arch/powerpc/Kconfig +1 -0
index 050cb37..8a8b0a9 100644
@@ -137,6 +137,7 @@ config PPC
 	select GENERIC_CLOCKEVENTS
 	select GENERIC_STRNCPY_FROM_USER
 	select GENERIC_STRNLEN_USER
+	select HAVE_MOD_ARCH_SPECIFIC
 
 config EARLY_PRINTK
 	bool
arch/powerpc/include/asm/module.h +1 -6
index 0192a4e..c1df590 100644
@@ -11,6 +11,7 @@
 
 #include <linux/list.h>
 #include <asm/bug.h>
+#include <asm-generic/module.h>
 
 
 #ifndef __powerpc64__
@@ -60,16 +61,10 @@ struct mod_arch_specific {
  */
 
 #ifdef __powerpc64__
-#    define Elf_Shdr	Elf64_Shdr
-#    define Elf_Sym	Elf64_Sym
-#    define Elf_Ehdr	Elf64_Ehdr
 #    ifdef MODULE
 	asm(".section .stubs,\"ax\",@nobits; .align 3; .previous");
 #    endif
 #else
-#    define Elf_Shdr	Elf32_Shdr
-#    define Elf_Sym	Elf32_Sym
-#    define Elf_Ehdr	Elf32_Ehdr
 #    ifdef MODULE
 	asm(".section .plt,\"ax\",@nobits; .align 3; .previous");
 	asm(".section .init.plt,\"ax\",@nobits; .align 3; .previous");
arch/s390/Kconfig +1 -0
index a39b469..61fb321 100644
@@ -121,6 +121,7 @@ config S390
 	select GENERIC_TIME_VSYSCALL
 	select GENERIC_CLOCKEVENTS
 	select KTIME_SCALAR if 32BIT
+	select HAVE_MOD_ARCH_SPECIFIC
 
 config SCHED_OMIT_FRAME_POINTER
 	def_bool y
arch/s390/include/asm/module.h +3 -15
index f0b6b26..df1f861 100644
@@ -1,5 +1,8 @@
 #ifndef _ASM_S390_MODULE_H
 #define _ASM_S390_MODULE_H
+
+#include <asm-generic/module.h>
+
 /*
  * This file contains the s390 architecture specific module code.
  */
@@ -28,19 +31,4 @@ struct mod_arch_specific
 	struct mod_arch_syminfo *syminfo;
 };
 
-#ifdef CONFIG_64BIT
-#define ElfW(x) Elf64_ ## x
-#define ELFW(x) ELF64_ ## x
-#else
-#define ElfW(x) Elf32_ ## x
-#define ELFW(x) ELF32_ ## x
-#endif
-
-#define Elf_Addr ElfW(Addr)
-#define Elf_Rela ElfW(Rela)
-#define Elf_Shdr ElfW(Shdr)
-#define Elf_Sym ElfW(Sym)
-#define Elf_Ehdr ElfW(Ehdr)
-#define ELF_R_SYM ELFW(R_SYM)
-#define ELF_R_TYPE ELFW(R_TYPE)
 #endif /* _ASM_S390_MODULE_H */
arch/score/Kconfig +1 -0
index ba0f412..ceeeb5a 100644
@@ -10,6 +10,7 @@ config SCORE
        select ARCH_DISCARD_MEMBLOCK
        select GENERIC_CPU_DEVICES
        select GENERIC_CLOCKEVENTS
+       select HAVE_MOD_ARCH_SPECIFIC
 
 choice
 	prompt "System type"
arch/score/include/asm/module.h +1 -5
index f0b5dc0..abf395b 100644
@@ -3,6 +3,7 @@
 
 #include <linux/list.h>
 #include <asm/uaccess.h>
+#include <asm-generic/module.h>
 
 struct mod_arch_specific {
 	/* Data Bus Error exception tables */
@@ -13,11 +14,6 @@ struct mod_arch_specific {
 
 typedef uint8_t Elf64_Byte;		/* Type for a 8-bit quantity. */
 
-#define Elf_Shdr	Elf32_Shdr
-#define Elf_Sym		Elf32_Sym
-#define Elf_Ehdr	Elf32_Ehdr
-#define Elf_Addr	Elf32_Addr
-
 /* Given an address, look for it in the exception tables. */
 #ifdef CONFIG_MODULES
 const struct exception_table_entry *search_module_dbetables(unsigned long addr);
arch/sh/Kconfig +1 -0
index 31d9db7..23de034 100644
@@ -34,6 +34,7 @@ config SUPERH
 	select GENERIC_CMOS_UPDATE if SH_SH03 || SH_DREAMCAST
 	select GENERIC_STRNCPY_FROM_USER
 	select GENERIC_STRNLEN_USER
+	select HAVE_MOD_ARCH_SPECIFIC if DWARF_UNWINDER
 	help
 	  The SuperH is a RISC processor targeted for use in embedded systems
 	  and consumer electronics; it was also used in the Sega Dreamcast
arch/sh/include/asm/module.h +3 -11
index b7927de..81300d8b 100644
@@ -1,21 +1,13 @@
 #ifndef _ASM_SH_MODULE_H
 #define _ASM_SH_MODULE_H
 
-struct mod_arch_specific {
+#include <asm-generic/module.h>
+
 #ifdef CONFIG_DWARF_UNWINDER
+struct mod_arch_specific {
 	struct list_head fde_list;
 	struct list_head cie_list;
-#endif
 };
-
-#ifdef CONFIG_64BIT
-#define Elf_Shdr Elf64_Shdr
-#define Elf_Sym Elf64_Sym
-#define Elf_Ehdr Elf64_Ehdr
-#else
-#define Elf_Shdr Elf32_Shdr
-#define Elf_Sym Elf32_Sym
-#define Elf_Ehdr Elf32_Ehdr
 #endif
 
 #ifdef CONFIG_CPU_LITTLE_ENDIAN
arch/sparc/Kconfig +1 -0
index e74ff13..f5cecb3 100644
@@ -36,6 +36,7 @@ config SPARC
 	select GENERIC_CLOCKEVENTS
 	select GENERIC_STRNCPY_FROM_USER
 	select GENERIC_STRNLEN_USER
+	select MODULES_USE_RELA_ONLY
 
 config SPARC32
 	def_bool !64BIT
arch/sparc/include/asm/Kbuild +1 -0
index 67f83e0..fbe1cb5 100644
@@ -21,4 +21,5 @@ generic-y += div64.h
 generic-y += local64.h
 generic-y += irq_regs.h
 generic-y += local.h
+generic-y += module.h
 generic-y += word-at-a-time.h
arch/sparc/include/asm/module.h deleted +0 -24
deleted file mode 100644
index ff8e02d..0000000
@@ -1,24 +0,0 @@
-#ifndef __SPARC_MODULE_H
-#define __SPARC_MODULE_H
-struct mod_arch_specific { };
-
-/*
- * Use some preprocessor magic to define the correct symbol
- * for sparc32 and sparc64.
- * Elf_Addr becomes Elf32_Addr for sparc32 and Elf64_Addr for sparc64
- */
-#define ___ELF(a, b, c) a##b##c
-#define __ELF(a, b, c)  ___ELF(a, b, c)
-#define  _Elf(t)        __ELF(Elf, CONFIG_BITS, t)
-#define  _ELF(t)        __ELF(ELF, CONFIG_BITS, t)
-
-#define Elf_Shdr     _Elf(_Shdr)
-#define Elf_Sym      _Elf(_Sym)
-#define Elf_Ehdr     _Elf(_Ehdr)
-#define Elf_Rela     _Elf(_Rela)
-#define Elf_Addr     _Elf(_Addr)
-
-#define ELF_R_SYM    _ELF(_R_SYM)
-#define ELF_R_TYPE   _ELF(_R_TYPE)
-
-#endif /* __SPARC_MODULE_H */
arch/x86/Kconfig +2 -0
index c70684f..3cebb96 100644
@@ -95,6 +95,8 @@ config X86
 	select KTIME_SCALAR if X86_32
 	select GENERIC_STRNCPY_FROM_USER
 	select GENERIC_STRNLEN_USER
+	select MODULES_USE_REL_ONLY if X86_32
+	select MODULES_USE_RELA_ONLY if X86_64
 
 config INSTRUCTION_DECODER
 	def_bool (KPROBES || PERF_EVENTS || UPROBES)
arch/xtensa/include/asm/module.h +1 -8
index d9b34be..488b40c 100644
@@ -13,15 +13,8 @@
 #ifndef _XTENSA_MODULE_H
 #define _XTENSA_MODULE_H
 
-struct mod_arch_specific
-{
-	/* No special elements, yet. */
-};
-
 #define MODULE_ARCH_VERMAGIC "xtensa-" __stringify(XCHAL_CORE_ID) " "
 
-#define Elf_Shdr Elf32_Shdr
-#define Elf_Sym Elf32_Sym
-#define Elf_Ehdr Elf32_Ehdr
+#include <asm-generic/module.h>
 
 #endif	/* _XTENSA_MODULE_H */
include/asm-generic/module.h +33 -7
index ed5b44d..479feb0 100644
@@ -5,18 +5,44 @@
  * Many architectures just need a simple module
  * loader without arch specific data.
  */
+#ifndef CONFIG_HAVE_MOD_ARCH_SPECIFIC
 struct mod_arch_specific
 {
 };
+#endif
 
 #ifdef CONFIG_64BIT
-#define Elf_Shdr Elf64_Shdr
-#define Elf_Sym Elf64_Sym
-#define Elf_Ehdr Elf64_Ehdr
-#else
-#define Elf_Shdr Elf32_Shdr
-#define Elf_Sym Elf32_Sym
-#define Elf_Ehdr Elf32_Ehdr
+#define Elf_Shdr	Elf64_Shdr
+#define Elf_Phdr	Elf64_Phdr
+#define Elf_Sym		Elf64_Sym
+#define Elf_Dyn		Elf64_Dyn
+#define Elf_Ehdr	Elf64_Ehdr
+#define Elf_Addr	Elf64_Addr
+#ifndef CONFIG_MODULES_USE_RELA_ONLY
+#define Elf_Rel		Elf64_Rel
+#endif
+#ifndef CONFIG_MODULES_USE_REL_ONLY
+#define Elf_Rela	Elf64_Rela
+#endif
+#define ELF_R_TYPE(X)	ELF64_R_TYPE(X)
+#define ELF_R_SYM(X)	ELF64_R_SYM(X)
+
+#else /* CONFIG_64BIT */
+
+#define Elf_Shdr	Elf32_Shdr
+#define Elf_Phdr	Elf32_Phdr
+#define Elf_Sym		Elf32_Sym
+#define Elf_Dyn		Elf32_Dyn
+#define Elf_Ehdr	Elf32_Ehdr
+#define Elf_Addr	Elf32_Addr
+#ifndef CONFIG_MODULES_USE_RELA_ONLY
+#define Elf_Rel		Elf32_Rel
+#endif
+#ifndef CONFIG_MODULES_USE_REL_ONLY
+#define Elf_Rela	Elf32_Rela
+#endif
+#define ELF_R_TYPE(X)	ELF32_R_TYPE(X)
+#define ELF_R_SYM(X)	ELF32_R_SYM(X)
 #endif
 
 #endif /* __ASM_GENERIC_MODULE_H */
init/Kconfig +20 -0
index d07dcf9..1c4e1e6 100644
@@ -1521,6 +1521,26 @@ menuconfig MODULES
 
 	  If unsure, say Y.
 
+config HAVE_MOD_ARCH_SPECIFIC
+	bool
+	help
+	  The arch uses struct mod_arch_specific to store data.  Many arches
+	  just need a simple module loader without arch specific data - those
+	  should not enable this.
+
+config MODULES_USE_RELA_ONLY
+	bool
+	help
+	  Modules only use ELF RELA relocations.  Modules with ELF REL
+	  relocations can be ignored.
+
+config MODULES_USE_REL_ONLY
+	bool
+	depends on !MODULES_USE_RELA_ONLY
+	help
+	  Modules only use ELF REL relocations.  Modules with ELF RELA
+	  relocations can be ignored.
+
 if MODULES
 
 config MODULE_FORCE_LOAD
#2 lore raw
In reply to Arnd Bergmann
Quoted 7 lines · Arnd Bergmann

The method I try to use for architectures overriding asm-generic definitions is to make the architecture define the same symbol, like

#ifdef CONFIG_ARM_UNWIND

struct mod_arch_specific {
	struct unwind_table *unwind[ARM_SEC_MAX];
};
Quoted 8 lines

#define mod_arch_specific mod_arch_specific
#endif

and then let the asm-generic version test that using

#ifndef mod_arch_specific
struct mod_arch_specific {};
#endif

Ewww. That's even ickier.

Quoted 2 lines

I believe all architectures have either one or the other, but never both or neither of the two, right? If so, we only need one symbol here.

That's probably the case, but I don't know which it is for which arch, or whether it has changed during the lifetime of an arch, requiring both to be supported for that arch.

Quoted 7 lines

some time back to provide a default so architectures no longer need to provide the apply_relocate function for both cases. If we have the Kconfig symbol you introduce, we can turn this into an nice inline function and do

#ifdef CONFIG_MODULES_USE_RELA_ONLY
static inline int __weak apply_relocate(Elf_Shdr *sechdrs,

You don't then need the __weak attributes.

Quoted 1 line

and consequently kill off the remaining empty functions.

:-)

David

#5 lore raw
In reply to David Howells
Quoted 16 lines · David Howells
Quoted 10 lines · David Howells

Hi Rusty, Arnd,

Here's a patch to asm-genericise the arch asm/module.h files. It allows four of them to be deleted outright. MIPS is the only weirdo of the bunch.

The patch can also be found here:

http://git.kernel.org/?p=linux/kernel/git/dhowells/linux-modsign.git;a=shortlog;h=refs/heads/for-rusty

David

No sooner had I pushed that than Fengguang Wu found a bug in it. I've pushed a new version to the GIT tree which will find its way to gitweb at some point.

Quoted 8 lines

The problem was that I defined the new config options within the:

	if MODULES
	...
	endif # MODULES

section within init/Kconfig - but they're statements of fact about the arch and are not dependent on whether or not modules are configured.

Stuff like this is better situated in arch/Kconfig.
This is not related to the init part but to the configuration of the architecture.
For historical reasons we used to use init/Kconfig for this in the past - but now that we have arch/Kconfig let's use it.

Sam

#9 lore raw
In reply to David Howells
Quoted 13 lines · On Wednesday 18 July 2012 08:46:59 David Howells wrote:
arch/blackfin/Kconfig +1 -0
@@ -40,6 +40,7 @@ config BLACKFIN
 	select HAVE_NMI_WATCHDOG if NMI_WATCHDOG
 	select GENERIC_SMP_IDLE_THREAD
 	select ARCH_USES_GETTIMEOFFSET if !GENERIC_CLOCKEVENTS
+	select HAVE_MOD_ARCH_SPECIFIC
 
 config GENERIC_CSUM
 	def_bool y

arch/blackfin/include/asm/module.h line 13

Quoted 10 lines
arch/blackfin/include/asm/module.h +1 -3
@@ -7,9 +7,7 @@
 #ifndef _ASM_BFIN_MODULE_H
 #define _ASM_BFIN_MODULE_H
 
-#define Elf_Shdr        Elf32_Shdr
-#define Elf_Sym         Elf32_Sym
-#define Elf_Ehdr        Elf32_Ehdr
+#include <asm-generic/module.h>
 
 struct mod_arch_specific {
 	Elf_Shdr	*text_l1;

looks sane to me
-mike

#3 lore raw
In reply to Arnd Bergmann
Quoted 5 lines · Arnd Bergmann
Quoted 5 lines

(*) MODULES_USE_RELA_ONLY

Arches define this if their modules will only contain RELA records (and not REL records). This causes the Elf_Rel mapping not to be emitted.

Quoted 7 lines
Quoted 4 lines

(*) MODULES_USE_REL_ONLY

Arches define this if their modules will only contain REL records (and not RELA records). This causes the Elf_Rela mapping not to be emitted.

I believe all architectures have either one or the other, but never both or neither of the two, right? If so, we only need one symbol here.

How sweet life would be without the SGI designed ELF NABI. For the purposes of kernel modules that means 64-bit MIPS kernels. The 64-bit ELF spec [1] allows both REL and RELA. I believe that GNU tools only emit rela relocations and in the hope that things are going to stay like this I'd like 64-bit MIPS to be treated as RELA-only. However we're in the hand of the tools guy here - they always could make use of the rope provided.

32-bit MIPS uses REL only.

Ralf

[1] https://www.linux-mips.org/pub/linux/mips/doc/ABI/elf64-2.4.pdf

#6 lore raw
In reply to David Howells
Quoted 7 lines · David Howells
arch/sh/include/asm/module.h +0 -0
index b7927de..81300d8b 100644
@@ -1,21 +1,13 @@
 #ifndef _ASM_SH_MODULE_H
 #define _ASM_SH_MODULE_H

arch/sh/include/asm/module.h line 10

Quoted 10 lines
arch/sh/include/asm/module.h +3 -2
 
-struct mod_arch_specific {
+#include <asm-generic/module.h>
+
 #ifdef CONFIG_DWARF_UNWINDER
+struct mod_arch_specific {
 	struct list_head fde_list;
 	struct list_head cie_list;
-#endif
 };

Hmm, this means we get two definitions if CONFIG_DWARF_UNWINDER?

Seems like a useful effort. Fiddly though.

Cheers,
Rusty.

#7 lore raw
Quoted 21 lines · Rusty Russell
Quoted 7 lines · David Howells
arch/sh/include/asm/module.h +0 -0
index b7927de..81300d8b 100644
@@ -1,21 +1,13 @@
 #ifndef _ASM_SH_MODULE_H
 #define _ASM_SH_MODULE_H

arch/sh/include/asm/module.h line 10

Quoted 10 lines
arch/sh/include/asm/module.h +3 -2
 
-struct mod_arch_specific {
+#include <asm-generic/module.h>
+
 #ifdef CONFIG_DWARF_UNWINDER
+struct mod_arch_specific {
 	struct list_head fde_list;
 	struct list_head cie_list;
-#endif
 };

Hmm, this means we get two definitions if CONFIG_DWARF_UNWINDER?

Quoted 2 lines

Seems like a useful effort. Fiddly though.

The DWARF_UNWINDER check is already done in the Kconfig part of this patch, so the ifdef here simply seems like a remnant that should have been deleted (as the endif was) -- similar to the ARM unwinder case.

#8 lore raw
Quoted 3 lines · Paul Mundt

The DWARF_UNWINDER check is already done in the Kconfig part of this patch, so the ifdef here simply seems like a remnant that should have been deleted (as the endif was) -- similar to the ARM unwinder case.

No, you still need the #ifdef here.

In the sh/Kconfig you can see this:

select HAVE_MOD_ARCH_SPECIFIC if DWARF_UNWINDER

This says that the arch defines struct mod_arch_specific if CONFIG_DWARF_UNWINDER is enabled.

If it is not enabled, asm-generic/module.h will emit its own definition of struct mod_arch_specific which will clash with the one in arch/sh/include/asm/module.h if the latter is not hidden by the preprocessor.

Note that the ARM unwinder case is the same. In the Kconfig you have:

select HAVE_MOD_ARCH_SPECIFIC if ARM_UNWIND

and in ARM's module.h you have:

	#ifdef CONFIG_ARM_UNWIND
	enum {
		ARM_SEC_INIT,
		ARM_SEC_DEVINIT,
		ARM_SEC_CORE,
		ARM_SEC_EXIT,
		ARM_SEC_DEVEXIT,
		ARM_SEC_MAX,
	};

	struct mod_arch_specific {
		struct unwind_table *unwind[ARM_SEC_MAX];
	};
	#endif

(Note I'm quoting from the latest version of the patch which got substantially reworked).

David