1 /* SPDX-License-Identifier: GPL-2.0 */ 1 2 #ifndef _LINUX_ELFNOTE_H 3 #define _LINUX_ELFNOTE_H 4 /* 5 * Helper macros to generate ELF Note structur 6 * PT_NOTE segment of the final vmlinux image. 7 * including name-value pairs of metadata into 8 * modules?) for use by external programs. 9 * 10 * Each note has three parts: a name, a type a 11 * intended to distinguish the note's originat 12 * company, project, subsystem, etc; it must b 13 * use in a section name. The type is an inte 14 * the data, and is considered to be within th 15 * "FooCo"'s type 42 is distinct from "BarProj 16 * "desc" field is the actual data. There are 17 * desc field's contents, though typically the 18 * 19 * All notes from a given NAME are put into a 20 * .note.NAME. When the kernel image is final 21 * are packed into a single .notes section, wh 22 * PT_NOTE segment. Because notes for a given 23 * the same section, they'll all be adjacent t 24 * 25 * This file defines macros for both C and ass 26 * syntax is slightly different, but they're s 27 * 28 * See the ELF specification for more detail a 29 */ 30 31 #ifdef __ASSEMBLER__ 32 /* 33 * Generate a structure with the same shape as 34 * turn out to be the same size and shape), fo 35 * desc data with appropriate padding. The 'd 36 * assembler pseudo op defining the type of th 37 * 'descdata' is the data itself e.g. "hello, 38 * 39 * e.g. ELFNOTE(XYZCo, 42, .asciz, "forty-two" 40 * ELFNOTE(XYZCo, 12, .long, 0xdeadbeef) 41 */ 42 #define ELFNOTE_START(name, type, flags) 43 .pushsection .note.name, flags,@note ; 44 .balign 4 ; 45 .long 2f - 1f /* namesz */ ; 46 .long 4484f - 3f /* descsz */ ; 47 .long type ; 48 1:.asciz #name ; 49 2:.balign 4 ; 50 3: 51 52 #define ELFNOTE_END 53 4484:.balign 4 ; 54 .popsection ; 55 56 #define ELFNOTE(name, type, desc) 57 ELFNOTE_START(name, type, "a") 58 desc ; 59 ELFNOTE_END 60 61 #else /* !__ASSEMBLER__ */ 62 #include <uapi/linux/elf.h> 63 /* 64 * Use an anonymous structure which matches th 65 * Elf{32,64}_Nhdr, but includes the name and 66 * type of name and desc depend on the macro a 67 * be a literal string, and "desc" must be pas 68 * only define one note per line, since __LINE 69 * unique symbols. 70 */ 71 #define _ELFNOTE_PASTE(a,b) a##b 72 #define _ELFNOTE(size, name, unique, type, des 73 static const struct { 74 struct elf##size##_note _nhdr; 75 unsigned char _name[sizeof(nam 76 __attribute__((aligned(sizeof( 77 typeof(desc) _desc 78 __attribute__((al 79 } _ELFNOTE_PASTE(_note_, unique) 80 __used 81 __attribute__((section(".note. 82 aligned(sizeof( 83 unused)) = { 84 { 85 sizeof(name), 86 sizeof(desc), 87 type, 88 }, 89 name, 90 desc 91 } 92 #define ELFNOTE(size, name, type, desc) 93 _ELFNOTE(size, name, __LINE__, type, d 94 95 #define ELFNOTE32(name, type, desc) ELFNOTE(32 96 #define ELFNOTE64(name, type, desc) ELFNOTE(64 97 #endif /* __ASSEMBLER__ */ 98 99 #endif /* _LINUX_ELFNOTE_H */ 100
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.