cross-architecture ELF clean up
Subsystems (14)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 cross-architecture ELF clean up
This patch cleans up the ELF headers and their users. It does several related things:
1. split linux/elf.h into pieces
This splits linux/elf.h into several pieces:
linux/elf.h - still the common elf header,
functionally unchanged
linux/elf-const.h - ELF constants, includable by asm code
linux/elf-decl.h - ELF type declarations, without definitions
linux/elf-defn.h - ELF type definitions
This makes it easier to use the ELF headers in various contexts such as assembler and boot code, without pulling in a lot of other unneeded headers.
2. add asm-*/elf-defines.h, and asm-generic/elf(32|64)-defines.h
Architectures define some arch-specific ELF definitions.
The most basic of these is whether they want to use a 32 or 64 bit ELF class, and their associated types. These common definitions have been put into asm-generic/elf(32|64)-defines.h, so that a simple architecture can simply include the appropriate generic header in its asm/elf-defines.h.
The effect of including asm/elf-defines.h in any code is that you get the architecture's preferred ELF_CLASS defined, and the generic types (Elf_Ehdr, Elf_Phdr, etc) are defined to the appropriate class types (Elf32_Ehdr, etc).
For most architectures this transition was straightforward, but some need special handling:
mips, powerpc, s390 allow both 32 and 64 bit operation. powerpc's logic for this was particularly complex, so I just copied the code outright into asm-powerpc/elf-defines.h and hope that it's right.
powerpc also appears to have its own duplicate copy of elf.h in arch/powerpc/boot/elf.h; presumably because the standard elf.h brings in too much. Update it to just linux/elf-defn.h, which should be fine.
x86-64 does some mucking about with ELF_CLASS in order to make fs/binfmt_elf also handle 32-bit binaries. This is why asm-generic/elf(32|64)_defines.h only conditionally define ELF_CLASS.
3. Narrow elf.h includes.
Some headers, such as linux/modules.h, are included by a large proportion of the kernel code, and end up including linux/elf.h which in turn includes a lot of other headers. In practice, linux/modules.h only wants a couple of ELF type declarations, and so can make do with asm/elf-defines.h, which includes very little.
A side effect of this is that some files were depending on linux/elf.h's implicit includes, and so needed to have some extra headers for the definitions they require.
Unfortunately I don't have the means to cross-build all the architectures, but I did an cross builds of i386, x86-64, sparc64 and powerpc and fixed up what I found.
--- arch/frv/kernel/process.c | 2 arch/i386/kernel/smpcommon.c | 1 arch/i386/kernel/vmi.c | 1 arch/powerpc/boot/elf.h | 145 --------- arch/powerpc/kernel/prom_init.c | 1 arch/powerpc/platforms/cell/io-workarounds.c | 1 arch/powerpc/platforms/cell/spufs/context.c | 1 arch/powerpc/platforms/pseries/eeh.c | 1 arch/powerpc/platforms/pseries/eeh_event.c | 1 arch/powerpc/platforms/pseries/hotplug-cpu.c | 1 arch/powerpc/platforms/pseries/iommu.c | 1 drivers/ps3/sys-manager.c | 1 include/asm-alpha/elf-defines.h | 1 include/asm-alpha/elf.h | 2 include/asm-alpha/module.h | 8 include/asm-arm/elf-defines.h | 1 include/asm-arm/elf.h | 2 include/asm-arm/module.h | 4 include/asm-arm26/elf-defines.h | 1 include/asm-arm26/elf.h | 2 include/asm-avr32/elf-defines.h | 1 include/asm-avr32/elf.h | 2 include/asm-avr32/module.h | 4 include/asm-blackfin/elf-defines.h | 1 include/asm-blackfin/elf.h | 2 include/asm-blackfin/module.h | 5 include/asm-cris/elf-defines.h | 1 include/asm-cris/elf.h | 2 include/asm-cris/module.h | 4 include/asm-frv/elf-defines.h | 1 include/asm-frv/elf.h | 2 include/asm-frv/module.h | 4 include/asm-generic/Kbuild | 2 include/asm-generic/Kbuild.asm | 1 include/asm-generic/elf32-defines.h | 21 + include/asm-generic/elf64-defines.h | 21 + include/asm-h8300/elf-defines.h | 1 include/asm-h8300/elf.h | 2 include/asm-h8300/module.h | 5 include/asm-i386/elf-defines.h | 24 + include/asm-i386/elf.h | 22 - include/asm-i386/module.h | 4 include/asm-ia64/elf-defines.h | 1 include/asm-ia64/elf.h | 2 include/asm-ia64/module.h | 4 include/asm-m32r/elf-defines.h | 1 include/asm-m32r/elf.h | 2 include/asm-m32r/module.h | 4 include/asm-m68k/elf-defines.h | 1 include/asm-m68k/elf.h | 2 include/asm-m68k/module.h | 5 include/asm-m68knommu/elf-defines.h | 1 include/asm-m68knommu/elf.h | 2 include/asm-mips/elf-defines.h | 6 include/asm-mips/elf.h | 15 include/asm-mips/module.h | 11 include/asm-parisc/elf-defines.h | 5 include/asm-parisc/elf.h | 6 include/asm-parisc/module.h | 14 include/asm-powerpc/elf-defines.h | 32 ++ include/asm-powerpc/elf.h | 23 - include/asm-powerpc/module.h | 7 include/asm-s390/elf-defines.h | 5 include/asm-s390/elf.h | 6 include/asm-s390/module.h | 6 include/asm-sh/elf-defines.h | 1 include/asm-sh/elf.h | 2 include/asm-sh/module.h | 4 include/asm-sh64/elf-defines.h | 1 include/asm-sh64/elf.h | 2 include/asm-sh64/module.h | 4 include/asm-sparc/elf-defines.h | 1 include/asm-sparc/elf.h | 2 include/asm-sparc/module.h | 4 include/asm-sparc64/elf-defines.h | 1 include/asm-sparc64/elf.h | 2 include/asm-sparc64/module.h | 4 include/asm-v850/elf-defines.h | 1 include/asm-v850/elf.h | 2 include/asm-v850/module.h | 4 include/asm-x86_64/elf-defines.h | 1 include/asm-x86_64/elf.h | 2 include/asm-x86_64/module.h | 4 include/asm-xtensa/elf-defines.h | 1 include/asm-xtensa/elf.h | 2 include/asm-xtensa/module.h | 4 include/linux/Kbuild | 4 include/linux/audit.h | 2 include/linux/elf-const.h | 222 ++++++++++++++ include/linux/elf-decl.h | 48 +++ include/linux/elf-defn.h | 174 +++++++++++ include/linux/elf-em.h | 51 --- include/linux/elf.h | 399 +------------------------- include/linux/elfnote.h | 30 + include/linux/module.h | 1 kernel/sysctl.c | 1 lib/bug.c | 1 97 files changed, 692 insertions(+), 761 deletions(-)
===================================================================
arch/frv/kernel/process.c +1 -1
@@ -309,7 +309,7 @@ unsigned long thread_saved_pc(struct tasreturn tsk->thread.pc; } -int elf_check_arch (const struct elf32_hdr *hdr) +int elf_check_arch (const Elf32_Ehdr *hdr) {unsigned long hsr0 =__get_HSR (0 );unsigned long psr =__get_PSR ();
===================================================================
arch/i386/kernel/smpcommon.c +1 -0
@@ -3,6 +3,7 @@*/ #include <linux/module.h> #include <asm/smp.h> +#include <asm/desc.h> DEFINE_PER_CPU(unsigned long, this_cpu_off);EXPORT_PER_CPU_SYMBOL (this_cpu_off);
===================================================================
arch/i386/kernel/vmi.c +1 -0
@@ -37,6 +37,7 @@#include <asm/timer.h> #include <asm/vmi_time.h> #include <asm/kmap_types.h> +#include <asm/desc.h> /* Convenient for calling VMI functions indirectly in the ROM */ typedef u32 __attribute__((regparm(1))) (VROMFUNC)(void);
===================================================================
arch/powerpc/boot/elf.h +1 -144
151 lines not on this page · raw message
===================================================================
arch/powerpc/kernel/prom_init.c +1 -0
@@ -28,6 +28,7 @@#include <linux/delay.h> #include <linux/initrd.h> #include <linux/bitops.h> +#include <linux/elf.h> #include <asm/prom.h> #include <asm/rtas.h> #include <asm/page.h>
===================================================================
arch/powerpc/platforms/cell/io-workarounds.c +1 -0
@@ -9,6 +9,7 @@#undef DEBUG#include <linux/kernel.h> +#include <linux/sched.h> #include <linux/mm.h> #include <linux/pci.h> #include <asm/io.h>
===================================================================
arch/powerpc/platforms/cell/spufs/context.c +1 -0
@@ -23,6 +23,7 @@#include <linux/fs.h> #include <linux/mm.h> #include <linux/slab.h> +#include <linux/sched.h> #include <asm/spu.h> #include <asm/spu_csa.h> #include "spufs.h"
===================================================================
arch/powerpc/platforms/pseries/eeh.c +1 -0
@@ -23,6 +23,7 @@#include <linux/pci.h> #include <linux/proc_fs.h> #include <linux/rbtree.h> +#include <linux/sched.h> #include <linux/seq_file.h> #include <linux/spinlock.h> #include <asm/atomic.h>
===================================================================
arch/powerpc/platforms/pseries/eeh_event.c +1 -0
@@ -20,6 +20,7 @@#include <linux/delay.h> #include <linux/list.h> +#include <linux/sched.h> #include <linux/mutex.h> #include <linux/pci.h> #include <linux/workqueue.h>
===================================================================
arch/powerpc/platforms/pseries/hotplug-cpu.c +1 -0
@@ -20,6 +20,7 @@#include <linux/kernel.h> #include <linux/delay.h> +#include <linux/sched.h> #include <linux/cpu.h> #include <asm/system.h> #include <asm/prom.h>
===================================================================
arch/powerpc/platforms/pseries/iommu.c +1 -0
@@ -28,6 +28,7 @@#include <linux/types.h> #include <linux/slab.h> #include <linux/mm.h> +#include <linux/sched.h> #include <linux/spinlock.h> #include <linux/string.h> #include <linux/pci.h>
===================================================================
drivers/ps3/sys-manager.c +1 -0
@@ -21,6 +21,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/workqueue.h> +#include <linux/sched.h> #include <linux/reboot.h> #include <asm/firmware.h>
===================================================================
include/asm-alpha/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf64-defines.h>
===================================================================
include/asm-alpha/elf.h +1 -1
@@ -77,7 +77,7 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N/* * These are used to set parameters in the core dumps. */ -#define ELF_CLASS ELFCLASS64 +#include <asm/elf-defines.h> #define ELF_DATA ELFDATA2LSB#define ELF_ARCH EM_ALPHA
===================================================================
include/asm-alpha/module.h +1 -7
@@ -6,13 +6,7 @@ struct mod_arch_specificunsigned 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 +#include <asm/elf-defines.h> #define ARCH_SHF_SMALL SHF_ALPHA_GPREL
===================================================================
include/asm-arm/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf32-defines.h>
===================================================================
include/asm-arm/elf.h +1 -1
@@ -31,7 +31,7 @@ typedef struct user_fp elf_fpregset_t;/* * These are used to set parameters in the core dumps. */ -#define ELF_CLASS ELFCLASS32 +#include <asm/elf-defines.h> #ifdef __ARMEB__#define ELF_DATA ELFDATA2MSB#else
===================================================================
include/asm-arm/module.h +1 -3
@@ -6,9 +6,7 @@ struct mod_arch_specificint foo; }; -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Ehdr Elf32_Ehdr +#include <asm/elf-defines.h> /* * Include the ARM architecture version.
===================================================================
include/asm-arm26/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf32-defines.h>
===================================================================
include/asm-arm26/elf.h +1 -1
@@ -35,7 +35,7 @@ typedef struct { void *null; } elf_fpreg/* * These are used to set parameters in the core dumps. */ -#define ELF_CLASS ELFCLASS32 +#include <asm/elf-defines.h> #define ELF_DATA ELFDATA2LSB#define ELF_ARCH EM_ARM
===================================================================
include/asm-avr32/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf32-defines.h>
===================================================================
include/asm-avr32/elf.h +1 -1
@@ -69,7 +69,7 @@ typedef struct user_fpu_struct elf_fpreg/* * These are used to set parameters in the core dumps. */ -#define ELF_CLASS ELFCLASS32 +#include <asm/elf-defines.h> #ifdef __LITTLE_ENDIAN__#define ELF_DATA ELFDATA2LSB#else
===================================================================
include/asm-avr32/module.h +1 -3
@@ -17,9 +17,7 @@ struct mod_arch_specific {struct mod_arch_syminfo *syminfo; }; -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Ehdr Elf32_Ehdr +#include <asm/elf-defines.h> #define MODULE_PROC_FAMILY "AVR32v1"
===================================================================
include/asm-blackfin/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf32-defines.h>
===================================================================
include/asm-blackfin/elf.h +1 -1
@@ -35,7 +35,7 @@ typedef struct user_bfinfp_struct elf_fp/* * These are used to set parameters in the core dumps. */ -#define ELF_CLASS ELFCLASS32 +#include <asm/elf-defines.h> #define ELF_DATA ELFDATA2LSB#define ELF_ARCH EM_BLACKFIN
===================================================================
include/asm-blackfin/module.h +2 -3
@@ -3,9 +3,8 @@#define MODULE_SYMBOL_PREFIX "_" -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Ehdr Elf32_Ehdr +#include <asm/elf-defines.h> +#define FLG_CODE_IN_L1 0x10#define FLG_DATA_IN_L1 0x20
===================================================================
include/asm-cris/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf32-defines.h>
===================================================================
include/asm-cris/elf.h +1 -1
@@ -41,7 +41,7 @@ typedef unsigned long elf_fpregset_t;/* * These are used to set parameters in the core dumps. */ -#define ELF_CLASS ELFCLASS32 +#include <asm/elf-defines.h> #define ELF_DATA ELFDATA2LSB#define ELF_ARCH EM_CRIS
===================================================================
include/asm-cris/module.h +1 -3
@@ -3,7 +3,5 @@/* cris is simple */ struct mod_arch_specific { }; -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Ehdr Elf32_Ehdr +#include <asm/elf-defines.h> #endif /* _ASM_CRIS_MODULE_H */
===================================================================
include/asm-frv/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf32-defines.h>
===================================================================
include/asm-frv/elf.h +1 -1
@@ -77,7 +77,7 @@ extern int elf_check_arch(const struct e/* * These are used to set parameters in the core dumps. */ -#define ELF_CLASS ELFCLASS32 +#include <asm/elf-defines.h> #define ELF_DATA ELFDATA2MSB#define ELF_ARCH EM_FRV
===================================================================
include/asm-frv/module.h +1 -3
@@ -15,9 +15,7 @@ struct mod_arch_specific { }; -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Ehdr Elf32_Ehdr +#include <asm/elf-defines.h> /* * Include the architecture version.
===================================================================
include/asm-generic/Kbuild +2 -0
@@ -1,3 +1,5 @@ header-y += errno-base.h +header-y += elf32-defines.h +header-y += elf64-defines.h header-y += errno-base.h header-y += errno.h header-y += fcntl.h
===================================================================
include/asm-generic/Kbuild.asm +1 -0
@@ -1,6 +1,7 @@ unifdef-y += a.out.h unifdef-y += a.out.h unifdef-y += auxvec.h unifdef-y += byteorder.h +unifdef-y += elf-defines.h unifdef-y += errno.h unifdef-y += fcntl.h unifdef-y += ioctl.h
===================================================================
include/asm-generic/elf32-defines.h new file +21 -0
@@ -0,0 +1,21 @@ +#ifndef __ASM_GENERIC_ELF32_DEFINES_H +#define __ASM_GENERIC_ELF32_DEFINES_H + +#include <linux/elf-decl.h> +#include <linux/elf-const.h> + +#ifndef ELF_CLASS +#define ELF_CLASS ELFCLASS32 +#endif + +typedef Elf32_Ehdr Elf_Ehdr ; +typedef Elf32_Phdr Elf_Phdr ; +typedef Elf32_Shdr Elf_Shdr ; +typedef Elf32_Sym Elf_Sym ; +typedef Elf32_Dyn Elf_Dyn ; +typedef Elf32_Rel Elf_Rel ; +typedef Elf32_Rela Elf_Rela ; + +typedef Elf32_Addr Elf_Addr ; + +#endif /* __ASM_GENERIC_ELF32_DEFINES_H */
===================================================================
include/asm-generic/elf64-defines.h new file +21 -0
@@ -0,0 +1,21 @@ +#ifndef __ASM_GENERIC_ELF64_DEFINES_H +#define __ASM_GENERIC_ELF64_DEFINES_H + +#include <linux/elf-decl.h> +#include <linux/elf-const.h> + +#ifndef ELF_CLASS +#define ELF_CLASS ELFCLASS64 +#endif + +typedef Elf64_Ehdr Elf_Ehdr ; +typedef Elf64_Phdr Elf_Phdr ; +typedef Elf64_Shdr Elf_Shdr ; +typedef Elf64_Sym Elf_Sym ; +typedef Elf64_Dyn Elf_Dyn ; +typedef Elf64_Rel Elf_Rel ; +typedef Elf64_Rela Elf_Rela ; + +typedef Elf64_Addr Elf_Addr ; + +#endif /* __ASM_GENERIC_ELF64_DEFINES_H */
===================================================================
include/asm-h8300/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf32-defines.h>
===================================================================
include/asm-h8300/elf.h +1 -1
@@ -22,7 +22,7 @@ typedef unsigned long elf_fpregset_t;/* * These are used to set parameters in the core dumps. */ -#define ELF_CLASS ELFCLASS32 +#include <asm/elf-defines.h> #define ELF_DATA ELFDATA2MSB#define ELF_ARCH EM_H8_300#if defined(__H8300H__)
===================================================================
include/asm-h8300/module.h +2 -3
@@ -4,9 +4,8 @@* 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 + +#include <asm/elf-defines.h> #define MODULE_SYMBOL_PREFIX "_"
===================================================================
include/asm-i386/elf-defines.h new file +24 -0
@@ -0,0 +1,24 @@ +#ifndef __ASM_I386_ELF_DEFINES_H +#define __ASM_I386_ELF_DEFINES_H + +#define R_386_NONE 0 +#define R_386_32 1 +#define R_386_PC32 2 +#define R_386_GOT32 3 +#define R_386_PLT32 4 +#define R_386_COPY 5 +#define R_386_GLOB_DAT 6 +#define R_386_JMP_SLOT 7 +#define R_386_RELATIVE 8 +#define R_386_GOTOFF 9 +#define R_386_GOTPC 10 +#define R_386_NUM 11 + +/* +* These are used to set parameters in the core dumps. +*/ +#include <asm-generic/elf32-defines.h> +#define ELF_DATA ELFDATA2LSB +#define ELF_ARCH EM_386 + +#endif /* __ASM_I386_ELF_DEFINES_H */
===================================================================
include/asm-i386/elf.h +1 -21
@@ -5,22 +5,9 @@* ELF register definitions.. */ -#include <asm/ptrace.h> #include <asm/user.h> #include <asm/auxvec.h> - -#define R_386_NONE 0 -#define R_386_32 1 -#define R_386_PC32 2 -#define R_386_GOT32 3 -#define R_386_PLT32 4 -#define R_386_COPY 5 -#define R_386_GLOB_DAT 6 -#define R_386_JMP_SLOT 7 -#define R_386_RELATIVE 8 -#define R_386_GOTOFF 9 -#define R_386_GOTPC 10 -#define R_386_NUM 11 +#include <asm/elf-defines.h> typedef unsigned long elf_greg_t ;
@@ -35,13 +22,6 @@ typedef struct user_fxsr_struct elf_fpxr*/ #define elf_check_arch (x) \ (((x)->e_machine == EM_386) || ((x)->e_machine == EM_486)) - -/* -* These are used to set parameters in the core dumps. -*/ -#define ELF_CLASS ELFCLASS32 -#define ELF_DATA ELFDATA2LSB -#define ELF_ARCH EM_386#ifdef __KERNEL__
===================================================================
include/asm-i386/module.h +1 -3
@@ -6,9 +6,7 @@ struct mod_arch_specific { }; -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Ehdr Elf32_Ehdr +#include <asm/elf-defines.h> #ifdef CONFIG_M386 #define MODULE_PROC_FAMILY "386 "
===================================================================
include/asm-ia64/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf64-defines.h>
===================================================================
include/asm-ia64/elf.h +1 -1
@@ -21,7 +21,7 @@/* * These are used to set parameters in the core dumps. */ -#define ELF_CLASS ELFCLASS64 +#include <asm/elf-defines.h> #define ELF_DATA ELFDATA2LSB#define ELF_ARCH EM_IA_64
===================================================================
include/asm-ia64/module.h +1 -3
@@ -23,9 +23,7 @@ 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 +#include <asm/elf-defines.h> #define MODULE_PROC_FAMILY "ia64"#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY \
===================================================================
include/asm-m32r/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf32-defines.h>
===================================================================
include/asm-m32r/elf.h +1 -1
@@ -81,7 +81,7 @@ typedef elf_fpreg_t elf_fpregset_t;/* * These are used to set parameters in the core dumps. */ -#define ELF_CLASS ELFCLASS32 +#include <asm/elf-defines.h> #if defined(__LITTLE_ENDIAN)#define ELF_DATA ELFDATA2LSB#elif defined(__BIG_ENDIAN)
===================================================================
include/asm-m32r/module.h +1 -3
@@ -3,8 +3,6 @@struct mod_arch_specific { }; -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Ehdr Elf32_Ehdr +#include <asm/elf-defines.h> #endif /* _ASM_M32R_MODULE_H */
===================================================================
include/asm-m68k/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf32-defines.h>
===================================================================
include/asm-m68k/elf.h +1 -1
@@ -50,7 +50,7 @@ typedef struct user_m68kfp_struct elf_fp/* * These are used to set parameters in the core dumps. */ -#define ELF_CLASS ELFCLASS32 +#include <asm/elf-defines.h> #define ELF_DATA ELFDATA2MSB#define ELF_ARCH EM_68K
===================================================================
include/asm-m68k/module.h +1 -4
@@ -10,10 +10,7 @@ struct mod_arch_specific { .fixup_end = __stop_fixup, \ } -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Ehdr Elf32_Ehdr - +#include <asm/elf-defines.h> enum m68k_fixup_type { m68k_fixup_memoffset,
===================================================================
include/asm-m68knommu/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf32-defines.h>
===================================================================
include/asm-m68knommu/elf.h +1 -1
@@ -50,7 +50,7 @@ typedef struct user_m68kfp_struct elf_fp/* * These are used to set parameters in the core dumps. */ -#define ELF_CLASS ELFCLASS32 +#include <asm/elf-defines.h> #define ELF_DATA ELFDATA2MSB#define ELF_ARCH EM_68K
===================================================================
include/asm-mips/elf-defines.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifdef CONFIG_64BIT +#include <asm-generic/elf64-defines.h> +#endif +#ifdef CONFIG_32BIT +#include <asm-generic/elf32-defines.h> +#endif
===================================================================
include/asm-mips/elf.h +5 -10
@@ -173,6 +173,11 @@ typedef double elf_fpreg_t;typedef double elf_fpreg_t ;typedef elf_fpreg_t elf_fpregset_t [ELF_NFPREG ]; +/* +* These are used to set parameters in the core dumps. +*/ +#include <asm/elf-defines.h> +#ifdef CONFIG_32BIT /*
@@ -196,11 +201,6 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N __res; \ }) -/* -* These are used to set parameters in the core dumps. -*/ -#define ELF_CLASS ELFCLASS32 -#endif /* CONFIG_32BIT */ #ifdef CONFIG_64BIT
@@ -219,11 +219,6 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N \ __res; \ }) - -/* -* These are used to set parameters in the core dumps. -*/ -#define ELF_CLASS ELFCLASS64#endif /* CONFIG_64BIT */
===================================================================
include/asm-mips/module.h +1 -10
@@ -3,6 +3,7 @@#include <linux/list.h> #include <asm/uaccess.h> +#include <asm/elf-defines.h> struct mod_arch_specific {/* Data Bus Error exception tables */
@@ -34,11 +35,6 @@ typedef struct {#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_Mips_Rel Elf32_Rel#define Elf_Mips_Rela Elf32_Rela
@@ -48,11 +44,6 @@ 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_Mips_Rel Elf64_Mips_Rel#define Elf_Mips_Rela Elf64_Mips_Rela
===================================================================
include/asm-parisc/elf-defines.h new file +5 -0
@@ -0,0 +1,5 @@ +#ifdef CONFIG_64BIT +#include <asm-generic/elf64-defines.h> +#else +#include <asm-generic/elf32-defines.h> +#endif
===================================================================
include/asm-parisc/elf.h +1 -5
@@ -220,11 +220,7 @@ typedef struct elf64_fdesc {* macros, and then it includes fs/binfmt_elf.c to provide an alternate * elf binary handler for 32 bit binaries (on the 64 bit kernel). */ -#ifdef CONFIG_64BIT -#define ELF_CLASS ELFCLASS64 -#else -#define ELF_CLASS ELFCLASS32 -#endif +#include <asm/elf-defines.h> typedef unsigned long elf_greg_t ;
===================================================================
include/asm-parisc/module.h +1 -13
@@ -3,19 +3,7 @@/* * 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 +#include <asm/elf-defines.h> struct unwind_table ;
===================================================================
include/asm-powerpc/elf-defines.h new file +32 -0
@@ -0,0 +1,32 @@ +#ifndef _ASM_POWERPC_ELF_DEFINES_H +#define _ASM_POWERPC_ELF_DEFINES_H + +#include <linux/elf-const.h> + +/* +* ELF_ARCH, CLASS, and DATA are used to set parameters in the core dumps. +*/ +#ifdef __powerpc64__ +# define ELF_NVRREG32 33/* includes vscr & vrsave stuffed together */ +# define ELF_NVRREG 34/* includes vscr & vrsave in split vectors */ +# define ELF_GREG_TYPE elf_greg_t64 +#else +# define ELF_NEVRREG 34/* includes acc (as 2) */ +# define ELF_NVRREG 33/* includes vscr */ +# define ELF_GREG_TYPE elf_greg_t32 +# define ELF_ARCH EM_PPC +# define ELF_CLASS ELFCLASS32 +# define ELF_DATA ELFDATA2MSB +#endif /* __powerpc64__ */ + +#ifndef ELF_ARCH +# include <asm-generic/elf64-defines.h> +# define ELF_ARCH EM_PPC64 +# define ELF_CLASS ELFCLASS64 +# define ELF_DATA ELFDATA2MSB +#else +/* Assumption: ELF_ARCH == EM_PPC and ELF_CLASS == ELFCLASS32 */ +# include <asm-generic/elf32-defines.h> +#endif + +#endif /* _ASM_POWERPC_ELF_DEFINES_H */
===================================================================
include/asm-powerpc/elf.h +3 -20
@@ -102,26 +102,9 @@ typedef unsigned int elf_greg_t32;typedef unsigned int elf_greg_t32 ;typedef elf_greg_t32 elf_gregset_t32 [ELF_NGREG ]; -/* -* ELF_ARCH, CLASS, and DATA are used to set parameters in the core dumps. -*/ -#ifdef __powerpc64__ -# define ELF_NVRREG32 33/* includes vscr & vrsave stuffed together */ -# define ELF_NVRREG 34/* includes vscr & vrsave in split vectors */ -# define ELF_GREG_TYPE elf_greg_t64 -#else -# define ELF_NEVRREG 34/* includes acc (as 2) */ -# define ELF_NVRREG 33/* includes vscr */ -# define ELF_GREG_TYPE elf_greg_t32 -# define ELF_ARCH EM_PPC -# define ELF_CLASS ELFCLASS32 -# define ELF_DATA ELFDATA2MSB -#endif /* __powerpc64__ */ - -#ifndef ELF_ARCH -# define ELF_ARCH EM_PPC64 -# define ELF_CLASS ELFCLASS64 -# define ELF_DATA ELFDATA2MSB +#include <asm/elf-defines.h> + +#if ELF_ARCH ==EM_PPC64 typedef elf_greg_t64 elf_greg_t ;typedef elf_gregset_t64 elf_gregset_t ;#else
===================================================================
include/asm-powerpc/module.h +1 -6
@@ -50,18 +50,13 @@ struct mod_arch_specific {* Select ELF headers. * Make empty section for module_frob_arch_sections to expand. */ +#include <asm/elf-defines.h> #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" );
===================================================================
include/asm-s390/elf-defines.h new file +5 -0
@@ -0,0 +1,5 @@ +#ifndef __s390x__ +#include <asm-generic/elf32-defines.h> +#else +#include <asm-generic/elf64-defines.h> +#endif
===================================================================
include/asm-s390/elf.h +1 -5
@@ -95,11 +95,7 @@/* * These are used to set parameters in the core dumps. */ -#ifndef __s390x__ -#define ELF_CLASS ELFCLASS32 -#else /* __s390x__ */ -#define ELF_CLASS ELFCLASS64 -#endif /* __s390x__ */ +#include <asm/elf-defines.h> #define ELF_DATA ELFDATA2MSB#define ELF_ARCH EM_S390
===================================================================
include/asm-s390/module.h +1 -5
@@ -28,6 +28,7 @@ struct mod_arch_specificstruct mod_arch_syminfo *syminfo; }; +#include <asm/elf-defines.h> #ifdef __s390x__#define ElfW (x) Elf64_ ## x#define ELFW (x) ELF64_ ## x
@@ -36,11 +37,6 @@ struct mod_arch_specific#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 */
===================================================================
include/asm-sh/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf32-defines.h>
===================================================================
include/asm-sh/elf.h +1 -1
@@ -65,7 +65,7 @@ typedef struct user_fpu_struct elf_fpreg/* * These are used to set parameters in the core dumps. */ -#define ELF_CLASS ELFCLASS32 +#include <asm/elf-defines.h> #ifdef __LITTLE_ENDIAN__#define ELF_DATA ELFDATA2LSB#else
===================================================================
include/asm-sh/module.h +1 -3
@@ -9,9 +9,7 @@ struct mod_arch_specific {/* Nothing to see here .. */ }; -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Ehdr Elf32_Ehdr +#include <asm/elf-defines.h> #ifdef CONFIG_CPU_LITTLE_ENDIAN # ifdef CONFIG_CPU_SH2
===================================================================
include/asm-sh64/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf32-defines.h>
===================================================================
include/asm-sh64/elf.h +1 -1
@@ -35,7 +35,7 @@ typedef struct user_fpu_struct elf_fpreg/* * These are used to set parameters in the core dumps. */ -#define ELF_CLASS ELFCLASS32 +#include <asm/elf-defines.h> #ifdef __LITTLE_ENDIAN__#define ELF_DATA ELFDATA2LSB#else
===================================================================
include/asm-sh64/module.h +1 -3
@@ -8,9 +8,7 @@ struct mod_arch_specific {/* empty */ }; -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Ehdr Elf32_Ehdr +#include <asm/elf-defines.h> #define module_map (x) vmalloc(x)#define module_unmap (x) vfree(x)
===================================================================
include/asm-sparc/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf32-defines.h>
===================================================================
include/asm-sparc/elf.h +1 -1
@@ -125,7 +125,7 @@ do { unsigned long *dest = &(__elf_regs[* These are used to set parameters in the core dumps. */ #define ELF_ARCH EM_SPARC -#define ELF_CLASS ELFCLASS32 +#include <asm/elf-defines.h> #define ELF_DATA ELFDATA2MSB#define USE_ELF_CORE_DUMP
===================================================================
include/asm-sparc/module.h +1 -3
@@ -1,7 +1,5 @@#ifndef _ASM_SPARC_MODULE_H#define _ASM_SPARC_MODULE_Hstruct mod_arch_specific { }; -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Ehdr Elf32_Ehdr +#include <asm/elf-defines.h> #endif /* _ASM_SPARC_MODULE_H */
===================================================================
include/asm-sparc64/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf64-defines.h>
===================================================================
include/asm-sparc64/elf.h +1 -1
@@ -75,8 +75,8 @@* These are used to set parameters in the core dumps. */ #ifndef ELF_ARCH +#include <asm/elf-defines.h> #define ELF_ARCH EM_SPARCV9 -#define ELF_CLASS ELFCLASS64#define ELF_DATA ELFDATA2MSBtypedef unsigned long elf_greg_t ;
===================================================================
include/asm-sparc64/module.h +1 -3
@@ -1,7 +1,5 @@#ifndef _ASM_SPARC64_MODULE_H#define _ASM_SPARC64_MODULE_Hstruct mod_arch_specific { }; -#define Elf_Shdr Elf64_Shdr -#define Elf_Sym Elf64_Sym -#define Elf_Ehdr Elf64_Ehdr +#include <asm/elf-defines.h> #endif /* _ASM_SPARC64_MODULE_H */
===================================================================
include/asm-v850/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf32-defines.h>
===================================================================
include/asm-v850/elf.h +1 -1
@@ -50,7 +50,7 @@ typedef struct user_fpu_struct elf_fpreg/* * These are used to set parameters in the core dumps. */ -#define ELF_CLASS ELFCLASS32 +#include <asm/elf-defines.h> #ifdef __LITTLE_ENDIAN__#define ELF_DATA ELFDATA2LSB#else
===================================================================
include/asm-v850/module.h +1 -3
@@ -31,9 +31,7 @@ struct mod_arch_specificunsigned int core_plt_section, init_plt_section; }; -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Ehdr Elf32_Ehdr +#include <asm/elf-defines.h> /* Make empty sections for module_frob_arch_sections to expand. */ #ifdef MODULE
===================================================================
include/asm-x86_64/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf64-defines.h>
===================================================================
include/asm-x86_64/elf.h +1 -1
@@ -39,7 +39,7 @@ typedef struct user_i387_struct elf_fpre/* * These are used to set parameters in the core dumps. */ -#define ELF_CLASS ELFCLASS64 +#include <asm/elf-defines.h> #define ELF_DATA ELFDATA2LSB#define ELF_ARCH EM_X86_64
===================================================================
include/asm-x86_64/module.h +1 -3
@@ -3,8 +3,6 @@struct mod_arch_specific {}; -#define Elf_Shdr Elf64_Shdr -#define Elf_Sym Elf64_Sym -#define Elf_Ehdr Elf64_Ehdr +#include <asm/elf-defines.h> #endif
===================================================================
include/asm-xtensa/elf-defines.h new file +1 -0
@@ -0,0 +1,1 @@ +#include <asm-generic/elf32-defines.h>
===================================================================
include/asm-xtensa/elf.h +1 -1
@@ -153,7 +153,7 @@ extern void xtensa_elf_core_copy_regs (x# error processor byte order undefined!#endif -#define ELF_CLASS ELFCLASS32 +#include <asm/elf-defines.h> #define ELF_ARCH EM_XTENSA#define USE_ELF_CORE_DUMP
===================================================================
include/asm-xtensa/module.h +1 -3
@@ -18,8 +18,6 @@ struct mod_arch_specific /* Module support is not completely implemented. */ }; -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Ehdr Elf32_Ehdr +#include <asm/elf-defines.h> #endif /* _XTENSA_MODULE_H */
===================================================================
include/linux/Kbuild +3 -1
@@ -58,7 +58,9 @@ header-y += efs_fs_sb.h header-y += efs_fs_sb.h header-y += elf-fdpic.h header-y += elf.h -header-y += elf-em.h +header-y += elf-const.h +header-y += elf-decl.h +header-y += elf-defn.h header-y += fadvise.h header-y += fd.h header-y += fdreg.h
===================================================================
include/linux/audit.h +1 -1
@@ -25,7 +25,7 @@#define _LINUX_AUDIT_H_#include <linux/types.h> -#include <linux/elf-em.h> +#include <linux/elf-const.h> /* The netlink messages for the audit system is divided into blocks: * 1000 - 1099 are for commanding the audit system
===================================================================
include/linux/elf-const.h new file +222 -0
222 lines not on this page · raw message
===================================================================
include/linux/elf-decl.h new file +48 -0
48 lines not on this page · raw message
===================================================================
include/linux/elf-defn.h new file +174 -0
174 lines not on this page · raw message
===================================================================
include/linux/elf-em.h deleted +0 -51
51 lines not on this page · raw message
===================================================================
include/linux/elf.h +21 -378
414 lines not on this page · raw message
===================================================================
include/linux/elfnote.h +19 -11
@@ -58,7 +58,8 @@ 4484:.balign 4 ; \ ELFNOTE_END#else /* !__ASSEMBLER__ */ -#include <linux/elf.h> +#include <linux/elf-defn.h> +#include <asm/elf-defines.h> /* * Use an anonymous structure which matches the shape of * Elf{32,64}_Nhdr, but includes the name and desc data. The size and
@@ -67,15 +68,15 @@ 4484:.balign 4 ; \* only define one note per line, since __LINE__ is used to generate * unique symbols. */ -#define _ELFNOTE_PASTE (a,b) a##b -#define _ELFNOTE (size, name, unique, type, desc) \ +#define __ELFNOTE_PASTE (a,b) a##b +#define __ELFNOTE (size, name, unique, type, desc) \ static const struct { \ - struct elf##size##_note _nhdr; \ + struct Elf##size##_Nhdr _nhdr; \ unsigned char _name[sizeof(name)] \ - __attribute__((aligned(sizeof(Elf##size##_Word)))); \ + __attribute__((aligned(sizeof(Elf##size##_Word)))); \ typeof(desc) _desc \ - __attribute__((aligned(sizeof(Elf##size##_Word)))); \ - } _ELFNOTE_PASTE(_note_, unique) \ + __attribute__((aligned(sizeof(Elf##size##_Word)))); \ + } __ELFNOTE_PASTE(_note_, unique) \ __attribute_used__ \ __attribute__((section(".note." name), \ aligned(sizeof(Elf##size##_Word)), \
@@ -88,11 +89,18 @@ 4484:.balign 4 ; \ name, \ desc \ } -#define ELFNOTE (size, name, type, desc) \ - _ELFNOTE(size, name, __LINE__, type, desc) -#define ELFNOTE32 (name, type, desc) ELFNOTE(32, name, type, desc) -#define ELFNOTE64 (name, type, desc) ELFNOTE(64, name, type, desc) +#define ELFNOTE32 (name, type, desc) __ELFNOTE(32, name, __LINE__, type, desc) +#define ELFNOTE64 (name, type, desc) __ELFNOTE(64, name, __LINE__, type, desc) + +#if ELF_CLASS ==ELFCLASS32 +#define ELFNOTE (name, type, desc) ELFNOTE32(name, type, desc) +#elif ELF_CLASS ==ELFCLASS64 +#define ELFNOTE (name, type, desc) ELFNOTE64(name, type, desc) +#else +#error Define ELFNOTE for this ELF_CLASS +#endif +#endif /* __ASSEMBLER__ */ #endif /* _LINUX_ELFNOTE_H */
===================================================================
include/linux/module.h +0 -1
@@ -11,7 +11,6 @@#include <linux/compiler.h> #include <linux/cache.h> #include <linux/kmod.h> -#include <linux/elf.h> #include <linux/stringify.h> #include <linux/kobject.h> #include <linux/moduleparam.h>
===================================================================
kernel/sysctl.c +1 -0
@@ -50,6 +50,7 @@#include <asm/uaccess.h> #include <asm/processor.h> +#include <asm/elf.h> extern int proc_nr_files (ctl_table *table,int write,struct file *filp,void __user *buffer,size_t *lenp,loff_t *ppos);
===================================================================
lib/bug.c +1 -0
@@ -38,6 +38,7 @@#include <linux/list.h> #include <linux/module.h> #include <linux/bug.h> +#include <linux/elf.h> extern const struct bug_entry __start___bug_table[], __stop___bug_table[];
On Wed, 2007-06-20 at 16:08 -0700, Jeremy Fitzhardinge wrote:
arm26 changes acked-by: Ian Molton <[email protected]>
Quoted 3 lines · ian
On Wed, 2007-06-20 at 16:08 -0700, Jeremy Fitzhardinge wrote:
arm26 changes acked-by: Ian Molton <[email protected]>
Did you try building it to flush out any missing-header problems?
J
Jeremy,
Could you please add the ELF architecture-magic number for Xtensa (94) when you finally submit this patch?
Quoted 10 lines · Jeremy Fitzhardinge
This patch cleans up the ELF headers and their users. It does several related things:
include/linux/elf-const.h new file +5
-0@@ -0,0 +1,222 @@ +#ifndef _LINUX_ELF_CONST_H +#define _LINUX_ELF_CONST_H + +/* These constants define the various ELF target machines */ +#define EM_NONE 0
...
include/linux/elf-const.h line 31
Quoted 2 lines
include/linux/elf-const.h new file +2
-0+#define EM_V850 87/* NEC v850 */ +#define EM_M32R 88/* Renesas M32R */
#define EM_XTENSA 94
Thanks,
-Chris
Quoted 3 lines · Chris Zankel
Jeremy,
Could you please add the ELF architecture-magic number for Xtensa (94) when you finally submit this patch?
I guess, but I think it would be better if you just sent an incremental patch to add it. Does my patch work OK for Xtensa?
J
Quoted 2 lines · Jeremy Fitzhardinge
This patch cleans up the ELF headers and their users. It does several related things:
Looks good. We can get away with exporting a lot less of this to userspace too, can't we?
Signature · 1 line
dwmw2
Quoted 9 lines · David Woodhouse
Quoted 3 lines · Jeremy Fitzhardinge
This patch cleans up the ELF headers and their users. It does several related things:
Looks good. We can get away with exporting a lot less of this to userspace too, can't we?
Probably. What needs to be exported at all?
J
Hi,
Quoted 6 lines · David Woodhouse
Quoted 2 lines · Jeremy Fitzhardinge
This patch cleans up the ELF headers and their users. It does several related things:
Looks good. We can get away with exporting a lot less of this to userspace too, can't we?
glibc provides its own version, so it doesn't has to be exported at all.
bye, Roman
Hi, Roman!
Quoted 11 lines · Roman Zippel
Hi,
Quoted 5 lines · David Woodhouse
Quoted 2 lines · Jeremy Fitzhardinge
This patch cleans up the ELF headers and their users. It does several related things:
Looks good. We can get away with exporting a lot less of this to userspace too, can't we?
glibc provides its own version, so it doesn't has to be exported at all.
AFAIK the glibc folks want to rely more on the linux kernel headers in the future and not provide more or less redundant headers anymore... Please talk to them about the future plans.
Regards,
Signature · 10 lines
Clemens Koller __________________________________ R&D Imaging Devices Anagramm GmbH Rupert-Mayer-Straße 45/1 Linhof Werksgelände D-81379 München Tel.089-741518-50 Fax 089-741518-19 http://www.anagramm-technology.com
Hi,
Quoted 4 lines · Clemens Koller
Quoted 1 line
glibc provides its own version, so it doesn't has to be exported at all.
AFAIK the glibc folks want to rely more on the linux kernel headers in the future and not provide more or less redundant headers anymore...
In this case it's more an ABI header, it doesn't export any kernel interfaces.
bye, Roman
Hi,
Quoted 9 lines · Jeremy Fitzhardinge
This patch cleans up the ELF headers and their users. It does several related things:
1. split
linux/elf.hinto piecesThis splits
linux/elf.hinto several pieces:
linux/elf.h- still the common elf header,
functionally unchanged
linux/elf-const.h- ELF constants, includable by asm code
We have the __ASSEMBLY__ define for this, so just for asm code we don't need a separate header.
Quoted 2 lines
linux/elf-decl.h- ELF type declarations, without definitions
linux/elf-defn.h- ELF type definitions
What's the point in splitting these two?
After this patch <linux/elf.h> seems to be pretty much empty, I'd rather suggest to move the function declarations to elfcore.h and leave the basic elf definitions in elf.h. Many small header files have the disadvantage that it takes longer to find the needed information.
bye, Roman
Quoted 5 lines · Roman Zippel
Quoted 5 lines
This patch cleans up the ELF headers and their users. It does several related things:
1. split
linux/elf.hinto pieces
Quoted 8 lines
Quoted 5 lines
This splits
linux/elf.hinto several pieces:
linux/elf.h- still the common elf header,
functionally unchanged
linux/elf-const.h- ELF constants, includable by asm codeWe have the
__ASSEMBLY__define for this, so just for asm code we don't need a separate header.
Hm. The number of __ASSEMBLY__s end up being pretty large, and it just seemed cleaner to put them in separate headers.
Quoted 6 lines
Quoted 3 lines
linux/elf-decl.h- ELF type declarations, without definitions
linux/elf-defn.h- ELF type definitionsWhat's the point in splitting these two?
Because there are other headers which just need some type forward-declarations, and don't need the whole set of ELF types defined. In particular, linux/module.h - which is included all over the place in the kernel - needs a couple of ELF types declared, and including it all over the place is just a waste. Also, there were some nasty cyclic header dependency problems around linux/elf.h, linux/module.h, linux/bug.h and asm/bug.h which ended up leading to some awkward hacks; I need to remind myself what the problems were and see if this elf cleanup helps (pretty sure it should).
Quoted 2 lines
After this patch <
linux/elf.h> seems to be pretty much empty, I'd rather suggest to move the function declarations toelfcore.hand leave the basic elf definitions inelf.h. Many small header files have the disadvantage that it takes longer to find the needed information.
linux/elf.h ends up pulling in a really surprising amount of stuff, mostly because it ends up including asm/elf.h. asm/elf.h, in turn, depending on the architecture, pulls in a wide variety of other headers. When I cleaned this up, I found quite a few buggy .c files which ended up relying on implicit includes via this chain.
Given that there's been a general push to try and cut down on the number of header dependency entanglements, I thought I could contribute while solving my own immediate problems.
linux/elfcore.h is specifically related to ELF core files, so the two corefile notes-related headers could be moved there.
J
Hi,
Quoted 6 lines · Jeremy Fitzhardinge
Quoted 3 lines
We have the
__ASSEMBLY__define for this, so just for asm code we don't need a separate header.Hm. The number of
__ASSEMBLY__send up being pretty large, and it just seemed cleaner to put them in separate headers.
This could be avoided by reordering things within elf.h, but is it really necessary since there is no user of this right now?
Having actual users would help to decide how to deal with this, since e.g. if only a few constants were needed this could also be done via asm-offsets.h.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
linux/elf-decl.h- ELF type declarations, without definitions
linux/elf-defn.h- ELF type definitions
Quoted 8 lines
Quoted 2 lines
What's the point in splitting these two?
Because there are other headers which just need some type forward-declarations, and don't need the whole set of ELF types defined. In particular,
linux/module.h- which is included all over the place in the kernel - needs a couple of ELF types declared, and including it all over the place is just a waste.
module.h does indeed pull in way too much, but instead of hacking headers into little pieces, IMO it would be better to solve the real problem. I played with it a little and the patch below moves a lot stuff out of module.h, so this would drastically reduce the header dependencies. Unless there are major objections, I can test the patch a little more and convert the other archs.
bye, Roman
--- arch/i386/kernel/module.c | 24 +-- drivers/base/bus.c | 4 include/linux/module.h | 173 --------------------------- include/linux/moduleloader.h | 212 +++++++++++++++++++++++++++++++++- include/linux/moduleparam.h | 22 --- include/linux/unwind.h | 4 kernel/module.c | 267 +++++++++++++++++++++---------------------- kernel/params.c | 13 +- scripts/mod/modpost.c | 9 - 9 files changed, 369 insertions(+), 359 deletions(-)
include/linux/module.h +0 -173
@@ -44,23 +44,6 @@ struct modversion_infostruct module ; -struct module_attribute { -struct attribute attr; -ssize_t (*show)(struct module_attribute *,struct module *,char *); -ssize_t (*store)(struct module_attribute *,struct module *, -const char *,size_t count); -void (*setup)(struct module *,const char *); -int (*test)(struct module *); -void (*free)(struct module *); -}; - -struct module_kobject -{ -struct kobject kobj; -struct module *mod; -struct kobject *drivers_dir; -}; -/* These are either module local, or the kernel's dummy ones. */ extern int init_module (void );extern void cleanup_module (void );
@@ -229,95 +212,13 @@ enum module_state MODULE_STATE_GOING, }; -/* Similar stuff for section attributes. */ -struct module_sect_attr -{ -struct module_attribute mattr; -char *name; -unsigned long address; -}; - -struct module_sect_attrs -{ -struct attribute_group grp; -int nsections; -struct module_sect_attr attrs[0 ]; -}; - -struct module_param_attrs ; -struct module {enum module_state state; -/* Member of list of modules */ -struct list_head list; -/* Unique handle for this module */ char name[MODULE_NAME_LEN ]; -/* Sysfs stuff. */ -struct module_kobject mkobj; -struct module_param_attrs *param_attrs; -struct module_attribute *modinfo_attrs; -const char *version; -const char *srcversion; -struct kobject *holders_dir; - -/* Exported symbols */ -const struct kernel_symbol *syms; -unsigned int num_syms; -const unsigned long *crcs; - -/* GPL-only exported symbols. */ -const struct kernel_symbol *gpl_syms; -unsigned int num_gpl_syms; -const unsigned long *gpl_crcs; - -/* unused exported symbols. */ -const struct kernel_symbol *unused_syms; -unsigned int num_unused_syms; -const unsigned long *unused_crcs; -/* GPL-only, unused exported symbols. */ -const struct kernel_symbol *unused_gpl_syms; -unsigned int num_unused_gpl_syms; -const unsigned long *unused_gpl_crcs; - -/* symbols that will be GPL-only in the near future. */ -const struct kernel_symbol *gpl_future_syms; -unsigned int num_gpl_future_syms; -const unsigned long *gpl_future_crcs; - -/* Exception table */ -unsigned int num_exentries; -const struct exception_table_entry *extable; - -/* Startup function. */ -int (*init)(void ); - -/* If this is non-NULL, vfree after init() returns */ -void *module_init; - -/* Here is the actual code + data, vfree'd on unload. */ -void *module_core; - -/* Here are the sizes of the init and core sections */ -unsigned long init_size, core_size; - -/* The size of the executable code in each section. */ -unsigned long init_text_size, core_text_size; - -/* The handle returned from unwind_add_table. */ -void *unwind_info; - -/* Arch-specific module values */ -struct mod_arch_specific arch; - -/* Am I unsafe to unload? */ -int unsafe; - -unsigned int taints;/* same bits as kernel:tainted */ -#ifdef CONFIG_GENERIC_BUG /* Support for BUG */ struct list_head bug_list;
@@ -328,25 +229,6 @@ struct module#ifdef CONFIG_MODULE_UNLOAD /* Reference counts */ struct module_ref ref[NR_CPUS ]; - -/* What modules depend on me? */ -struct list_head modules_which_use_me; - -/* Who is waiting for us to be unloaded */ -struct task_struct *waiter; - -/* Destruction function. */ -void (*exit)(void ); -#endif - -#ifdef CONFIG_KALLSYMS -/* We keep the symbol and string tables for kallsyms. */ -Elf_Sym *symtab; -unsigned long num_symtab; -char *strtab; - -/* Section attributes */ -struct module_sect_attrs *sect_attrs;#endif /* Per-cpu data. */
@@ -356,9 +238,6 @@ struct modulekeeping pointers to this stuff */ char *args; }; -#ifndef MODULE_ARCH_INIT -#define MODULE_ARCH_INIT {} -#endif /* FIXME: It'd be nice to isolate modules during init, too, so they aren't used before they (may) fail. But presently too much code
@@ -571,58 +450,6 @@ static inline void print_modules(void)#endif /* CONFIG_MODULES */ -struct device_driver ; -#ifdef CONFIG_SYSFS -struct module ; - -extern struct kset module_subsys; - -int mod_sysfs_init (struct module *mod); -int mod_sysfs_setup (struct module *mod, -struct kernel_param *kparam, -unsigned int num_params); -int module_add_modinfo_attrs (struct module *mod); -void module_remove_modinfo_attrs (struct module *mod); - -#else /* !CONFIG_SYSFS */ - -static inline int mod_sysfs_init (struct module *mod) -{ -return 0 ; -} - -static inline int mod_sysfs_setup (struct module *mod, -struct kernel_param *kparam, -unsigned int num_params) -{ -return 0 ; -} - -static inline int module_add_modinfo_attrs (struct module *mod) -{ -return 0 ; -} - -static inline void module_remove_modinfo_attrs (struct module *mod) -{ } - -#endif /* CONFIG_SYSFS */ - -#if defined(CONFIG_SYSFS ) && defined(CONFIG_MODULES ) - -void module_add_driver (struct module *mod,struct device_driver *drv); -void module_remove_driver (struct device_driver *drv); - -#else /* not both CONFIG_SYSFS && CONFIG_MODULES */ - -static inline void module_add_driver (struct module *mod,struct device_driver *drv) -{ } - -static inline void module_remove_driver (struct device_driver *drv) -{ } - -#endif -#define symbol_request (x) try_then_request_module(symbol_get(x), "symbol:" #x)/* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
include/linux/moduleloader.h +206 -6
247 lines not on this page · raw message
include/linux/moduleparam.h +0 -22
@@ -165,26 +165,4 @@ extern int param_array_get(char *buffer,extern int param_set_copystring (const char *val,struct kernel_param *kp);extern int param_get_string (char *buffer,struct kernel_param *kp); -/* for exporting parameters in /sys/parameters */ - -struct module ; - -#if defined(CONFIG_SYSFS ) && defined(CONFIG_MODULES ) -extern int module_param_sysfs_setup (struct module *mod, -struct kernel_param *kparam, -unsigned int num_params); - -extern void module_param_sysfs_remove (struct module *mod); -#else -static inline int module_param_sysfs_setup (struct module *mod, -struct kernel_param *kparam, -unsigned int num_params) -{ -return 0 ; -} - -static inline void module_param_sysfs_remove (struct module *mod) -{ } -#endif -#endif /* _LINUX_MODULE_PARAMS_H */
include/linux/unwind.h +2 -2
@@ -12,7 +12,7 @@* is not much point in implementing the full Dwarf2 unwind API. */ -struct module ; +struct module_private ;struct unwind_frame_info {};
@@ -21,7 +21,7 @@ static inline void unwind_setup(void) {}#ifdef CONFIG_MODULES -static inline void *unwind_add_table (struct module *mod, +static inline void *unwind_add_table (struct module_private *mod,const void *table_start,unsigned long table_size) {
kernel/module.c +134 -133
913 lines not on this page · raw message
kernel/params.c +7 -6
@@ -15,6 +15,7 @@along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <linux/moduleloader.h> #include <linux/moduleparam.h> #include <linux/kernel.h> #include <linux/string.h>
@@ -397,7 +398,7 @@ struct module_param_attrs#define to_param_attr (n) container_of(n, struct param_attribute, mattr);static ssize_t param_attr_show (struct module_attribute *mattr, -struct module *mod,char *buf) +struct module_private *mod,char *buf) {int count;struct param_attribute *attribute =to_param_attr (mattr);
@@ -415,7 +416,7 @@ static ssize_t param_attr_show(struct mo/* sysfs always hands a nul-terminated string in buf. We rely on that. */ static ssize_t param_attr_store (struct module_attribute *mattr, -struct module *owner, +struct module_private *owner,const char *buf,size_t len) {int err;
@@ -491,7 +492,7 @@ param_sysfs_setup(struct module_kobject pattr->mattr.show = param_attr_show; pattr->mattr.store = param_attr_store; pattr->mattr.attr.name = (char *)&kp->name[name_skip]; - pattr->mattr.attr.owner = mk->mod; + pattr->mattr.attr.owner = &mk->mod->mod; pattr->mattr.attr.mode = kp->perm; *(gattr++) = &(pattr++)->mattr.attr; }
@@ -515,7 +516,7 @@ param_sysfs_setup(struct module_kobject* Adds sysfs entries for module parameters, and creates a link from * /sys/module/[mod->name]/parameters to /sys/parameters/[mod->name]/ */ -int module_param_sysfs_setup (struct module *mod, +int module_param_sysfs_setup (struct module_private *mod,struct kernel_param *kparam,unsigned int num_params) {
@@ -536,7 +537,7 @@ int module_param_sysfs_setup(struct modu* Remove sysfs entries for module parameters and the corresponding * kobject. */ -void module_param_sysfs_remove (struct module *mod) +void module_param_sysfs_remove (struct module_private *mod) {if (mod->param_attrs) { sysfs_remove_group(&mod->mkobj.kobj,
@@ -563,7 +564,7 @@ static void __init kernel_param_sysfs_se mk =kzalloc (sizeof (struct module_kobject ),GFP_KERNEL );BUG_ON (!mk); - mk->mod =THIS_MODULE ; + mk->mod =get_mod_private (THIS_MODULE );kobj_set_kset_s (mk, module_subsys);kobject_set_name (&mk->kobj, name);kobject_init (&mk->kobj);
arch/i386/kernel/module.c +12 -12
@@ -38,7 +38,7 @@ void *module_alloc(unsigned long size)/* Free memory returned from module_alloc */ -void module_free (struct module *mod,void *module_region) +void module_free (struct module_private *mod,void *module_region) {vfree (module_region);/* FIXME: If module_region == mod->init_region, trim exception
@@ -49,7 +49,7 @@ void module_free(struct module *mod, voiint module_frob_arch_sections (Elf_Ehdr *hdr,Elf_Shdr *sechdrs,char *secstrings, -struct module *mod) +struct module_private *mod) {return 0 ; }
@@ -58,7 +58,7 @@ int apply_relocate(Elf32_Shdr *sechdrs,const char *strtab, unsigned int symindex, unsigned int relsec, - struct module *me) + struct module_private *me) { unsigned int i;Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
@@ -87,7 +87,7 @@ int apply_relocate(Elf32_Shdr *sechdrs,break ;default :printk (KERN_ERR "module %s: Unknown relocation: %u\n" , - me->name,ELF32_R_TYPE (rel[i].r_info)); + me->mod.name,ELF32_R_TYPE (rel[i].r_info));return -ENOEXEC ; } }
@@ -98,16 +98,16 @@ int apply_relocate_add(Elf32_Shdr *sechd const char *strtab, unsigned int symindex, unsigned int relsec, - struct module *me) + struct module_private *me) { printk(KERN_ERR "module %s: ADD RELOCATION unsupported\n", - me->name); + me->mod.name);return -ENOEXEC ; }int module_finalize (const Elf_Ehdr *hdr,const Elf_Shdr *sechdrs, -struct module *me) +struct module_private *me) {const Elf_Shdr *s, *text =NULL , *alt =NULL , *locks =NULL , *para =NULL ;
@@ -132,7 +132,7 @@ int module_finalize(const Elf_Ehdr *hdr,if (locks && text) {void *lseg = (void *)locks->sh_addr;void *tseg = (void *)text->sh_addr; -alternatives_smp_module_add (me, me->name, +alternatives_smp_module_add (&me->mod, me->mod.name, lseg, lseg + locks->sh_size, tseg, tseg + text->sh_size); }
@@ -142,11 +142,11 @@ int module_finalize(const Elf_Ehdr *hdr,apply_paravirt (pseg, pseg + para->sh_size); } -return module_bug_finalize (hdr, sechdrs, me); +return module_bug_finalize (hdr, sechdrs, &me->mod); } -void module_arch_cleanup (struct module *mod) +void module_arch_cleanup (struct module_private *mod) { -alternatives_smp_module_del (mod); -module_bug_cleanup (mod); +alternatives_smp_module_del (&mod->mod); +module_bug_cleanup (&mod->mod); }
drivers/base/bus.c +2 -2
@@ -9,7 +9,7 @@*/ #include <linux/device.h> -#include <linux/module.h> +#include <linux/moduleloader.h> #include <linux/errno.h> #include <linux/init.h> #include <linux/string.h>
@@ -619,7 +619,7 @@ int bus_add_driver(struct device_driver goto out_unregister; }klist_add_tail (&drv->knode_bus, &bus->klist_drivers); -module_add_driver (drv->owner, drv); +module_add_driver (get_mod_private (drv->owner), drv); error =driver_add_attrs (bus, drv);if (error) {
scripts/mod/modpost.c +6 -3
@@ -1314,15 +1314,17 @@ static void check_exports(struct module**/ static void add_header (struct buffer *b,struct module *mod) { -buf_printf (b,"#include <linux/module.h>\n" ); +buf_printf (b,"#include <linux/moduleloader.h>\n" );buf_printf (b,"#include <linux/vermagic.h>\n" );buf_printf (b,"#include <linux/compiler.h>\n" );buf_printf (b,"\n" );buf_printf (b,"MODULE_INFO(vermagic, VERMAGIC_STRING);\n" );buf_printf (b,"\n" ); -buf_printf (b,"struct module __this_module\n" ); +buf_printf (b,"struct module_private __this_module_private\n" );buf_printf (b,"__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n" ); -buf_printf (b," .name = KBUILD_MODNAME,\n" ); +buf_printf (b," .mod = {\n" ); +buf_printf (b," .name = KBUILD_MODNAME,\n" ); +buf_printf (b," },\n" );if (mod->has_init)buf_printf (b," .init = init_module,\n" );if (mod->has_cleanup)
@@ -1331,6 +1333,7 @@ static void add_header(struct buffer *b, "#endif\n");buf_printf (b," .arch = MODULE_ARCH_INIT,\n" );buf_printf (b,"};\n" ); +buf_printf (b,"asm (\".globl __this_module; .type __this_module,@object; __this_module = __this_module_private\");\n" ); }/**
Quoted 2 lines · Roman Zippel
This could be avoided by reordering things within
elf.h, but is it really necessary since there is no user of this right now?
Well, yes, I don't have much need to include ELF headers in asm now, but I still think its worth separating the arch-specific definitions from asm/elf.h and all the other stuff they pull in. Specifically, the structure forward declarations and constants have very few external dependencies, but the structure definitions - particularly the arch-specific ones - have very wide dependencies, which is what I'm trying to solve. Very few pieces of code care about the arch-specific structures.
Quoted 2 lines
module.hdoes indeed pull in way too much, but instead of hacking headers into little pieces, IMO it would be better to solve the real problem.
No, that's not the real problem; its a side-effect of the real problem. The real problem is that linux/elf.h ends up bringing in too much. arch/powerpc, for example, has its own stripped down copy of elf.h for bootloader stuff in order to avoid this extra crud. The fix is to make it possible to get just the appropriate ELF definitions without getting everything else.
There's the secondary problem that lots of ELF stuff is copy'n'paste duplicated across all the architectures, but all they really care about is one of two sets of parallel definitions (32 or 64 ELF structures). That was the secondary
Quoted 3 lines
I played with it a little and the patch below moves a lot stuff out of
module.h, so this would drastically reduce the header dependencies. Unless there are major objections, I can test the patch a little more and convert the other archs.
Well, it seems like a large fiddly patch which only solves part of the problem I want to solve; actually it doesn't help me at all, but it achieves one of the side-effects of my patch. The arch changes make it look pretty awkward to merge.
J
Hi,
Quoted 5 lines · Jeremy Fitzhardinge
Quoted 3 lines · Roman Zippel
This could be avoided by reordering things within
elf.h, but is it really necessary since there is no user of this right now?
Quoted 7 lines
Well, yes, I don't have much need to include ELF headers in asm now, but I still think its worth separating the arch-specific definitions from
asm/elf.hand all the other stuff they pull in. Specifically, the structure forward declarations and constants have very few external dependencies, but the structure definitions - particularly the arch-specific ones - have very wide dependencies, which is what I'm trying to solve. Very few pieces of code care about the arch-specific structures.
The problem I have is that you want to separate _all_ constants, which doesn't really make sense to me, because many of them are useless without the correspending structures.
Quoted 6 lines
Quoted 3 lines
module.hdoes indeed pull in way too much, but instead of hacking headers into little pieces, IMO it would be better to solve the real problem.No, that's not the real problem; its a side-effect of the real problem. The real problem is that
linux/elf.hends up bringing in too much.
Please define the problem more specific. :)
Quoted 4 lines
arch/powerpc,
for example, has its own stripped down copy ofelf.hfor bootloader stuff in order to avoid this extra crud. The fix is to make it possible to get just the appropriate ELF definitions without getting everything else.
The bootloader is no kernel code and thus the elf header pull in a lot less:
$ gcc -c foo.c -Iusr/include --trace-includes . usr/include/linux/elf.h .. usr/include/linux/types.h ... usr/include/linux/posix_types.h .... usr/include/linux/stddef.h .... usr/include/asm/posix_types.h ... usr/include/asm/types.h .. usr/include/linux/auxvec.h ... usr/include/asm/auxvec.h .. usr/include/linux/elf-em.h .. usr/include/asm/elf.h ... usr/include/asm/ptrace.h .... usr/include/asm/ptrace-abi.h ... usr/include/asm/user.h .... usr/include/asm/page.h
One could remove ptrace.h but otherwise the result looks quite reasonable.
Quoted 4 lines
There's the secondary problem that lots of ELF stuff is copy'n'paste duplicated across all the architectures, but all they really care about is one of two sets of parallel definitions (32 or 64 ELF structures). That was the secondary
Some of it you could put into linux/elf, e.g.:
#if ELF_CLASS == ELFCLASS32
typedef Elf32_Ehdr Elf_Ehdr; typedef Elf32_Phdr Elf_Phdr; typedef Elf32_Shdr Elf_Shdr; typedef Elf32_Sym Elf_Sym; typedef Elf32_Dyn Elf_Dyn; typedef Elf32_Rel Elf_Rel; typedef Elf32_Rela Elf_Rela;
typedef Elf32_Addr Elf_Addr;
#elif ELF_CLASS == ELFCLASS64
typedef Elf64_Ehdr Elf_Ehdr; typedef Elf64_Phdr Elf_Phdr; typedef Elf64_Shdr Elf_Shdr; typedef Elf64_Sym Elf_Sym; typedef Elf64_Dyn Elf_Dyn; typedef Elf64_Rel Elf_Rel; typedef Elf64_Rela Elf_Rela;
typedef Elf64_Addr Elf_Addr;
#else
#error
#endif
Quoted 10 lines
Quoted 5 lines
I played with it a little and the patch below moves a lot stuff out of
module.h, so this would drastically reduce the header dependencies. Unless there are major objections, I can test the patch a little more and convert the other archs.Well, it seems like a large fiddly patch which only solves part of the problem I want to solve; actually it doesn't help me at all, but it achieves one of the side-effects of my patch. The arch changes make it look pretty awkward to merge.
The patch does help you quite a bit, you don't have to cleanup elf.h so it's usable by the whole kernel. Only few parts now really need it and depend on it, which makes the extensive splitup unnecessary only to reduce header dependencies.
bye, Roman
Quoted 2 lines · Roman Zippel
The problem I have is that you want to separate _all_ constants, which doesn't really make sense to me, because many of them are useless without the correspending structures.
It seems cleanest to just put all the constants in one place rather than scatter them around based on how they happen to be used.
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
module.hdoes indeed pull in way too much, but instead of hacking headers into little pieces, IMO it would be better to solve the real problem.No, that's not the real problem; its a side-effect of the real problem. The real problem is that
linux/elf.hends up bringing in too much.Please define the problem more specific. :)
I want to be able to include a header to get just the ELF type and constant definitions with no other crud. Both arch-independent ELF definitions, and the ones parameterised by ELF_CLASS.
I want this for three reasons:
1. one is the general cleanup that allows people to use forward-declared ELF types in general kernel headers without needing to pull in the full set of ELF headers
2. and to be able to pull full ELF declarations into code which can't deal with Linux headers, such as bootloader code which doesn't compile in the same universe as the rest of the kernel
3. a way of getting arch-dependent but broadly common ELF parameters in a consistent way
This is complicated by the fact that each architecture needs to define some arch-dependent ELF structures which will end up having wider dependencies. The classic example is the ELF note for core files which contains register and other process state, and that will naturally pull in a bunch of other headers to implement that. Unfortunately, the current structure of the ELF headers mean that any user with the slightest interest in ELF structures will end up pulling in half the kernel headers via the asm/elf.h includes.
So my solution was to factor the ELF definitions into useful groups that allow the various users to pull in what they need. The breakdown is:
* arch-independent ELF forward declarations: linux/elf-decl.h
* arch-independent constants: linux/elf-const.h
* arch-independent ELF structure definitions: linux/elf-defn.h
* arch-parameterised ELF declarations: asm/elf-defines.h
and because more or less all the architectures do the same thing for their parameterised ELF types (albeit inconsistently), I pulled the implementation into asm-generic/elf{32,64}-defines.h, and the typical asm/elf-defines.h ends up being a single line to include the appropriate one.
I'd agree that linux/elf-const.h and linux/elf-decl.h could probably be folded together.
Quoted 24 lines
Quoted 5 lines
arch/powerpc,
for example, has its own stripped down copy ofelf.hfor bootloader stuff in order to avoid this extra crud. The fix is to make it possible to get just the appropriate ELF definitions without getting everything else.The bootloader is no kernel code and thus the elf header pull in a lot less:
$ gcc -c foo.c -Iusr/include --trace-includes . usr/include/linux/elf.h .. usr/include/linux/types.h ... usr/include/linux/posix_types.h .... usr/include/linux/stddef.h .... usr/include/asm/posix_types.h ... usr/include/asm/types.h .. usr/include/linux/auxvec.h ... usr/include/asm/auxvec.h .. usr/include/linux/elf-em.h .. usr/include/asm/elf.h ... usr/include/asm/ptrace.h .... usr/include/asm/ptrace-abi.h ... usr/include/asm/user.h .... usr/include/asm/page.h
Quoted 2 lines
One could remove
ptrace.hbut otherwise the result looks quite reasonable.
Which architecture? The variation of other includes in the various asm-*/elf.h headers is very broad.
On i386, it ends up being dependent on the mach-* subarch mess, which doesn't work in the boot code. Since there's nothing about the ELF definitions which is subarch-dependent, so that's clearly a bogus dependency.
Quoted 30 lines
Quoted 5 lines
There's the secondary problem that lots of ELF stuff is copy'n'paste duplicated across all the architectures, but all they really care about is one of two sets of parallel definitions (32 or 64 ELF structures). That was the secondary
Some of it you could put into linux/elf, e.g.:
#if
ELF_CLASS== ELFCLASS32typedef Elf32_Ehdr Elf_Ehdr; typedef Elf32_Phdr Elf_Phdr; typedef Elf32_Shdr Elf_Shdr; typedef Elf32_Sym Elf_Sym; typedef Elf32_Dyn Elf_Dyn; typedef Elf32_Rel Elf_Rel; typedef Elf32_Rela Elf_Rela;typedef
Elf32_AddrElf_Addr;#elif
ELF_CLASS== ELFCLASS64typedef Elf64_Ehdr Elf_Ehdr; typedef Elf64_Phdr Elf_Phdr; typedef Elf64_Shdr Elf_Shdr; typedef Elf64_Sym Elf_Sym; typedef Elf64_Dyn Elf_Dyn; typedef Elf64_Rel Elf_Rel; typedef Elf64_Rela Elf_Rela;
Quoted 6 lines
typedef
Elf64_AddrElf_Addr;#else
#error
#endif
Yes, but it does get a bit subtle. x86-64 does strange things with redefining the ELF class to compile a 32-bit binfmt_elf, and I think other architectures play similar games. Rearranging these headers is pretty fragile, and I think my approach is a bit less likely to (possibly) break things. But I haven't cross-compiled all the architectures, so I may have broken stuff anyway.
Quoted 2 lines
The patch does help you quite a bit, you don't have to cleanup
elf.hso it's usable by the whole kernel. Only few parts now really need it and depend on it, which makes the extensive splitup unnecessary only to reduce header dependencies.
Yes, but only for the module.h case. My concerns are wider.
J
Quoted 8 lines · Jeremy Fitzhardinge
Quoted 4 lines · Roman Zippel
The problem I have is that you want to separate _all_ constants, which doesn't really make sense to me, because many of them are useless without the correspending structures.
It seems cleanest to just put all the constants in one place rather than scatter them around based on how they happen to be used.
Grouping related things together is always a good approach. But the right factor should be used for the grouping. For the ELF file is would from a usage perspective be natural to have constants close to the definition that they are used to describe. Having constants grouped with other constants just _because_ they are constants does not cut here.
Sam
Quoted 5 lines · Sam Ravnborg
Grouping related things together is always a good approach. But the right factor should be used for the grouping. For the ELF file is would from a usage perspective be natural to have constants close to the definition that they are used to describe. Having constants grouped with other constants just _because_ they are constants does not cut here.
Many ELF constants are used without direct reference to their corresponding structures. My linux/elf-const.h header is just a generalization of the existing linux/elf-em.h header, which just contained the ELF EM_* constants. Given that there seems to be a preexisting need for the EM_* constants in a separate header, and having a separate elf-*.h for each group of constants is a bad idea, it seemed to me that elf-const.h was the appropriate direction to take.
J
Hi,
Quoted 1 line · Jeremy Fitzhardinge
linux/elf-const.h- ELF constants, includable by asm code
BTW who's the maniac who tries to use this in asm code? Many of these constants are pretty useless without the corresponding structure definitions.
bye, Roman
Quoted 5 lines · Roman Zippel
Quoted 2 lines
linux/elf-const.h- ELF constants, includable by asm codeBTW who's the maniac who tries to use this in asm code?
Many of these constants are pretty useless without the corresponding structure definitions.
I was for a while, in order to hand-craft ELF headers for the bzImage boot image, but I since changed it to define these structures from C. Still, its useful to have the constants separate, since they are used separate from their corresponding structures.
J
Quoted 4 lines · Jeremy Fitzhardinge
powerpc also appears to have its own duplicate copy of
elf.hinarch/powerpc/boot/elf.h; presumably because the standardelf.hbrings in too much. Update it to justlinux/elf-defn.h, which should be fine.
No, it's because the bootwrapper is not part of the kernel and does not use kernel headers. The aim is that the bootwrapper can be built and used outside the kernel source tree, so it needs its own copies of any headers that aren't in /usr/include.
Paul.
Quoted 5 lines · Paul Mackerras
No, it's because the bootwrapper is not part of the kernel and does not use kernel headers. The aim is that the bootwrapper can be built and used outside the kernel source tree, so it needs its own copies of any headers that aren't in
/usr/include.
Hm, I see. But <elf.h> is generally available, isn't it?
J
arch/powerpc/platforms/cell/io-workarounds.c line 12
Quoted 8 lines · Jeremy Fitzhardinge
===================================================================
arch/powerpc/platforms/cell/io-workarounds.c +1
-0@@ -9,6 +9,7 @@#undef DEBUG#include <linux/kernel.h> +#include <linux/sched.h>
Why is this needed? You've added #include <linux/sched.h> to 7 files without explanation - and I can't see that you have removed a corresponding #include from any header, have you?
Paul.
Quoted 6 lines · Paul Mackerras
Quoted 6 lines
===================================================================
arch/powerpc/platforms/cell/io-workarounds.c +0
-0@@ -9,6 +9,7 @@#undef DEBUG
Quoted 8 lines
arch/powerpc/platforms/cell/io-workarounds.c line 13
Quoted 3 lines
arch/powerpc/platforms/cell/io-workarounds.c +1
-0#include <linux/kernel.h> +#include <linux/sched.h> Why is this needed? You've added #include <
linux/sched.h> to 7 files without explanation - and I can't see that you have removed a corresponding #include from any header, have you?
asm-powerpc/elf.h included sched.h, and it in turn was being included by something else. With the cleanups in this patch, asm-powerpc/elf.h is no longer being included, so io-workarounds.c needs kernel/sched.h for a declaration of init_mm.
Similarly with the others; they all failed to compile without linux/sched.h.
J