ecc26c1c87a9ace399e104487cbba58182ef2cb4
[binutils-gdb.git] / ld / pdb.h
1 /* pdb.h - header file for generating PDB CodeView debugging files.
2 Copyright (C) 2022 Free Software Foundation, Inc.
3
4 This file is part of the GNU Binutils.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
20
21 /* Header files referred to below can be found in Microsoft's PDB
22 repository: https://github.com/microsoft/microsoft-pdb. */
23
24 #ifndef PDB_H
25 #define PDB_H
26
27 #include "sysdep.h"
28 #include "bfd.h"
29 #include <stdbool.h>
30 #include <stddef.h>
31
32 #define LF_VTSHAPE 0x000a
33 #define LF_MODIFIER 0x1001
34 #define LF_POINTER 0x1002
35 #define LF_PROCEDURE 0x1008
36 #define LF_MFUNCTION 0x1009
37 #define LF_ARGLIST 0x1201
38 #define LF_FIELDLIST 0x1203
39 #define LF_BITFIELD 0x1205
40 #define LF_METHODLIST 0x1206
41 #define LF_BCLASS 0x1400
42 #define LF_VBCLASS 0x1401
43 #define LF_IVBCLASS 0x1402
44 #define LF_INDEX 0x1404
45 #define LF_VFUNCTAB 0x1409
46 #define LF_ENUMERATE 0x1502
47 #define LF_ARRAY 0x1503
48 #define LF_CLASS 0x1504
49 #define LF_STRUCTURE 0x1505
50 #define LF_UNION 0x1506
51 #define LF_ENUM 0x1507
52 #define LF_MEMBER 0x150d
53 #define LF_STMEMBER 0x150e
54 #define LF_METHOD 0x150f
55 #define LF_NESTTYPE 0x1510
56 #define LF_ONEMETHOD 0x1511
57
58 #define LF_CHAR 0x8000
59 #define LF_SHORT 0x8001
60 #define LF_USHORT 0x8002
61 #define LF_LONG 0x8003
62 #define LF_ULONG 0x8004
63 #define LF_QUADWORD 0x8009
64 #define LF_UQUADWORD 0x800a
65
66 #define S_PUB32 0x110e
67
68 /* PDBStream70 in pdb1.h */
69 struct pdb_stream_70
70 {
71 uint32_t version;
72 uint32_t signature;
73 uint32_t age;
74 uint8_t guid[16];
75 };
76
77 #define PDB_STREAM_VERSION_VC70 20000404
78 #define PDB_STREAM_VERSION_VC140 20140508
79
80 /* HDR in tpi.h */
81 struct pdb_tpi_stream_header
82 {
83 uint32_t version;
84 uint32_t header_size;
85 uint32_t type_index_begin;
86 uint32_t type_index_end;
87 uint32_t type_record_bytes;
88 uint16_t hash_stream_index;
89 uint16_t hash_aux_stream_index;
90 uint32_t hash_key_size;
91 uint32_t num_hash_buckets;
92 uint32_t hash_value_buffer_offset;
93 uint32_t hash_value_buffer_length;
94 uint32_t index_offset_buffer_offset;
95 uint32_t index_offset_buffer_length;
96 uint32_t hash_adj_buffer_offset;
97 uint32_t hash_adj_buffer_length;
98 };
99
100 #define TPI_STREAM_VERSION_80 20040203
101
102 #define TPI_FIRST_INDEX 0x1000
103 #define NUM_TPI_HASH_BUCKETS 0x3ffff
104
105 /* NewDBIHdr in dbi.h */
106 struct pdb_dbi_stream_header
107 {
108 uint32_t version_signature;
109 uint32_t version_header;
110 uint32_t age;
111 uint16_t global_stream_index;
112 uint16_t build_number;
113 uint16_t public_stream_index;
114 uint16_t pdb_dll_version;
115 uint16_t sym_record_stream;
116 uint16_t pdb_dll_rbld;
117 uint32_t mod_info_size;
118 uint32_t section_contribution_size;
119 uint32_t section_map_size;
120 uint32_t source_info_size;
121 uint32_t type_server_map_size;
122 uint32_t mfc_type_server_index;
123 uint32_t optional_dbg_header_size;
124 uint32_t ec_substream_size;
125 uint16_t flags;
126 uint16_t machine;
127 uint32_t padding;
128 };
129
130 #define DBI_STREAM_VERSION_70 19990903
131
132 /* PSGSIHDR in gsi.h */
133 struct publics_header
134 {
135 uint32_t sym_hash_size;
136 uint32_t addr_map_size;
137 uint32_t num_thunks;
138 uint32_t thunks_size;
139 uint32_t thunk_table;
140 uint32_t thunk_table_offset;
141 uint32_t num_sects;
142 };
143
144 /* GSIHashHdr in gsi.h */
145 struct globals_hash_header
146 {
147 uint32_t signature;
148 uint32_t version;
149 uint32_t entries_size;
150 uint32_t buckets_size;
151 };
152
153 /* HRFile in gsi.h */
154 struct hash_record
155 {
156 uint32_t offset;
157 uint32_t reference;
158 };
159
160 #define GLOBALS_HASH_SIGNATURE 0xffffffff
161 #define GLOBALS_HASH_VERSION_70 0xf12f091a
162
163 /* PUBSYM32 in cvinfo.h */
164 struct pubsym
165 {
166 uint16_t record_length;
167 uint16_t record_type;
168 uint32_t flags;
169 uint32_t offset;
170 uint16_t section;
171 /* followed by null-terminated string */
172 } ATTRIBUTE_PACKED;
173
174 /* see bitset CV_PUBSYMFLAGS in cvinfo.h */
175 #define PUBSYM_FUNCTION 0x2
176
177 struct optional_dbg_header
178 {
179 uint16_t fpo_stream;
180 uint16_t exception_stream;
181 uint16_t fixup_stream;
182 uint16_t omap_to_src_stream;
183 uint16_t omap_from_src_stream;
184 uint16_t section_header_stream;
185 uint16_t token_map_stream;
186 uint16_t xdata_stream;
187 uint16_t pdata_stream;
188 uint16_t new_fpo_stream;
189 uint16_t orig_section_header_stream;
190 };
191
192 #define CV_SIGNATURE_C13 4
193
194 #define DEBUG_S_LINES 0xf2
195 #define DEBUG_S_STRINGTABLE 0xf3
196 #define DEBUG_S_FILECHKSMS 0xf4
197
198 #define STRING_TABLE_SIGNATURE 0xeffeeffe
199 #define STRING_TABLE_VERSION 1
200
201 /* VHdr in nmt.h */
202 struct string_table_header
203 {
204 uint32_t signature;
205 uint32_t version;
206 };
207
208 #define SECTION_CONTRIB_VERSION_60 0xf12eba2d
209
210 /* SC in dbicommon.h */
211 struct section_contribution
212 {
213 uint16_t section;
214 uint16_t padding1;
215 uint32_t offset;
216 uint32_t size;
217 uint32_t characteristics;
218 uint16_t module_index;
219 uint16_t padding2;
220 uint32_t data_crc;
221 uint32_t reloc_crc;
222 };
223
224 /* MODI_60_Persist in dbi.h */
225 struct module_info
226 {
227 uint32_t unused1;
228 struct section_contribution sc;
229 uint16_t flags;
230 uint16_t module_sym_stream;
231 uint32_t sym_byte_size;
232 uint32_t c11_byte_size;
233 uint32_t c13_byte_size;
234 uint16_t source_file_count;
235 uint16_t padding;
236 uint32_t unused2;
237 uint32_t source_file_name_index;
238 uint32_t pdb_file_path_name_index;
239 };
240
241 /* filedata in dumpsym7.cpp */
242 struct file_checksum
243 {
244 uint32_t file_id;
245 uint8_t checksum_length;
246 uint8_t checksum_type;
247 } ATTRIBUTE_PACKED;
248
249 /* lfModifier in cvinfo.h */
250 struct lf_modifier
251 {
252 uint16_t size;
253 uint16_t kind;
254 uint32_t base_type;
255 uint16_t modifier;
256 uint16_t padding;
257 } ATTRIBUTE_PACKED;
258
259 /* lfPointer in cvinfo.h */
260 struct lf_pointer
261 {
262 uint16_t size;
263 uint16_t kind;
264 uint32_t base_type;
265 uint32_t attributes;
266 } ATTRIBUTE_PACKED;
267
268 /* lfArgList in cvinfo.h */
269 struct lf_arglist
270 {
271 uint16_t size;
272 uint16_t kind;
273 uint32_t num_entries;
274 uint32_t args[];
275 } ATTRIBUTE_PACKED;
276
277 /* lfProc in cvinfo.h */
278 struct lf_procedure
279 {
280 uint16_t size;
281 uint16_t kind;
282 uint32_t return_type;
283 uint8_t calling_convention;
284 uint8_t attributes;
285 uint16_t num_parameters;
286 uint32_t arglist;
287 } ATTRIBUTE_PACKED;
288
289 /* lfMFunc in cvinfo.h */
290 struct lf_mfunction
291 {
292 uint16_t size;
293 uint16_t kind;
294 uint32_t return_type;
295 uint32_t containing_class_type;
296 uint32_t this_type;
297 uint8_t calling_convention;
298 uint8_t attributes;
299 uint16_t num_parameters;
300 uint32_t arglist;
301 int32_t this_adjustment;
302 } ATTRIBUTE_PACKED;
303
304 /* lfArray in cvinfo.h */
305 struct lf_array
306 {
307 uint16_t size;
308 uint16_t kind;
309 uint32_t element_type;
310 uint32_t index_type;
311 uint16_t length_in_bytes;
312 char name[];
313 } ATTRIBUTE_PACKED;
314
315 /* lfBitfield in cvinfo.h */
316 struct lf_bitfield
317 {
318 uint16_t size;
319 uint16_t kind;
320 uint32_t base_type;
321 uint8_t length;
322 uint8_t position;
323 } ATTRIBUTE_PACKED;
324
325 /* lfMember in cvinfo.h */
326 struct lf_member
327 {
328 uint16_t kind;
329 uint16_t attributes;
330 uint32_t type;
331 uint16_t offset;
332 char name[];
333 } ATTRIBUTE_PACKED;
334
335 /* from bitfield structure CV_prop_t in cvinfo.h */
336 #define CV_PROP_FORWARD_REF 0x80
337 #define CV_PROP_SCOPED 0x100
338 #define CV_PROP_HAS_UNIQUE_NAME 0x200
339
340 /* lfClass in cvinfo.h */
341 struct lf_class
342 {
343 uint16_t size;
344 uint16_t kind;
345 uint16_t num_members;
346 uint16_t properties;
347 uint32_t field_list;
348 uint32_t derived_from;
349 uint32_t vshape;
350 uint16_t length;
351 char name[];
352 } ATTRIBUTE_PACKED;
353
354 /* lfUnion in cvinfo.h */
355 struct lf_union
356 {
357 uint16_t size;
358 uint16_t kind;
359 uint16_t num_members;
360 uint16_t properties;
361 uint32_t field_list;
362 uint16_t length;
363 char name[];
364 } ATTRIBUTE_PACKED;
365
366 /* lfEnumerate in cvinfo.h */
367 struct lf_enumerate
368 {
369 uint16_t kind;
370 uint16_t attributes;
371 uint16_t value;
372 /* then actual value if value >= 0x8000 */
373 char name[];
374 } ATTRIBUTE_PACKED;
375
376 /* lfEnum in cvinfo.h */
377 struct lf_enum
378 {
379 uint16_t size;
380 uint16_t kind;
381 uint16_t num_elements;
382 uint16_t properties;
383 uint32_t underlying_type;
384 uint32_t field_list;
385 char name[];
386 } ATTRIBUTE_PACKED;
387
388 /* lfIndex in cvinfo.h */
389 struct lf_index
390 {
391 uint16_t kind;
392 uint16_t padding;
393 uint32_t index;
394 } ATTRIBUTE_PACKED;
395
396 /* lfOneMethod in cvinfo.h */
397 struct lf_onemethod
398 {
399 uint16_t kind;
400 uint16_t method_attribute;
401 uint32_t method_type;
402 char name[];
403 } ATTRIBUTE_PACKED;
404
405 /* mlMethod in cvinfo.h */
406 struct lf_methodlist_entry
407 {
408 uint16_t method_attribute;
409 uint16_t padding;
410 uint32_t method_type;
411 } ATTRIBUTE_PACKED;
412
413 /* lfMethodList in cvinfo.h */
414 struct lf_methodlist
415 {
416 uint16_t size;
417 uint16_t kind;
418 struct lf_methodlist_entry entries[];
419 } ATTRIBUTE_PACKED;
420
421 /* lfMethod in cvinfo.h */
422 struct lf_method
423 {
424 uint16_t kind;
425 uint16_t count;
426 uint32_t method_list;
427 char name[];
428 } ATTRIBUTE_PACKED;
429
430 /* lfBClass in cvinfo.h */
431 struct lf_bclass
432 {
433 uint16_t kind;
434 uint16_t attributes;
435 uint32_t base_class_type;
436 uint16_t offset;
437 uint16_t padding;
438 } ATTRIBUTE_PACKED;
439
440 /* lfVFuncTab in cvinfo.h */
441 struct lf_vfunctab
442 {
443 uint16_t kind;
444 uint16_t padding;
445 uint32_t type;
446 } ATTRIBUTE_PACKED;
447
448 /* lfVBClass in cvinfo.h */
449 struct lf_vbclass
450 {
451 uint16_t kind;
452 uint16_t attributes;
453 uint32_t base_class_type;
454 uint32_t virtual_base_pointer_type;
455 uint16_t virtual_base_pointer_offset;
456 uint16_t virtual_base_vbtable_offset;
457 } ATTRIBUTE_PACKED;
458
459 /* lfSTMember in cvinfo.h */
460 struct lf_static_member
461 {
462 uint16_t kind;
463 uint16_t attributes;
464 uint32_t type;
465 char name[];
466 } ATTRIBUTE_PACKED;
467
468 /* lfNestType in cvinfo.h */
469 struct lf_nest_type
470 {
471 uint16_t kind;
472 uint16_t padding;
473 uint32_t type;
474 char name[];
475 } ATTRIBUTE_PACKED;
476
477 extern bool create_pdb_file (bfd *, const char *, const unsigned char *);
478
479 #endif