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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
|
/* elf-os-gnu.pk - ELF GNU specific definitions. */
/* Copyright (C) 2024 Jose E. Marchesi. */
/* This program 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 of the License, or
* (at your option) any later version.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* The GNU ABI is documented at https://sourceware.org/gnu-gabi */
/* GNU segment types. */
var ELF_PT_GNU_EH_FRAME = 0x6474e550U,
ELF_PT_GNU_STACK = 0x6474e551U,
ELF_PT_GNU_RELRO = 0x6474e552U,
ELF_PT_GNU_PROPERTY = 0x6474e553U;
elf_config.add_enum
:class "segment-types"
:entries [Elf_Config_UInt { value = ELF_PT_GNU_EH_FRAME, name = "gnu-eh-frame" },
Elf_Config_UInt { value = ELF_PT_GNU_STACK, name = "gnu-stack" },
Elf_Config_UInt { value = ELF_PT_GNU_RELRO, name = "gnu-relro" },
Elf_Config_UInt { value = ELF_PT_GNU_PROPERTY, name = "gnu-property" }];
/* GNU section types. */
var ELF_SHT_GNU_INCREMENTAL_INPUTS = 0x6fff_4700U,
ELF_SHT_GNU_ATTRIBUTES = 0x6fff_fff5U,
ELF_SHT_GNU_HASH = 0x6fff_fff6U,
ELF_SHT_GNU_LIBLIST = 0x6fff_fff7U,
ELF_SHT_GNU_VERDEF = 0x6fff_fffdU,
ELF_SHT_GNU_VERNEED = 0x6fff_fffeU,
ELF_SHT_GNU_VERSYM = 0x6fff_ffffU;
elf_config.add_enum
:class "section-types"
:entries [Elf_Config_UInt { value = ELF_SHT_GNU_INCREMENTAL_INPUTS, name = "gnu-incremental-inputs" },
Elf_Config_UInt { value = ELF_SHT_GNU_ATTRIBUTES, name = "gnu-attributes" },
Elf_Config_UInt { value = ELF_SHT_GNU_HASH, name = "gnu-hash" },
Elf_Config_UInt { value = ELF_SHT_GNU_LIBLIST, name = "gnu-liblist" },
Elf_Config_UInt { value = ELF_SHT_GNU_VERDEF, name = "gnu-verdef" },
Elf_Config_UInt { value = ELF_SHT_GNU_VERNEED, name = "gnu-verneed" },
Elf_Config_UInt { value = ELF_SHT_GNU_VERSYM, name = "gnu-versym" }];
/* GNU Dynamic tags. */
var ELF_DT_GNU_HASH = 0x6fff_fef5U,
ELF_DT_VERSYM = 0x6fff_fff0U,
ELF_DT_FLAGS_1 = 0x6fff_fffbU,
ELF_DT_VERDEF = 0x6fff_fffcU,
ELF_DT_GNU_PRELINKED = 0x6ffffdf5U,
ELF_DT_GNU_CONFLICTSZ = 0x6ffffdf6U,
ELF_DT_TLSDESC_PLT = 0x6ffffef6U,
ELF_DT_TLSDESC_GOT = 0x6ffffef7U,
ELF_DT_GNU_CONFLICT = 0x6ffffef8U,
ELF_DT_GNU_LIBLIST= 0x6ffffef9U,
ELF_DT_CONFIG = 0x6ffffefaU,
ELF_DT_DEPAUDIT = 0x6ffffefbU,
ELF_DT_AUDIT = 0x6ffffefcU,
ELF_DT_PLTPAD = 0x6ffffefdU,
ELF_DT_MOVETAB = 0x6ffffefeU,
ELF_DT_SYMINFO = 0x6ffffeffU,
ELF_DT_ADDRRNGHI = 0x6ffffeffU,
ELF_DT_RELACOUNT = 0x6ffffff9U,
ELF_DT_RELCOUNT = 0x6ffffffaU,
ELF_DT_FLAGS_1 = 0x6ffffffbU,
ELF_DT_VERDEF = 0x6ffffffcU,
ELF_DT_VERDEFNUM = 0x6ffffffdU,
ELF_DT_VERNEED = 0x6fff_fffeU,
ELF_DT_VERNEEDNUM = 0x6fff_ffffU;
elf_config.add_enum
:class "dynamic-tag-types"
:entries [Elf_Config_UInt { value = ELF_DT_GNU_HASH, name = "gnu-hash" },
Elf_Config_UInt { value = ELF_DT_VERSYM, name = "versym" },
Elf_Config_UInt { value = ELF_DT_FLAGS_1, name = "flags_1" },
Elf_Config_UInt { value = ELF_DT_GNU_PRELINKED, name = "gnu-prelinked",
doc = "d_val contains a time_t value giving a \
time_t value giving the UTC time at which the object was (pre)linked." },
Elf_Config_UInt { value = ELF_DT_GNU_CONFLICTSZ, name = "conflictsz",
doc = "Used in prelinked objects. d_val contains \
the size of the conflict segment." },
Elf_Config_UInt { value = ELF_DT_TLSDESC_PLT, name = "tlsdesc_plt" },
Elf_Config_UInt { value = ELF_DT_TLSDESC_GOT, name = "tlsdesc_got" },
Elf_Config_UInt { value = ELF_DT_GNU_CONFLICT, name = "gnu_conflict" },
Elf_Config_UInt { value = ELF_DT_GNU_LIBLIST, name = "gnu_liblis" },
Elf_Config_UInt { value = ELF_DT_CONFIG, name = "config" },
Elf_Config_UInt { value = ELF_DT_DEPAUDIT, name = "depaudit" },
Elf_Config_UInt { value = ELF_DT_AUDIT, name = "audit" },
Elf_Config_UInt { value = ELF_DT_PLTPAD, name = "pltpad" },
Elf_Config_UInt { value = ELF_DT_MOVETAB, name = "movetab" },
Elf_Config_UInt { value = ELF_DT_SYMINFO, name = "syminfo" },
Elf_Config_UInt { value = ELF_DT_ADDRRNGHI, name = "addrrnghi" },
Elf_Config_UInt { value = ELF_DT_RELACOUNT, name = "relacount" },
Elf_Config_UInt { value = ELF_DT_RELCOUNT, name = "relcount" },
Elf_Config_UInt { value = ELF_DT_FLAGS_1, name = "flags_1" },
Elf_Config_UInt { value = ELF_DT_VERDEF, name = "verdef" },
Elf_Config_UInt { value = ELF_DT_VERNEED, name = "verneed" },
Elf_Config_UInt { value = ELF_DT_VERNEEDNUM, name = "verneednum" }];
/* Some of the tags above are between DT_HIOS and DT_LOPROC, so
whether they are pointers or values has to be explicitly
determined. */
apush (elf_tag_rules, Elf_Tag_Rule { tag = ELF_DT_VERSYM, is_ptr = 1 });
apush (elf_tag_rules, Elf_Tag_Rule { tag = ELF_DT_GNU_HASH, is_ptr = 1 });
apush (elf_tag_rules, Elf_Tag_Rule { tag = ELF_DT_GNU_PRELINKED, is_ptr = 0 });
apush (elf_tag_rules, Elf_Tag_Rule { tag = ELF_DT_GNU_CONFLICTSZ, is_ptr = 0 });
/* .note.ABI-tag sections contain notes that indicate the kernel type
and minimum kernel version required to load this binary. */
var ELF_NT_GNU_ABI_TAG = 1;
elf_config.add_enum
:class "note-tags"
:entries [Elf_Config_UInt { value = ELF_NT_GNU_ABI_TAG, name = "gnu-abi-tag",
doc = "Kernel type and minimum kernel version. \
The note name contains the string \"GNU\". The desc field contains an \
Elf_ABI_Tag struct." }];
var ELF_GNU_ABI_TAG_LINUX = 0 as Elf_Word,
ELF_GNU_ABI_TAG_HURD = 1 as Elf_Word,
ELF_GNU_ABI_TAG_SOLARIS = 2 as Elf_Word,
ELF_GNU_ABI_TAG_FREEBSD = 3 as Elf_Word,
ELF_GNU_ABI_TAG_NETBSD = 4 as Elf_Word,
ELF_GNU_ABI_TAG_SYLLABLE = 5 as Elf_Word,
ELF_GNU_ABI_TAG_NACL = 6 as Elf_Word;
type Elf_ABI_Tag =
struct
{
Elf_Word kernel_type : kernel_type in [ELF_GNU_ABI_TAG_LINUX,
ELF_GNU_ABI_TAG_HURD,
ELF_GNU_ABI_TAG_SOLARIS,
ELF_GNU_ABI_TAG_FREEBSD,
ELF_GNU_ABI_TAG_NETBSD,
ELF_GNU_ABI_TAG_SYLLABLE];
Elf_Word[3] kernel_version;
method _print_kernel_version = void:
{
printf "#<%u32d.%u32d.%u32d>", kernel_version[0],
kernel_version[1],
kernel_version[2];
}
};
/* Hardware capability notes reflect the hardware "capabilities"
required by the object file. */
var ELF_NT_GNU_HWCAP = 2;
elf_config.add_enum
:class "note-tags"
:entries [Elf_Config_UInt { value = ELF_NT_GNU_HWCAP, name = "gnu-hwcap",
doc = "Hardware capabilities required by the object. \
The desc field contains an Elf_Hwcaps struct." }];
type Elf_Hwcap =
struct
{
uint<8> testbit;
string capname;
};
type Elf_Hwcaps =
struct
{
int<32> num_caps;
uint<32> enabled;
Elf_Hwcap[num_caps] caps;
};
/* Other GNU specific notes. */
var ELF_NT_GNU_BUILD_ID = 3,
ELF_NT_GNU_GOLD_VERSION = 4,
ELF_NT_GNU_PROPERTY_TYPE_0 = 5;
elf_config.add_enum
:class "note-tags"
:entries [Elf_Config_UInt { value = ELF_NT_GNU_BUILD_ID, name = "gnu-build-id",
doc = "GNU build ID. Contents are not requrired to \
be printable, and is opaque." },
Elf_Config_UInt { value = ELF_NT_GNU_GOLD_VERSION, name = "gnu-gold-version",
doc = "Up to descsz of printable gold version string bytes"},
Elf_Config_UInt { value = ELF_NT_GNU_PROPERTY_TYPE_0, name = "gnu-property-type-0",
doc = "Program properties for the kernel to consider." }];
/* Contents of ELF_GNU_PT_GNU_Property segments/sections.
If there is a program property that requires the kernel to perform
some action before loading and ELF file (eg AArch64 BTI or Intel
CET) then this header MUST be present. If no such features are to
be enabled this header MUST NOT be present.
The contents are laid out as a sequence of notes, with type
NT_GNU_PROPERTY_TYPE_0 and name "GNU". The note desc contains an
an array of Elf_Prop struct values. */
var ELF_GNU_PROPERTY_STACK_SIZE = 1,
ELF_GNU_PROPERTY_NO_COPY_ON_PROTECTED = 2,
ELF_GNU_PROPERTY_LOPROC = 0xc0000000,
ELF_GNU_PROPERTY_HIPROC = 0xdfffffff,
ELF_GNU_PROPERTY_LOUSER = 0xe0000000,
ELF_GNU_PROPERTY_HIUSER = 0xffffffff;
elf_config.add_enum
:class "gnu-properties"
:entries [Elf_Config_UInt { value = ELF_GNU_PROPERTY_STACK_SIZE, name = "stack-size",
doc = "pr_data holds a native sized (4 bytes on 32 bit architecures, \
8 bytes on 64 bit) integer in the target processor's native format." },
Elf_Config_UInt { value = ELF_GNU_PROPERTY_NO_COPY_ON_PROTECTED, name = "no-copy-on-protected",
doc = "The linker should treat protected data symbol as defined locally at \
run-time and copy this property to the output share object." }];
type Elf_Prop =
struct
{
Elf_Word pr_type : elf_config.check_enum ("gnu-properties", elf_mach, pr_type);
offset<Elf_Word,B> pr_datasz;
uint<8>[pr_datasz] pr_data;
uint<8>[alignto (pr_datasz, 4#B)] pr_padding;
method _print_pr_type = void:
{
printf "#<%s>", elf_config.format_enum ("gnu-properties", elf_mach, pr_type);
}
};
/* Symbol versioning. */
type Elf_Verneed =
struct
{
Elf_Half vn_version;
Elf_Half vn_cnt;
Elf_Word vn_file;
Elf_Word vn_aux;
Elf_Word vn_next;
};
type Elf_Vernaux =
struct
{
Elf_Word vna_hash;
Elf_Half vna_flags;
Elf_Half vna_other;
Elf_Word vna_name;
Elf_Word vna_next;
};
|