direct-io.hg

changeset 11223:a4550b748840

[LINUX] Support creating ELF note segments in the kernel ELF image.

i386 version is taken from 2.6.18-rc4-mm1 and x86_64 version has been
submitted for inclusion.

Signed-off-by: Ian Campbell <ian.campbell@xensource.com>
author Ian Campbell <ian.campbell@xensource.com>
date Tue Aug 22 12:20:43 2006 +0100 (2006-08-22)
parents cd4e7ace4e58
children b688d4a68a3e
files linux-2.6-xen-sparse/arch/i386/kernel/vmlinux.lds.S patches/linux-2.6.16.13/series patches/linux-2.6.16.13/x86-put-note-sections-into-a-pt_note-segment-in-vmlinux.patch patches/linux-2.6.16.13/x86_64-put-note-sections-into-a-pt_note-segment-in-vmlinux.patch
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/vmlinux.lds.S	Tue Aug 22 11:34:46 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/vmlinux.lds.S	Tue Aug 22 12:20:43 2006 +0100
     1.3 @@ -12,6 +12,12 @@ OUTPUT_FORMAT("elf32-i386", "elf32-i386"
     1.4  OUTPUT_ARCH(i386)
     1.5  ENTRY(phys_startup_32)
     1.6  jiffies = jiffies_64;
     1.7 +
     1.8 +PHDRS {
     1.9 +	text PT_LOAD FLAGS(5);	/* R_E */
    1.10 +	data PT_LOAD FLAGS(7);	/* RWE */
    1.11 +	note PT_NOTE FLAGS(4);	/* R__ */
    1.12 +}
    1.13  SECTIONS
    1.14  {
    1.15    . = __KERNEL_START;
    1.16 @@ -25,7 +31,7 @@ SECTIONS
    1.17  	KPROBES_TEXT
    1.18  	*(.fixup)
    1.19  	*(.gnu.warning)
    1.20 -	} = 0x9090
    1.21 +	} :text = 0x9090
    1.22  
    1.23    _etext = .;			/* End of text section */
    1.24  
    1.25 @@ -47,7 +53,7 @@ SECTIONS
    1.26    .data : AT(ADDR(.data) - LOAD_OFFSET) {	/* Data */
    1.27  	*(.data)
    1.28  	CONSTRUCTORS
    1.29 -	}
    1.30 +	} :data
    1.31  
    1.32    . = ALIGN(4096);
    1.33    __nosave_begin = .;
    1.34 @@ -154,4 +160,6 @@ SECTIONS
    1.35    STABS_DEBUG
    1.36  
    1.37    DWARF_DEBUG
    1.38 +
    1.39 +  NOTES
    1.40  }
     2.1 --- a/patches/linux-2.6.16.13/series	Tue Aug 22 11:34:46 2006 +0100
     2.2 +++ b/patches/linux-2.6.16.13/series	Tue Aug 22 12:20:43 2006 +0100
     2.3 @@ -18,3 +18,5 @@ tpm_plugin_2.6.17.patch
     2.4  x86-increase-interrupt-vector-range.patch
     2.5  xen-hotplug.patch
     2.6  xenoprof-generic.patch
     2.7 +x86-put-note-sections-into-a-pt_note-segment-in-vmlinux.patch
     2.8 +x86_64-put-note-sections-into-a-pt_note-segment-in-vmlinux.patch
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/patches/linux-2.6.16.13/x86-put-note-sections-into-a-pt_note-segment-in-vmlinux.patch	Tue Aug 22 12:20:43 2006 +0100
     3.3 @@ -0,0 +1,174 @@
     3.4 +Taken from 2.6.18-rc4-mm1.
     3.5 +
     3.6 +From: Jeremy Fitzhardinge <jeremy@xensource.com>
     3.7 +
     3.8 +This patch will pack any .note.* section into a PT_NOTE segment in the output
     3.9 +file.
    3.10 +
    3.11 +To do this, we tell ld that we need a PT_NOTE segment.  This requires us to
    3.12 +start explicitly mapping sections to segments, so we also need to explicitly
    3.13 +create PT_LOAD segments for text and data, and map the sections to them
    3.14 +appropriately.  Fortunately, each section will default to its previous
    3.15 +section's segment, so it doesn't take many changes to vmlinux.lds.S.
    3.16 +
    3.17 +This only changes i386 for now, but I presume the corresponding changes for
    3.18 +other architectures will be as simple.
    3.19 +
    3.20 +This change also adds <linux/elfnote.h>, which defines C and Assembler macros
    3.21 +for actually creating ELF notes.
    3.22 +
    3.23 +Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
    3.24 +Cc: Eric W. Biederman <ebiederm@xmission.com>
    3.25 +Cc: Hollis Blanchard <hollisb@us.ibm.com>
    3.26 +Signed-off-by: Andrew Morton <akpm@osdl.org>
    3.27 +---
    3.28 +
    3.29 + arch/i386/kernel/vmlinux.lds.S    |   12 +++
    3.30 + include/asm-generic/vmlinux.lds.h |    3 
    3.31 + include/linux/elfnote.h           |   88 ++++++++++++++++++++++++++++
    3.32 + 3 files changed, 101 insertions(+), 2 deletions(-)
    3.33 +
    3.34 +diff -puN arch/i386/kernel/vmlinux.lds.S~x86-put-note-sections-into-a-pt_note-segment-in-vmlinux arch/i386/kernel/vmlinux.lds.S
    3.35 +--- a/arch/i386/kernel/vmlinux.lds.S~x86-put-note-sections-into-a-pt_note-segment-in-vmlinux
    3.36 ++++ a/arch/i386/kernel/vmlinux.lds.S
    3.37 +@@ -13,6 +13,12 @@ OUTPUT_FORMAT("elf32-i386", "elf32-i386"
    3.38 + OUTPUT_ARCH(i386)
    3.39 + ENTRY(phys_startup_32)
    3.40 + jiffies = jiffies_64;
    3.41 ++
    3.42 ++PHDRS {
    3.43 ++	text PT_LOAD FLAGS(5);	/* R_E */
    3.44 ++	data PT_LOAD FLAGS(7);	/* RWE */
    3.45 ++	note PT_NOTE FLAGS(4);	/* R__ */
    3.46 ++}
    3.47 + SECTIONS
    3.48 + {
    3.49 +   . = __KERNEL_START;
    3.50 +@@ -26,7 +32,7 @@ SECTIONS
    3.51 + 	KPROBES_TEXT
    3.52 + 	*(.fixup)
    3.53 + 	*(.gnu.warning)
    3.54 +-	} = 0x9090
    3.55 ++	} :text = 0x9090
    3.56 + 
    3.57 +   _etext = .;			/* End of text section */
    3.58 + 
    3.59 +@@ -50,7 +56,7 @@ SECTIONS
    3.60 +   .data : AT(ADDR(.data) - LOAD_OFFSET) {	/* Data */
    3.61 + 	*(.data)
    3.62 + 	CONSTRUCTORS
    3.63 +-	}
    3.64 ++	} :data
    3.65 + 
    3.66 +   . = ALIGN(4096);
    3.67 +   __nosave_begin = .;
    3.68 +@@ -186,4 +192,6 @@ SECTIONS
    3.69 +   STABS_DEBUG
    3.70 + 
    3.71 +   DWARF_DEBUG
    3.72 ++
    3.73 ++  NOTES
    3.74 + }
    3.75 +diff -puN include/asm-generic/vmlinux.lds.h~x86-put-note-sections-into-a-pt_note-segment-in-vmlinux include/asm-generic/vmlinux.lds.h
    3.76 +--- a/include/asm-generic/vmlinux.lds.h~x86-put-note-sections-into-a-pt_note-segment-in-vmlinux
    3.77 ++++ a/include/asm-generic/vmlinux.lds.h
    3.78 +@@ -194,3 +194,6 @@
    3.79 + 		.stab.index 0 : { *(.stab.index) }			\
    3.80 + 		.stab.indexstr 0 : { *(.stab.indexstr) }		\
    3.81 + 		.comment 0 : { *(.comment) }
    3.82 ++
    3.83 ++#define NOTES								\
    3.84 ++		.notes : { *(.note.*) } :note
    3.85 +diff -puN /dev/null include/linux/elfnote.h
    3.86 +--- /dev/null
    3.87 ++++ a/include/linux/elfnote.h
    3.88 +@@ -0,0 +1,88 @@
    3.89 ++#ifndef _LINUX_ELFNOTE_H
    3.90 ++#define _LINUX_ELFNOTE_H
    3.91 ++/*
    3.92 ++ * Helper macros to generate ELF Note structures, which are put into a
    3.93 ++ * PT_NOTE segment of the final vmlinux image.  These are useful for
    3.94 ++ * including name-value pairs of metadata into the kernel binary (or
    3.95 ++ * modules?) for use by external programs.
    3.96 ++ *
    3.97 ++ * Each note has three parts: a name, a type and a desc.  The name is
    3.98 ++ * intended to distinguish the note's originator, so it would be a
    3.99 ++ * company, project, subsystem, etc; it must be in a suitable form for
   3.100 ++ * use in a section name.  The type is an integer which is used to tag
   3.101 ++ * the data, and is considered to be within the "name" namespace (so
   3.102 ++ * "FooCo"'s type 42 is distinct from "BarProj"'s type 42).  The
   3.103 ++ * "desc" field is the actual data.  There are no constraints on the
   3.104 ++ * desc field's contents, though typically they're fairly small.
   3.105 ++ *
   3.106 ++ * All notes from a given NAME are put into a section named
   3.107 ++ * .note.NAME.  When the kernel image is finally linked, all the notes
   3.108 ++ * are packed into a single .notes section, which is mapped into the
   3.109 ++ * PT_NOTE segment.  Because notes for a given name are grouped into
   3.110 ++ * the same section, they'll all be adjacent the output file.
   3.111 ++ *
   3.112 ++ * This file defines macros for both C and assembler use.  Their
   3.113 ++ * syntax is slightly different, but they're semantically similar.
   3.114 ++ *
   3.115 ++ * See the ELF specification for more detail about ELF notes.
   3.116 ++ */
   3.117 ++
   3.118 ++#ifdef __ASSEMBLER__
   3.119 ++/*
   3.120 ++ * Generate a structure with the same shape as Elf{32,64}_Nhdr (which
   3.121 ++ * turn out to be the same size and shape), followed by the name and
   3.122 ++ * desc data with appropriate padding.  The 'desc' argument includes
   3.123 ++ * the assembler pseudo op defining the type of the data: .asciz
   3.124 ++ * "hello, world"
   3.125 ++ */
   3.126 ++.macro ELFNOTE name type desc:vararg
   3.127 ++.pushsection ".note.\name"
   3.128 ++  .align 4
   3.129 ++  .long 2f - 1f			/* namesz */
   3.130 ++  .long 4f - 3f			/* descsz */
   3.131 ++  .long \type
   3.132 ++1:.asciz "\name"
   3.133 ++2:.align 4
   3.134 ++3:\desc
   3.135 ++4:.align 4
   3.136 ++.popsection
   3.137 ++.endm
   3.138 ++#else	/* !__ASSEMBLER__ */
   3.139 ++#include <linux/elf.h>
   3.140 ++/*
   3.141 ++ * Use an anonymous structure which matches the shape of
   3.142 ++ * Elf{32,64}_Nhdr, but includes the name and desc data.  The size and
   3.143 ++ * type of name and desc depend on the macro arguments.  "name" must
   3.144 ++ * be a literal string, and "desc" must be passed by value.  You may
   3.145 ++ * only define one note per line, since __LINE__ is used to generate
   3.146 ++ * unique symbols.
   3.147 ++ */
   3.148 ++#define _ELFNOTE_PASTE(a,b)	a##b
   3.149 ++#define _ELFNOTE(size, name, unique, type, desc)			\
   3.150 ++	static const struct {						\
   3.151 ++		struct elf##size##_note _nhdr;				\
   3.152 ++		unsigned char _name[sizeof(name)]			\
   3.153 ++		__attribute__((aligned(sizeof(Elf##size##_Word))));	\
   3.154 ++		typeof(desc) _desc					\
   3.155 ++			     __attribute__((aligned(sizeof(Elf##size##_Word)))); \
   3.156 ++	} _ELFNOTE_PASTE(_note_, unique)				\
   3.157 ++		__attribute_used__					\
   3.158 ++		__attribute__((section(".note." name),			\
   3.159 ++			       aligned(sizeof(Elf##size##_Word)),	\
   3.160 ++			       unused)) = {				\
   3.161 ++		{							\
   3.162 ++			sizeof(name),					\
   3.163 ++			sizeof(desc),					\
   3.164 ++			type,						\
   3.165 ++		},							\
   3.166 ++		name,							\
   3.167 ++		desc							\
   3.168 ++	}
   3.169 ++#define ELFNOTE(size, name, type, desc)		\
   3.170 ++	_ELFNOTE(size, name, __LINE__, type, desc)
   3.171 ++
   3.172 ++#define ELFNOTE32(name, type, desc) ELFNOTE(32, name, type, desc)
   3.173 ++#define ELFNOTE64(name, type, desc) ELFNOTE(64, name, type, desc)
   3.174 ++#endif	/* __ASSEMBLER__ */
   3.175 ++
   3.176 ++#endif /* _LINUX_ELFNOTE_H */
   3.177 +_
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/patches/linux-2.6.16.13/x86_64-put-note-sections-into-a-pt_note-segment-in-vmlinux.patch	Tue Aug 22 12:20:43 2006 +0100
     4.3 @@ -0,0 +1,40 @@
     4.4 +diff -urN ref-linux-2.6.16.13/arch/x86_64/kernel/vmlinux.lds.S x86-64_elfnotes/arch/x86_64/kernel/vmlinux.lds.S
     4.5 +--- ref-linux-2.6.16.13/arch/x86_64/kernel/vmlinux.lds.S	2006-05-02 22:38:44.000000000 +0100
     4.6 ++++ x86-64_elfnotes/arch/x86_64/kernel/vmlinux.lds.S	2006-08-22 11:39:14.000000000 +0100
     4.7 +@@ -14,6 +14,11 @@
     4.8 + OUTPUT_ARCH(i386:x86-64)
     4.9 + ENTRY(phys_startup_64)
    4.10 + jiffies_64 = jiffies;
    4.11 ++PHDRS {
    4.12 ++	text PT_LOAD FLAGS(5);	/* R_E */
    4.13 ++	data PT_LOAD FLAGS(7);	/* RWE */
    4.14 ++	note PT_NOTE FLAGS(4);	/* R__ */
    4.15 ++}
    4.16 + SECTIONS
    4.17 + {
    4.18 +   . = __START_KERNEL;
    4.19 +@@ -26,7 +31,7 @@
    4.20 + 	KPROBES_TEXT
    4.21 + 	*(.fixup)
    4.22 + 	*(.gnu.warning)
    4.23 +-	} = 0x9090
    4.24 ++	} :text = 0x9090
    4.25 +   				/* out-of-line lock text */
    4.26 +   .text.lock : AT(ADDR(.text.lock) - LOAD_OFFSET) { *(.text.lock) }
    4.27 + 
    4.28 +@@ -43,7 +48,7 @@
    4.29 +   .data : AT(ADDR(.data) - LOAD_OFFSET) {
    4.30 + 	*(.data)
    4.31 + 	CONSTRUCTORS
    4.32 +-	}
    4.33 ++	} :data
    4.34 + 
    4.35 +   _edata = .;			/* End of data section */
    4.36 + 
    4.37 +@@ -201,4 +206,6 @@
    4.38 +   STABS_DEBUG
    4.39 + 
    4.40 +   DWARF_DEBUG
    4.41 ++
    4.42 ++  NOTES
    4.43 + }