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