xref: /illumos-gate/usr/src/lib/libdwarf/common/pro_section.h (revision 4d9fdb46b215739778ebc12079842c9905586999)
1bc1f688bSRobert Mustacchi /*
2bc1f688bSRobert Mustacchi 
3bc1f688bSRobert Mustacchi   Copyright (C) 2000,2004 Silicon Graphics, Inc.  All Rights Reserved.
4*4d9fdb46SRobert Mustacchi   Portions (C) 2016 David Anderson .  All Rights Reserved.
5bc1f688bSRobert Mustacchi 
6bc1f688bSRobert Mustacchi   This program is free software; you can redistribute it and/or modify it
7bc1f688bSRobert Mustacchi   under the terms of version 2.1 of the GNU Lesser General Public License
8bc1f688bSRobert Mustacchi   as published by the Free Software Foundation.
9bc1f688bSRobert Mustacchi 
10bc1f688bSRobert Mustacchi   This program is distributed in the hope that it would be useful, but
11bc1f688bSRobert Mustacchi   WITHOUT ANY WARRANTY; without even the implied warranty of
12bc1f688bSRobert Mustacchi   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13bc1f688bSRobert Mustacchi 
14bc1f688bSRobert Mustacchi   Further, this software is distributed without any warranty that it is
15bc1f688bSRobert Mustacchi   free of the rightful claim of any third person regarding infringement
16bc1f688bSRobert Mustacchi   or the like.  Any license provided herein, whether implied or
17bc1f688bSRobert Mustacchi   otherwise, applies only to this software file.  Patent licenses, if
18bc1f688bSRobert Mustacchi   any, provided herein do not apply to combinations of this program with
19bc1f688bSRobert Mustacchi   other software, or any other product whatsoever.
20bc1f688bSRobert Mustacchi 
21bc1f688bSRobert Mustacchi   You should have received a copy of the GNU Lesser General Public
22bc1f688bSRobert Mustacchi   License along with this program; if not, write the Free Software
23bc1f688bSRobert Mustacchi   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
24bc1f688bSRobert Mustacchi   USA.
25bc1f688bSRobert Mustacchi 
26bc1f688bSRobert Mustacchi */
27bc1f688bSRobert Mustacchi 
28bc1f688bSRobert Mustacchi 
29bc1f688bSRobert Mustacchi 
30bc1f688bSRobert Mustacchi 
31bc1f688bSRobert Mustacchi 
32bc1f688bSRobert Mustacchi /* relocation section names */
33*4d9fdb46SRobert Mustacchi extern const char *_dwarf_rel_section_names[];
34bc1f688bSRobert Mustacchi 
35bc1f688bSRobert Mustacchi /* section names */
36*4d9fdb46SRobert Mustacchi extern const char *_dwarf_sectnames[];
37bc1f688bSRobert Mustacchi 
38bc1f688bSRobert Mustacchi /*  struct to hold relocation entries. Its mantained as a linked
39bc1f688bSRobert Mustacchi     list of relocation structs, and will then be written at as a
40bc1f688bSRobert Mustacchi     whole into the relocation section. Whether its 32 bit or
41*4d9fdb46SRobert Mustacchi     64 bit will be obtained from Dwarf_Debug pointer.  */
42bc1f688bSRobert Mustacchi 
43bc1f688bSRobert Mustacchi 
44bc1f688bSRobert Mustacchi 
45bc1f688bSRobert Mustacchi 
46bc1f688bSRobert Mustacchi 
47*4d9fdb46SRobert Mustacchi /* struct stores a chunk of data pertaining to a section */
48bc1f688bSRobert Mustacchi struct Dwarf_P_Section_Data_s {
49bc1f688bSRobert Mustacchi     int ds_elf_sect_no; /* elf section number */
50bc1f688bSRobert Mustacchi     char *ds_data;      /* data contained in section */
51bc1f688bSRobert Mustacchi     unsigned long ds_nbytes; /* bytes of data used so far */
52bc1f688bSRobert Mustacchi     unsigned long ds_orig_alloc; /* bytes allocated originally */
53bc1f688bSRobert Mustacchi     Dwarf_P_Section_Data ds_next; /* next on the list */
54bc1f688bSRobert Mustacchi };
55bc1f688bSRobert Mustacchi 
56bc1f688bSRobert Mustacchi /* Used to allow a dummy initial struct (which we
57bc1f688bSRobert Mustacchi    drop before it gets used
58bc1f688bSRobert Mustacchi    This must not match any legitimate 'section' number.
59bc1f688bSRobert Mustacchi */
60bc1f688bSRobert Mustacchi #define MAGIC_SECT_NO -3
61bc1f688bSRobert Mustacchi 
62bc1f688bSRobert Mustacchi /* Size of chunk of data allocated in one alloc
63bc1f688bSRobert Mustacchi    Not clear if this is the best size.
64bc1f688bSRobert Mustacchi    Used to be just 4096 for user data, the section data struct
65bc1f688bSRobert Mustacchi    was a separate malloc.
66bc1f688bSRobert Mustacchi */
67bc1f688bSRobert Mustacchi #define CHUNK_SIZE (4096 - sizeof (struct Dwarf_P_Section_Data_s))
68bc1f688bSRobert Mustacchi 
69bc1f688bSRobert Mustacchi /*
70bc1f688bSRobert Mustacchi     chunk alloc routine -
71bc1f688bSRobert Mustacchi     if chunk->ds_data is nil, it will alloc CHUNK_SIZE bytes,
72bc1f688bSRobert Mustacchi     and return pointer to the beginning. If chunk is not nil,
73bc1f688bSRobert Mustacchi     it will see if there's enoungh space for nbytes in current
74bc1f688bSRobert Mustacchi     chunk, if not, add new chunk to linked list, and return
75bc1f688bSRobert Mustacchi     a char * pointer to it. Return null if unsuccessful.
76bc1f688bSRobert Mustacchi */
77bc1f688bSRobert Mustacchi Dwarf_Small *_dwarf_pro_buffer(Dwarf_P_Debug dbg, int sectno,
78bc1f688bSRobert Mustacchi     unsigned long nbytes);
79bc1f688bSRobert Mustacchi 
80*4d9fdb46SRobert Mustacchi /* GET_CHUNK_ERROR is new Sept 2016 to use DW_DLV_ERROR. */
81*4d9fdb46SRobert Mustacchi #define GET_CHUNK_ERR(dbg,sectno,ptr,nbytes,error) \
82*4d9fdb46SRobert Mustacchi { \
83*4d9fdb46SRobert Mustacchi     (ptr) = _dwarf_pro_buffer((dbg),(sectno),(nbytes)); \
84*4d9fdb46SRobert Mustacchi     if ((ptr) == NULL) { \
85*4d9fdb46SRobert Mustacchi         DWARF_P_DBG_ERROR(dbg,DW_DLE_CHUNK_ALLOC,DW_DLV_ERROR); \
86*4d9fdb46SRobert Mustacchi     } \
87*4d9fdb46SRobert Mustacchi }
88bc1f688bSRobert Mustacchi #define GET_CHUNK(dbg,sectno,ptr,nbytes,error) \
89bc1f688bSRobert Mustacchi { \
90bc1f688bSRobert Mustacchi     (ptr) = _dwarf_pro_buffer((dbg),(sectno),(nbytes)); \
91bc1f688bSRobert Mustacchi     if ((ptr) == NULL) { \
92bc1f688bSRobert Mustacchi         DWARF_P_DBG_ERROR(dbg,DW_DLE_CHUNK_ALLOC,-1); \
93bc1f688bSRobert Mustacchi     } \
94bc1f688bSRobert Mustacchi }
95bc1f688bSRobert Mustacchi 
96bc1f688bSRobert Mustacchi 
97bc1f688bSRobert Mustacchi 
98*4d9fdb46SRobert Mustacchi int _dwarf_transform_arange_to_disk(Dwarf_P_Debug dbg,
99*4d9fdb46SRobert Mustacchi     Dwarf_Signed *nbufs,
100bc1f688bSRobert Mustacchi     Dwarf_Error * error);
101bc1f688bSRobert Mustacchi 
102bc1f688bSRobert Mustacchi /*  These are for creating ELF section type codes.
103*4d9fdb46SRobert Mustacchi     We are not trying to match any particulare
104*4d9fdb46SRobert Mustacchi     ABI's settings for section type.
105*4d9fdb46SRobert Mustacchi     In the producer, see de_callback_func() calls.
106*4d9fdb46SRobert Mustacchi 
107*4d9fdb46SRobert Mustacchi     If SHT_MIPS_DWARF was defined sometimes
108*4d9fdb46SRobert Mustacchi     that was the value taken:  0x7000001e
109*4d9fdb46SRobert Mustacchi     If it's important to someone then
110*4d9fdb46SRobert Mustacchi     passing in a string like SHT=0x7000001e
111*4d9fdb46SRobert Mustacchi     to the 'extra' argument of dwarf_producer_init()
112*4d9fdb46SRobert Mustacchi     would work nicely (leading/trailing spaces
113*4d9fdb46SRobert Mustacchi     are allowed, as is a NULL pointer instead
114*4d9fdb46SRobert Mustacchi     of a string).
115*4d9fdb46SRobert Mustacchi     One is a convenient default for testing purposes.
116bc1f688bSRobert Mustacchi */
117*4d9fdb46SRobert Mustacchi #define SECTION_TYPE 1  /* SHT_PROGBITS in Elf. */
118