ia64/linux-2.6.18-xen.hg

changeset 16:b450c13522c8

Imported patch x86-put-note-sections-into-a-pt_note-segment-in-vmlinux.patch from xen-unstable.hg 15200:bd3d6b4c52ec
author Ian Campbell <ian.campbell@xensource.com>
date Mon Jun 04 10:05:24 2007 +0100 (2007-06-04)
parents 132f24200f4c
children 3cb68e3808a4
files arch/i386/kernel/vmlinux.lds.S include/asm-generic/vmlinux.lds.h include/linux/elfnote.h
line diff
     1.1 --- a/arch/i386/kernel/vmlinux.lds.S	Mon Jun 04 10:05:24 2007 +0100
     1.2 +++ b/arch/i386/kernel/vmlinux.lds.S	Mon Jun 04 10:05:24 2007 +0100
     1.3 @@ -13,6 +13,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 @@ -26,7 +32,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 @@ -48,7 +54,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 @@ -184,4 +190,6 @@ SECTIONS
    1.35    STABS_DEBUG
    1.36  
    1.37    DWARF_DEBUG
    1.38 +
    1.39 +  NOTES
    1.40  }
     2.1 --- a/include/asm-generic/vmlinux.lds.h	Mon Jun 04 10:05:24 2007 +0100
     2.2 +++ b/include/asm-generic/vmlinux.lds.h	Mon Jun 04 10:05:24 2007 +0100
     2.3 @@ -194,3 +194,6 @@
     2.4  		.stab.index 0 : { *(.stab.index) }			\
     2.5  		.stab.indexstr 0 : { *(.stab.indexstr) }		\
     2.6  		.comment 0 : { *(.comment) }
     2.7 +
     2.8 +#define NOTES								\
     2.9 +		.notes : { *(.note.*) } :note
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/include/linux/elfnote.h	Mon Jun 04 10:05:24 2007 +0100
     3.3 @@ -0,0 +1,88 @@
     3.4 +#ifndef _LINUX_ELFNOTE_H
     3.5 +#define _LINUX_ELFNOTE_H
     3.6 +/*
     3.7 + * Helper macros to generate ELF Note structures, which are put into a
     3.8 + * PT_NOTE segment of the final vmlinux image.  These are useful for
     3.9 + * including name-value pairs of metadata into the kernel binary (or
    3.10 + * modules?) for use by external programs.
    3.11 + *
    3.12 + * Each note has three parts: a name, a type and a desc.  The name is
    3.13 + * intended to distinguish the note's originator, so it would be a
    3.14 + * company, project, subsystem, etc; it must be in a suitable form for
    3.15 + * use in a section name.  The type is an integer which is used to tag
    3.16 + * the data, and is considered to be within the "name" namespace (so
    3.17 + * "FooCo"'s type 42 is distinct from "BarProj"'s type 42).  The
    3.18 + * "desc" field is the actual data.  There are no constraints on the
    3.19 + * desc field's contents, though typically they're fairly small.
    3.20 + *
    3.21 + * All notes from a given NAME are put into a section named
    3.22 + * .note.NAME.  When the kernel image is finally linked, all the notes
    3.23 + * are packed into a single .notes section, which is mapped into the
    3.24 + * PT_NOTE segment.  Because notes for a given name are grouped into
    3.25 + * the same section, they'll all be adjacent the output file.
    3.26 + *
    3.27 + * This file defines macros for both C and assembler use.  Their
    3.28 + * syntax is slightly different, but they're semantically similar.
    3.29 + *
    3.30 + * See the ELF specification for more detail about ELF notes.
    3.31 + */
    3.32 +
    3.33 +#ifdef __ASSEMBLER__
    3.34 +/*
    3.35 + * Generate a structure with the same shape as Elf{32,64}_Nhdr (which
    3.36 + * turn out to be the same size and shape), followed by the name and
    3.37 + * desc data with appropriate padding.  The 'desc' argument includes
    3.38 + * the assembler pseudo op defining the type of the data: .asciz
    3.39 + * "hello, world"
    3.40 + */
    3.41 +.macro ELFNOTE name type desc:vararg
    3.42 +.pushsection ".note.\name"
    3.43 +  .align 4
    3.44 +  .long 2f - 1f			/* namesz */
    3.45 +  .long 4f - 3f			/* descsz */
    3.46 +  .long \type
    3.47 +1:.asciz "\name"
    3.48 +2:.align 4
    3.49 +3:\desc
    3.50 +4:.align 4
    3.51 +.popsection
    3.52 +.endm
    3.53 +#else	/* !__ASSEMBLER__ */
    3.54 +#include <linux/elf.h>
    3.55 +/*
    3.56 + * Use an anonymous structure which matches the shape of
    3.57 + * Elf{32,64}_Nhdr, but includes the name and desc data.  The size and
    3.58 + * type of name and desc depend on the macro arguments.  "name" must
    3.59 + * be a literal string, and "desc" must be passed by value.  You may
    3.60 + * only define one note per line, since __LINE__ is used to generate
    3.61 + * unique symbols.
    3.62 + */
    3.63 +#define _ELFNOTE_PASTE(a,b)	a##b
    3.64 +#define _ELFNOTE(size, name, unique, type, desc)			\
    3.65 +	static const struct {						\
    3.66 +		struct elf##size##_note _nhdr;				\
    3.67 +		unsigned char _name[sizeof(name)]			\
    3.68 +		__attribute__((aligned(sizeof(Elf##size##_Word))));	\
    3.69 +		typeof(desc) _desc					\
    3.70 +			     __attribute__((aligned(sizeof(Elf##size##_Word)))); \
    3.71 +	} _ELFNOTE_PASTE(_note_, unique)				\
    3.72 +		__attribute_used__					\
    3.73 +		__attribute__((section(".note." name),			\
    3.74 +			       aligned(sizeof(Elf##size##_Word)),	\
    3.75 +			       unused)) = {				\
    3.76 +		{							\
    3.77 +			sizeof(name),					\
    3.78 +			sizeof(desc),					\
    3.79 +			type,						\
    3.80 +		},							\
    3.81 +		name,							\
    3.82 +		desc							\
    3.83 +	}
    3.84 +#define ELFNOTE(size, name, type, desc)		\
    3.85 +	_ELFNOTE(size, name, __LINE__, type, desc)
    3.86 +
    3.87 +#define ELFNOTE32(name, type, desc) ELFNOTE(32, name, type, desc)
    3.88 +#define ELFNOTE64(name, type, desc) ELFNOTE(64, name, type, desc)
    3.89 +#endif	/* __ASSEMBLER__ */
    3.90 +
    3.91 +#endif /* _LINUX_ELFNOTE_H */