1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/* annobin - Header file for the gcc plugin for annotating binary files.
Copyright (c) 2017 - 2019 Red Hat.
Created by Nick Clifton.
This is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3, or (at your
option) any later version.
It is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. */
#ifndef TREE_ANNOBIN
#define TREE_ANNOBIN
/* TODO: replace with host-target width */
#include <elf.h>
/* The version of the annotation specification supported by this plugin. */
#define SPEC_VERSION 3
#if 0 /* This would be the correct thing to do if elf/common.h did not conflict with elf.h. */
#include "elf/common.h"
#else
#define SHF_GNU_BUILD_NOTE (1 << 20) /* Section contains GNU BUILD ATTRIBUTE notes. */
#define NT_GNU_PROPERTY_TYPE_0 5 /* Generated by gcc. */
#define NT_GNU_BUILD_ATTRIBUTE_OPEN 0x100
#define NT_GNU_BUILD_ATTRIBUTE_FUNC 0x101
#define GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC '*'
#define GNU_BUILD_ATTRIBUTE_TYPE_STRING '$'
#define GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE '+'
#define GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE '!'
#define GNU_BUILD_ATTRIBUTE_VERSION 1
#define GNU_BUILD_ATTRIBUTE_STACK_PROT 2
#define GNU_BUILD_ATTRIBUTE_RELRO 3
#define GNU_BUILD_ATTRIBUTE_STACK_SIZE 4
#define GNU_BUILD_ATTRIBUTE_TOOL 5
#define GNU_BUILD_ATTRIBUTE_ABI 6
#define GNU_BUILD_ATTRIBUTE_PIC 7
#define GNU_BUILD_ATTRIBUTE_SHORT_ENUM 8
#define GNU_BUILD_ATTRIBUTE_NO_SANITIZE 9
#define NOTE_GNU_PROPERTY_SECTION_NAME ".note.gnu.property"
#define GNU_BUILD_ATTRS_SECTION_NAME ".gnu.build.attributes"
/* Values used in GNU .note.gnu.property notes (NT_GNU_PROPERTY_TYPE_0). */
#define GNU_PROPERTY_STACK_SIZE 1
#define GNU_PROPERTY_NO_COPY_ON_PROTECTED 2
#define GNU_PROPERTY_COMPILER_FLAGS 32
/* Bit masks for compiler flags: */
/* Pre/post cxx11 ABI. */
#define GNU_PROPERTY_USECXX_VALIDATION (1U << 0)
#define GNU_PROPERTY_USECXX11_ABI (1U << 1)
/* Sanitizer flags. */
#define GNU_PROPERTY_SANITIZE_VALIDATION (1U << 2)
#define GNU_PROPERTY_SANITIZE_ADDRESS (1U << 3)
#define GNU_PROPERTY_SANITIZE_UNDEFINED (1U << 4)
#define GNU_PROPERTY_SANITIZE_THREAD (1U << 5)
#endif /* Copy of elf/common.h */
typedef struct
{
Elf32_Word pr_type;
Elf32_Word pr_datasz;
Elf32_Word pr_data;
} Elf32_loader_note;
typedef struct
{
Elf32_Word pr_type;
Elf32_Word pr_datasz;
Elf64_Xword pr_data;
} Elf64_loader_note;
typedef struct
{
Elf32_Word pr_type;
Elf32_Word pr_datasz;
Elf32_Word pr_data;
Elf32_Word pr_pad;
} Elf64_32_loader_note;
/* Called during plugin_init(). */
extern void annobin_save_target_specific_information (void);
/* Called during PLUGIN_START_UNIT.
Should only produce notes for the static tools, ie
notes in the SECNAME section. */
extern void annobin_record_global_target_notes (const char * SECNAME);
/* Called during PLUGIN_ALL_PASSES_START.
Should produce notes specific to the function just compiled.
Should only produce notes for the static tools, ie
notes in the .gnu.build.attributes section.
Arguments are the START and END symbols for the function,
the name of the note SECTION into which the notes should be
placed and a boolean indicating if it is necessary to FORCE
the generation of notes even if nothing has changed. */
extern void annobin_target_specific_function_notes (const char * START,
const char * END,
const char * SECTION,
bool FORCE);
/* Called during PLUGIN_FINISH_UNIT.
Should only produce notes for the dynamic loader, ie
notes in the .note.gnu.property section. */
extern void annobin_target_specific_loader_notes (void);
/* Called during plugin_init ().
Returns the bias, if any, that should be applied to
the start symbol in order for it to avoid conflicts
with file symbols and/or the first function symbol. */
extern signed int annobin_target_start_symbol_bias (void);
extern void annobin_assemble_start_function_notes ();
extern void annobin_assemble_end_function_notes ();
/* Generate final annobin annotations. */
extern void annobin_finish_file ();
extern void annobin_search_abi_declaration (tree decl);
/* Declare initial static sections for now, compute flags. */
extern void annobin_init ();
/* Check if binary annotations are enabled. */
static inline bool
annobin_enable_p (void)
{
return (flag_annotate_binary != ANNOBIN_NONE);
}
/* Check if .note.gnu.property annotations are enabled. */
static inline bool
annobin_dynamic_notes_p (void)
{
return (flag_annotate_binary & ANNOBIN_DYNAMIC_NOTES);
}
/* Check if .gnu.build.attributes annotations are enabled. */
static inline bool
annobin_static_notes_p (void)
{
return (flag_annotate_binary & ANNOBIN_STATIC_NOTES);
}
#endif /* TREE_ANNOBIN */
|