1 /* Output CTF format from GCC.
2 Copyright (C) 2019,2021 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
26 #include "dwarf2asm.h"
29 #include "diagnostic-core.h"
31 static int ctf_label_num
;
33 /* Pointers to various CTF sections. */
35 static GTY (()) section
* ctf_info_section
;
37 /* Section names used to hold CTF debugging information. */
39 /* CTF debug info section. */
41 #ifndef CTF_INFO_SECTION_NAME
42 #define CTF_INFO_SECTION_NAME ".ctf"
45 /* Section flags for the CTF debug info section. */
47 #define CTF_INFO_SECTION_FLAGS (SECTION_DEBUG)
49 /* Maximum size (in bytes) of an artificially generated CTF label. */
51 #define MAX_CTF_LABEL_BYTES 40
53 static char ctf_info_section_label
[MAX_CTF_LABEL_BYTES
];
55 #ifndef CTF_INFO_SECTION_LABEL
56 #define CTF_INFO_SECTION_LABEL "Lctf"
59 /* CTF preprocess callback arguments. */
61 typedef struct ctf_dtd_preprocess_arg
63 uint64_t dtd_global_func_idx
;
64 ctf_container_ref dtd_arg_ctfc
;
65 } ctf_dtd_preprocess_arg_t
;
67 typedef struct ctf_dvd_preprocess_arg
69 uint64_t dvd_global_obj_idx
;
70 ctf_container_ref dvd_arg_ctfc
;
71 } ctf_dvd_preprocess_arg_t
;
73 /* Compare two CTF variable definition entries. Currently used for sorting
77 ctf_varent_compare (const void * entry1
, const void * entry2
)
80 const ctf_dvdef_t
* e1
= *(const ctf_dvdef_t
* const*) entry1
;
81 const ctf_dvdef_t
* e2
= *(const ctf_dvdef_t
* const*) entry2
;
83 result
= strcmp (e1
->dvd_name
, e2
->dvd_name
);
88 /* A CTF type record may be followed by variable-length of bytes to encode the
89 CTF type completely. This routine calculates the number of bytes, in the
90 final binary CTF format, which are used to encode information about the type
93 This function must always be in sync with the CTF header. */
96 ctf_calc_num_vbytes (ctf_dtdef_ref ctftype
)
99 uint64_t vlen_bytes
= 0;
101 uint32_t kind
= CTF_V2_INFO_KIND (ctftype
->dtd_data
.ctti_info
);
102 uint32_t vlen
= CTF_V2_INFO_VLEN (ctftype
->dtd_data
.ctti_info
);
105 ctf_func_arg_t
* farg
;
106 uint32_t size_per_member
= 0;
107 unsigned int num_members
= 0;
108 unsigned int num_fargs
= 0;
119 /* These types have no vlen data. */
124 /* 4 bytes to represent encoding CTF_INT_DATA, CTF_FP_DATA. */
125 vlen_bytes
+= sizeof (uint32_t);
128 /* Sanity check - number of function args must be the same as
130 for (farg
= ctftype
->dtd_u
.dtu_argv
;
131 farg
!= NULL
; farg
= (ctf_func_arg_t
*) ctf_farg_list_next (farg
))
133 gcc_assert (vlen
== num_fargs
);
135 /* FIXME - CTF_PADDING_FOR_ALIGNMENT. */
136 vlen_bytes
+= (vlen
+ (vlen
& 1)) * sizeof (uint32_t);
139 /* This has a single ctf_array_t. */
140 vlen_bytes
+= sizeof (ctf_array_t
);
143 vlen_bytes
+= sizeof (ctf_slice_t
);
147 /* Count the number and type of members. */
148 size
= ctftype
->dtd_data
.ctti_size
;
149 size_per_member
= size
>= CTF_LSTRUCT_THRESH
150 ? sizeof (ctf_lmember_t
) : sizeof (ctf_member_t
);
152 /* Sanity check - number of members of struct must be the same as
154 for (dmd
= ctftype
->dtd_u
.dtu_members
;
155 dmd
!= NULL
; dmd
= (ctf_dmdef_t
*) ctf_dmd_list_next (dmd
))
157 gcc_assert (vlen
== num_members
);
159 vlen_bytes
+= (num_members
* size_per_member
);
162 vlen_bytes
+= vlen
* sizeof (ctf_enum_t
);
170 /* Add a CTF variable to the end of the list. */
173 ctf_list_add_ctf_vars (ctf_container_ref ctfc
, ctf_dvdef_ref var
)
175 /* FIXME - static may not fly with multiple CUs. */
176 static int num_vars_added
= 0;
177 ctfc
->ctfc_vars_list
[num_vars_added
++] = var
;
180 /* Initialize the various sections and labels for CTF output. */
183 init_ctf_sections (void)
185 /* Note : Even in case of LTO, the compiler continues to generate a single
186 CTF section for each compilation unit "early". Unlike other debug
187 sections, CTF sections are non-LTO sections, and do not take the
188 .gnu.debuglto_ prefix. The linker will de-duplicate the types in the CTF
189 sections, in case of LTO or otherwise. */
190 ctf_info_section
= get_section (CTF_INFO_SECTION_NAME
, CTF_INFO_SECTION_FLAGS
,
193 ASM_GENERATE_INTERNAL_LABEL (ctf_info_section_label
,
194 CTF_INFO_SECTION_LABEL
, ctf_label_num
++);
197 /* Routines for CTF pre-processing. */
200 ctf_preprocess_var (ctf_container_ref ctfc
, ctf_dvdef_ref var
)
202 /* Add it to the list of types. This array of types will be sorted before
203 assembling into output. */
204 ctf_list_add_ctf_vars (ctfc
, var
);
207 /* CTF preprocess callback routine for CTF variables. */
210 ctf_dvd_preprocess_cb (ctf_dvdef_ref
* slot
, void * arg
)
212 ctf_dvd_preprocess_arg_t
* dvd_arg
= (ctf_dvd_preprocess_arg_t
*)arg
;
213 ctf_dvdef_ref var
= (ctf_dvdef_ref
) *slot
;
214 ctf_container_ref arg_ctfc
= dvd_arg
->dvd_arg_ctfc
;
216 ctf_preprocess_var (arg_ctfc
, var
);
218 /* Keep track of global objts. */
219 arg_ctfc
->ctfc_gobjts_list
[dvd_arg
->dvd_global_obj_idx
] = var
;
220 dvd_arg
->dvd_global_obj_idx
++;
225 /* CTF preprocess callback routine for CTF types. */
228 ctf_dtd_preprocess_cb (ctf_dtdef_ref
* slot
, void * arg
)
232 ctf_dtdef_ref ctftype
= (ctf_dtdef_ref
) *slot
;
233 ctf_dtd_preprocess_arg_t
* dtd_arg
= (ctf_dtd_preprocess_arg_t
*)arg
;
234 ctf_container_ref arg_ctfc
= dtd_arg
->dtd_arg_ctfc
;
236 size_t index
= ctftype
->dtd_type
;
237 gcc_assert (index
<= arg_ctfc
->ctfc_types
->elements ());
239 /* CTF types need to be output in the order of their type IDs. In other
240 words, if type A is used to define type B, type ID of type A must
241 appear before type ID of type B. */
242 arg_ctfc
->ctfc_types_list
[index
] = ctftype
;
244 /* Keep track of the CTF type if it's a function type and the type
245 was generated from a function object. */
246 kind
= CTF_V2_INFO_KIND (ctftype
->dtd_data
.ctti_info
);
247 if (kind
== CTF_K_FUNCTION
&& ctftype
->from_global_func
)
249 arg_ctfc
->ctfc_gfuncs_list
[dtd_arg
->dtd_global_func_idx
] = ctftype
;
250 dtd_arg
->dtd_global_func_idx
++;
253 /* Calculate the vlen bytes. */
254 arg_ctfc
->ctfc_num_vlen_bytes
+= ctf_calc_num_vbytes (ctftype
);
259 /* CTF preprocessing.
260 After the CTF types for the compilation unit have been generated fully, the
261 compiler writes out the asm for the CTF types.
263 CTF writeout in the compiler requires two passes over the CTF types. In the
264 first pass, the CTF preprocess pass:
265 1. CTF types are sorted in the order of their type IDs.
266 2. The variable number of bytes after each CTF type record are calculated.
267 This is used to calculate the offsets in the ctf_header_t.
268 3. If the CTF type is of CTF_K_FUNCTION, the number of bytes in the
269 funcinfo sub-section are calculated. This is used to calculate the
270 offsets in the ctf_header_t.
271 4. Keep the list of CTF variables in ASCIIbetical order of their names.
273 In the second pass, the CTF writeout pass, asm tags are written out using
274 the compiler's afore-generated internal pre-processed CTF types. */
277 ctf_preprocess (ctf_container_ref ctfc
)
279 size_t num_ctf_types
= ctfc
->ctfc_types
->elements ();
281 /* Initialize an array to keep track of the CTF variables at global
283 size_t num_global_objts
= ctfc
->ctfc_num_global_objts
;
284 if (num_global_objts
)
286 ctfc
->ctfc_gobjts_list
= ggc_vec_alloc
<ctf_dvdef_t
*>(num_global_objts
);
289 size_t num_ctf_vars
= ctfc
->ctfc_vars
->elements ();
292 ctf_dvd_preprocess_arg_t dvd_arg
;
293 dvd_arg
.dvd_global_obj_idx
= 0;
294 dvd_arg
.dvd_arg_ctfc
= ctfc
;
296 /* Allocate CTF var list. */
297 ctfc
->ctfc_vars_list
= ggc_vec_alloc
<ctf_dvdef_ref
>(num_ctf_vars
);
298 /* Variables appear in the sort ASCIIbetical order of their names. This
299 permits binary searching in the CTF reader. Add the variables to a
301 ctfc
->ctfc_vars
->traverse
<void *, ctf_dvd_preprocess_cb
> (&dvd_arg
);
303 qsort (ctfc
->ctfc_vars_list
, num_ctf_vars
, sizeof (ctf_dvdef_ref
),
307 /* Initialize an array to keep track of the CTF functions types for global
308 functions in the CTF data section. */
309 size_t num_global_funcs
= ctfc
->ctfc_num_global_funcs
;
310 if (num_global_funcs
)
312 ctfc
->ctfc_gfuncs_list
= ggc_vec_alloc
<ctf_dtdef_t
*>(num_global_funcs
);
313 gcc_assert (num_ctf_types
);
318 ctf_dtd_preprocess_arg_t dtd_arg
;
319 dtd_arg
.dtd_global_func_idx
= 0;
320 dtd_arg
.dtd_arg_ctfc
= ctfc
;
321 /* Allocate the CTF types list. Add 1 because type ID 0 is never a valid
322 CTF type ID. No CTF type record should appear at that offset, this
323 eases debugging and readability. */
324 ctfc
->ctfc_types_list
= ggc_vec_alloc
<ctf_dtdef_ref
>(num_ctf_types
+ 1);
325 /* Pre-process CTF types. */
326 ctfc
->ctfc_types
->traverse
<void *, ctf_dtd_preprocess_cb
> (&dtd_arg
);
328 gcc_assert (dtd_arg
.dtd_global_func_idx
== num_global_funcs
);
332 /* CTF asm helper routines. */
334 /* Asm'out the CTF preamble. */
337 ctf_asm_preamble (ctf_container_ref ctfc
)
339 dw2_asm_output_data (2, ctfc
->ctfc_magic
,
340 "CTF preamble magic number");
341 dw2_asm_output_data (1, ctfc
->ctfc_version
, "CTF preamble version");
342 dw2_asm_output_data (1, ctfc
->ctfc_flags
, "CTF preamble flags");
345 /* Asm'out a CTF type which is represented by ctf_stype_t. */
348 ctf_asm_stype (ctf_dtdef_ref type
)
350 dw2_asm_output_data (4, type
->dtd_data
.ctti_name
, "ctt_name");
351 dw2_asm_output_data (4, type
->dtd_data
.ctti_info
, "ctt_info");
353 dw2_asm_output_data (4, type
->dtd_data
.ctti_size
, "ctt_size or ctt_type");
356 /* Asm'out a CTF type which is represented by ctf_type_t. */
359 ctf_asm_type (ctf_dtdef_ref type
)
361 dw2_asm_output_data (4, type
->dtd_data
.ctti_name
, "ctt_name");
362 dw2_asm_output_data (4, type
->dtd_data
.ctti_info
, "ctt_info");
364 dw2_asm_output_data (4, type
->dtd_data
.ctti_size
, "ctt_size");
365 dw2_asm_output_data (4, type
->dtd_data
.ctti_lsizehi
, "ctt_lsizehi");
366 dw2_asm_output_data (4, type
->dtd_data
.ctti_lsizelo
, "ctt_lsizelo");
369 /* Asm'out a CTF type of kind CTF_K_SLICE. */
372 ctf_asm_slice (ctf_dtdef_ref type
)
374 dw2_asm_output_data (4, type
->dtd_u
.dtu_slice
.cts_type
, "cts_type");
375 dw2_asm_output_data (2, type
->dtd_u
.dtu_slice
.cts_offset
, "cts_offset");
376 dw2_asm_output_data (2, type
->dtd_u
.dtu_slice
.cts_bits
, "cts_bits");
379 /* Asm'out a CTF type of kind CTF_K_ARRAY. */
382 ctf_asm_array (ctf_dtdef_ref dtd
)
384 dw2_asm_output_data (4, dtd
->dtd_u
.dtu_arr
.ctr_contents
, "cta_contents");
385 dw2_asm_output_data (4, dtd
->dtd_u
.dtu_arr
.ctr_index
, "cta_index");
386 dw2_asm_output_data (4, dtd
->dtd_u
.dtu_arr
.ctr_nelems
, "cta_nelems");
389 /* Asm'out a CTF variable. */
392 ctf_asm_varent (ctf_dvdef_ref var
)
394 /* Output the reference to the name in the string table. */
395 dw2_asm_output_data (4, var
->dvd_name_offset
, "ctv_name");
396 /* Output the type index. */
397 dw2_asm_output_data (4, var
->dvd_type
, "ctv_typeidx");
400 /* Asm'out a member of CTF struct or union, represented by ctf_lmember_t. */
403 ctf_asm_sou_lmember (ctf_dmdef_t
* dmd
)
405 dw2_asm_output_data (4, dmd
->dmd_name_offset
, "ctlm_name");
406 dw2_asm_output_data (4, CTF_OFFSET_TO_LMEMHI (dmd
->dmd_offset
),
408 dw2_asm_output_data (4, dmd
->dmd_type
, "ctlm_type");
409 dw2_asm_output_data (4, CTF_OFFSET_TO_LMEMLO (dmd
->dmd_offset
),
413 /* Asm'out a member of a CTF sruct or union, represented by ctf_member_t. */
416 ctf_asm_sou_member (ctf_dmdef_t
* dmd
)
418 dw2_asm_output_data (4, dmd
->dmd_name_offset
, "ctm_name");
419 dw2_asm_output_data (4, dmd
->dmd_offset
, "ctm_offset");
420 dw2_asm_output_data (4, dmd
->dmd_type
, "ctm_type");
423 /* Asm'out an enumerator constant. */
426 ctf_asm_enum_const (ctf_dmdef_t
* dmd
)
428 dw2_asm_output_data (4, dmd
->dmd_name_offset
, "cte_name");
429 dw2_asm_output_data (4, dmd
->dmd_value
, "cte_value");
432 /* Asm'out a function argument. */
435 ctf_asm_func_arg (ctf_func_arg_t
* farg
)
437 dw2_asm_output_data (4, farg
->farg_type
, "dtu_argv");
440 /* CTF writeout to asm file. */
443 output_ctf_header (ctf_container_ref ctfc
)
445 switch_to_section (ctf_info_section
);
446 ASM_OUTPUT_LABEL (asm_out_file
, ctf_info_section_label
);
448 ctf_asm_preamble (ctfc
);
450 /* For a single compilation unit, the parent container's name and label are
452 dw2_asm_output_data (4, 0, "cth_parlabel");
453 dw2_asm_output_data (4, 0, "cth_parname");
454 dw2_asm_output_data (4, ctfc
->ctfc_cuname_offset
, "cth_cuname");
457 /* Initialize the offsets. The offsets are from after the CTF header. */
459 uint32_t objtoff
= 0;
460 uint32_t funcoff
= 0;
461 uint32_t objtidxoff
= 0;
462 uint32_t funcidxoff
= 0;
464 uint32_t typeoff
= 0;
467 if (!ctfc_is_empty_container (ctfc
))
469 gcc_assert (ctfc_get_num_ctf_types (ctfc
)
470 == (ctfc
->ctfc_num_types
+ ctfc
->ctfc_num_stypes
));
472 funcoff
= objtoff
+ ctfc
->ctfc_num_global_objts
* sizeof (uint32_t);
473 /* Object index appears after function info. */
474 objtidxoff
= funcoff
+ ctfc
->ctfc_num_global_funcs
* sizeof (uint32_t);
475 /* Funxtion index goes next. */
476 funcidxoff
= objtidxoff
+ ctfc
->ctfc_num_global_objts
* sizeof (uint32_t);
477 /* Vars appear after function index. */
478 varoff
= funcidxoff
+ ctfc
->ctfc_num_global_funcs
* sizeof (uint32_t);
479 /* CTF types appear after vars. */
480 typeoff
= varoff
+ ctfc_get_num_ctf_vars (ctfc
) * sizeof (ctf_varent_t
);
481 /* The total number of bytes for CTF types is the sum of the number of
482 times struct ctf_type_t, struct ctf_stype_t are written, plus the
483 amount of variable length data after each one of these. */
484 typeslen
= ctfc
->ctfc_num_types
* sizeof (ctf_type_t
)
485 + ctfc
->ctfc_num_stypes
* (sizeof (ctf_stype_t
))
486 + ctfc_get_num_vlen_bytes (ctfc
);
488 /* Strings appear after types. */
489 stroff
= typeoff
+ typeslen
;
492 /* Offset of label section. */
493 dw2_asm_output_data (4, lbloff
, "cth_lbloff");
494 /* Offset of object section. */
495 dw2_asm_output_data (4, objtoff
, "cth_objtoff");
496 /* Offset of function section. */
497 dw2_asm_output_data (4, funcoff
, "cth_funcoff");
498 /* Offset of object index section. */
499 dw2_asm_output_data (4, objtidxoff
, "cth_objtidxoff");
500 /* Offset of function index section. */
501 dw2_asm_output_data (4, funcidxoff
, "cth_funcidxoff");
503 /* Offset of variable section. */
504 dw2_asm_output_data (4, varoff
, "cth_varoff");
505 /* Offset of type section. */
506 dw2_asm_output_data (4, typeoff
, "cth_typeoff");
507 /* Offset of string section. */
508 dw2_asm_output_data (4, stroff
, "cth_stroff");
509 /* Length of string section in bytes. */
510 dw2_asm_output_data (4, ctfc
->ctfc_strlen
, "cth_strlen");
513 /* Output the CTF object info section. */
516 output_ctf_obj_info (ctf_container_ref ctfc
)
521 if (!ctfc
->ctfc_num_global_objts
) return;
523 /* Compiler spits out the objts (at global scope) in the CTF obj info section.
524 In no specific order. In an object file, the CTF object index section is
525 used to associate the objts to their corresponding names. */
526 for (i
= 0; i
< ctfc
->ctfc_num_global_objts
; i
++)
528 var
= ctfc
->ctfc_gobjts_list
[i
];
530 /* CTF type ID corresponding to the type of the variable. */
531 dw2_asm_output_data (4, var
->dvd_type
, "objtinfo_var_type");
536 /* Output the CTF function info section. */
539 output_ctf_func_info (ctf_container_ref ctfc
)
542 ctf_dtdef_ref ctftype
;
544 if (!ctfc
->ctfc_num_global_funcs
) return;
546 /* The CTF funcinfo section is simply an array of CTF_K_FUNCTION type IDs in
547 the type section. In an object file, the CTF function index section is
548 used to associate functions to their corresponding names. */
549 for (i
= 0; i
< ctfc
->ctfc_num_global_funcs
; i
++)
551 ctftype
= ctfc
->ctfc_gfuncs_list
[i
];
552 dw2_asm_output_data (4, ctftype
->dtd_type
, "funcinfo_func_type");
556 /* Output the CTF object index section. */
559 output_ctf_objtidx (ctf_container_ref ctfc
)
564 if (!ctfc
->ctfc_num_global_objts
) return;
566 for (i
= 0; i
< ctfc
->ctfc_num_global_objts
; i
++)
568 var
= ctfc
->ctfc_gobjts_list
[i
];
569 /* Offset to the name in CTF string table. */
570 dw2_asm_output_data (4, var
->dvd_name_offset
, "objtinfo_name");
574 /* Output the CTF function index section. */
577 output_ctf_funcidx (ctf_container_ref ctfc
)
580 ctf_dtdef_ref ctftype
;
582 if (!ctfc
->ctfc_num_global_funcs
) return;
584 for (i
= 0; i
< ctfc
->ctfc_num_global_funcs
; i
++)
586 ctftype
= ctfc
->ctfc_gfuncs_list
[i
];
587 /* Offset to the name in CTF string table. */
588 dw2_asm_output_data (4, ctftype
->dtd_data
.ctti_name
, "funcinfo_name");
592 /* Output the CTF variables. Variables appear in the sorted ASCIIbetical
593 order of their names. This permits binary searching in the CTF reader. */
596 output_ctf_vars (ctf_container_ref ctfc
)
599 size_t num_ctf_vars
= ctfc
->ctfc_vars
->elements ();
602 /* Iterate over the list of sorted vars and output the asm. */
603 for (i
= 0; i
< num_ctf_vars
; i
++)
605 ctf_asm_varent (ctfc
->ctfc_vars_list
[i
]);
606 /* The type of variable must be a valid one. */
607 gcc_assert (ctfc
->ctfc_vars_list
[i
]->dvd_type
!= CTF_NULL_TYPEID
);
612 /* Output the CTF string records. */
615 output_ctf_strs (ctf_container_ref ctfc
)
617 ctf_string_t
* ctf_string
= ctfc
->ctfc_strtable
.ctstab_head
;
621 dw2_asm_output_nstring (ctf_string
->cts_str
, -1, "ctf_string");
622 ctf_string
= ctf_string
->cts_next
;
626 /* Output the members of the CTF struct or union. */
629 output_asm_ctf_sou_fields (ctf_container_ref
ARG_UNUSED (ctfc
),
634 /* Function pointer to dump struct/union members. */
635 void (*ctf_asm_sou_field_func
) (ctf_dmdef_t
*);
637 uint32_t size
= dtd
->dtd_data
.ctti_size
;
639 /* The variable length data struct/union CTF types is an array of
640 ctf_member or ctf_lmember, depending on size of the member. */
641 if (size
>= CTF_LSTRUCT_THRESH
)
642 ctf_asm_sou_field_func
= ctf_asm_sou_lmember
;
644 ctf_asm_sou_field_func
= ctf_asm_sou_member
;
646 for (dmd
= dtd
->dtd_u
.dtu_members
;
647 dmd
!= NULL
; dmd
= (ctf_dmdef_t
*) ctf_dmd_list_next (dmd
))
649 ctf_asm_sou_field_func (dmd
);
650 /* Sanity Check - Unrepresented types appear as explicit types. */
651 gcc_assert (dmd
->dmd_type
!= CTF_NULL_TYPEID
);
655 /* Output the list of enumerator constants of the CTF enum type. */
658 output_asm_ctf_enum_list (ctf_container_ref
ARG_UNUSED (ctfc
),
663 for (dmd
= dtd
->dtd_u
.dtu_members
;
664 dmd
!= NULL
; dmd
= (ctf_dmdef_t
*) ctf_dmd_list_next (dmd
))
665 ctf_asm_enum_const (dmd
);
668 /* Output the list of function arguments of the CTF function type. */
671 output_asm_func_args_list (ctf_container_ref
ARG_UNUSED (ctfc
),
674 ctf_func_arg_t
* farg
;
676 for (farg
= dtd
->dtd_u
.dtu_argv
;
677 farg
!= NULL
; farg
= (ctf_func_arg_t
*) ctf_farg_list_next (farg
))
678 ctf_asm_func_arg (farg
);
681 /* Output the variable length portion of the CTF type record. */
684 output_asm_ctf_vlen_bytes (ctf_container_ref ctfc
, ctf_dtdef_ref ctftype
)
687 uint32_t kind
= CTF_V2_INFO_KIND (ctftype
->dtd_data
.ctti_info
);
688 uint32_t vlen
= CTF_V2_INFO_VLEN (ctftype
->dtd_data
.ctti_info
);
694 if (kind
== CTF_K_INTEGER
)
696 encoding
= CTF_INT_DATA (ctftype
->dtd_u
.dtu_enc
.cte_format
,
697 ctftype
->dtd_u
.dtu_enc
.cte_offset
,
698 ctftype
->dtd_u
.dtu_enc
.cte_bits
);
702 encoding
= CTF_FP_DATA (ctftype
->dtd_u
.dtu_enc
.cte_format
,
703 ctftype
->dtd_u
.dtu_enc
.cte_offset
,
704 ctftype
->dtd_u
.dtu_enc
.cte_bits
);
706 dw2_asm_output_data (4, encoding
, "ctf_encoding_data");
710 output_asm_func_args_list (ctfc
, ctftype
);
711 /* FIXME - CTF_PADDING_FOR_ALIGNMENT.
712 libctf expects this padding for alignment reasons. Expected to
713 be redundant in CTF_VERSION_4. */
715 dw2_asm_output_data (4, 0, "dtu_argv_padding");
720 ctf_asm_array (ctftype
);
724 ctf_asm_slice (ctftype
);
725 /* Type of the slice must be a valid CTF type. */
726 gcc_assert (ctftype
->dtd_u
.dtu_slice
.cts_type
!= CTF_NULL_TYPEID
);
731 output_asm_ctf_sou_fields (ctfc
, ctftype
);
734 output_asm_ctf_enum_list (ctfc
, ctftype
);
738 /* CTF types of kind CTF_K_VOLATILE, CTF_K_CONST, CTF_K_RESTRICT,
739 etc have no vlen data to write. */
744 /* Output a CTF Type. */
747 output_asm_ctf_type (ctf_container_ref ctfc
, ctf_dtdef_ref type
)
749 if (type
->dtd_data
.ctti_size
<= CTF_MAX_SIZE
)
750 ctf_asm_stype (type
);
753 /* Now comes the variable-length portion for defining types completely.
754 E.g., encoding follows CTF_INT_DATA, CTF_FP_DATA types,
755 struct ctf_array_t follows CTF_K_ARRAY types, or a bunch of
756 struct ctf_member / ctf_lmember ctf_enum sit in there for CTF_K_STRUCT or
758 output_asm_ctf_vlen_bytes (ctfc
, type
);
760 uint32_t kind
= CTF_V2_INFO_KIND (type
->dtd_data
.ctti_info
);
761 /* The underlying type must be a valid CTF type. */
762 if (kind
== CTF_K_POINTER
|| kind
== CTF_K_TYPEDEF
763 || kind
== CTF_K_VOLATILE
|| kind
== CTF_K_CONST
764 || kind
== CTF_K_RESTRICT
)
765 gcc_assert (type
->dtd_data
.ctti_type
!= CTF_NULL_TYPEID
);
768 /* Output all CTF type records. */
771 output_ctf_types (ctf_container_ref ctfc
)
774 size_t num_ctf_types
= ctfc
->ctfc_types
->elements ();
777 /* Type ID = 0 is used as sentinel value; not a valid type. */
778 for (i
= 1; i
<= num_ctf_types
; i
++)
779 output_asm_ctf_type (ctfc
, ctfc
->ctfc_types_list
[i
]);
783 /* CTF routines interfacing to the compiler. */
785 /* Prepare and output the CTF section. */
788 ctf_output (const char * filename
)
790 if (ctf_debug_info_level
== CTFINFO_LEVEL_NONE
)
793 /* Get the CTF container for the current translation unit. */
794 ctf_container_ref tu_ctfc
= ctf_get_tu_ctfc ();
796 init_ctf_sections ();
798 ctf_add_cuname (tu_ctfc
, filename
);
800 /* Pre-process CTF before generating assembly. */
801 ctf_preprocess (tu_ctfc
);
802 output_ctf_header (tu_ctfc
);
803 output_ctf_obj_info (tu_ctfc
);
804 output_ctf_func_info (tu_ctfc
);
805 output_ctf_objtidx (tu_ctfc
);
806 output_ctf_funcidx (tu_ctfc
);
807 output_ctf_vars (tu_ctfc
);
808 output_ctf_types (tu_ctfc
);
809 output_ctf_strs (tu_ctfc
);
811 /* The total number of string bytes must be equal to those processed out to
812 the str subsection. */
813 gcc_assert (tu_ctfc
->ctfc_strlen
814 == ctfc_get_strtab_len (tu_ctfc
, CTF_STRTAB
));
818 /* Reset all state for CTF generation so that we can rerun the compiler within
824 ctf_info_section
= NULL
;
826 ctf_container_ref tu_ctfc
= ctf_get_tu_ctfc ();
827 ctfc_delete_container (tu_ctfc
);
831 #include "gt-ctfout.h"