149d3bc91SRichard Lowe /*
249d3bc91SRichard Lowe 
307dc1947SRichard Lowe   Copyright (C) 2000,2004 Silicon Graphics, Inc.  All Rights Reserved.
4*4d9fdb46SRobert Mustacchi   Portions (C) 2016 David Anderson .  All Rights Reserved.
549d3bc91SRichard Lowe 
649d3bc91SRichard Lowe   This program is free software; you can redistribute it and/or modify it
7*4d9fdb46SRobert Mustacchi   under the terms of version 2.1 of the GNU Lesser General Public License
849d3bc91SRichard Lowe   as published by the Free Software Foundation.
949d3bc91SRichard Lowe 
1049d3bc91SRichard Lowe   This program is distributed in the hope that it would be useful, but
1149d3bc91SRichard Lowe   WITHOUT ANY WARRANTY; without even the implied warranty of
1349d3bc91SRichard Lowe 
1449d3bc91SRichard Lowe   Further, this software is distributed without any warranty that it is
15*4d9fdb46SRobert Mustacchi   free of the rightful claim of any third person regarding infringement
16*4d9fdb46SRobert Mustacchi   or the like.  Any license provided herein, whether implied or
1749d3bc91SRichard Lowe   otherwise, applies only to this software file.  Patent licenses, if
18*4d9fdb46SRobert Mustacchi   any, provided herein do not apply to combinations of this program with
19*4d9fdb46SRobert Mustacchi   other software, or any other product whatsoever.
2049d3bc91SRichard Lowe 
2107dc1947SRichard Lowe   You should have received a copy of the GNU Lesser General Public
2207dc1947SRichard Lowe   License along with this program; if not, write the Free Software
2307dc1947SRichard Lowe   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
2449d3bc91SRichard Lowe   USA.
2549d3bc91SRichard Lowe 
2649d3bc91SRichard Lowe */
2749d3bc91SRichard Lowe 
2849d3bc91SRichard Lowe 
2949d3bc91SRichard Lowe 
3049d3bc91SRichard Lowe 
3149d3bc91SRichard Lowe 
3249d3bc91SRichard Lowe /* relocation section names */
33*4d9fdb46SRobert Mustacchi extern const char *_dwarf_rel_section_names[];
3449d3bc91SRichard Lowe 
3549d3bc91SRichard Lowe /* section names */
36*4d9fdb46SRobert Mustacchi extern const char *_dwarf_sectnames[];
3749d3bc91SRichard Lowe 
38*4d9fdb46SRobert Mustacchi /*  struct to hold relocation entries. Its mantained as a linked
39*4d9fdb46SRobert Mustacchi     list of relocation structs, and will then be written at as a
40*4d9fdb46SRobert Mustacchi     whole into the relocation section. Whether its 32 bit or
41*4d9fdb46SRobert Mustacchi     64 bit will be obtained from Dwarf_Debug pointer.  */
4249d3bc91SRichard Lowe 
4349d3bc91SRichard Lowe 
4449d3bc91SRichard Lowe 
4549d3bc91SRichard Lowe 
4649d3bc91SRichard Lowe 
47*4d9fdb46SRobert Mustacchi /* struct stores a chunk of data pertaining to a section */
4849d3bc91SRichard Lowe struct Dwarf_P_Section_Data_s {
49*4d9fdb46SRobert Mustacchi     int ds_elf_sect_no; /* elf section number */
50*4d9fdb46SRobert Mustacchi     char *ds_data;      /* data contained in section */
51*4d9fdb46SRobert Mustacchi     unsigned long ds_nbytes; /* bytes of data used so far */
52*4d9fdb46SRobert Mustacchi     unsigned long ds_orig_alloc; /* bytes allocated originally */
53*4d9fdb46SRobert Mustacchi     Dwarf_P_Section_Data ds_next; /* next on the list */
5449d3bc91SRichard Lowe };
5549d3bc91SRichard Lowe 
5649d3bc91SRichard Lowe /* Used to allow a dummy initial struct (which we
5749d3bc91SRichard Lowe    drop before it gets used
5849d3bc91SRichard Lowe    This must not match any legitimate 'section' number.
5949d3bc91SRichard Lowe */
6049d3bc91SRichard Lowe #define MAGIC_SECT_NO -3
6149d3bc91SRichard Lowe 
62*4d9fdb46SRobert Mustacchi /* Size of chunk of data allocated in one alloc
6349d3bc91SRichard Lowe    Not clear if this is the best size.
6449d3bc91SRichard Lowe    Used to be just 4096 for user data, the section data struct
6549d3bc91SRichard Lowe    was a separate malloc.
6649d3bc91SRichard Lowe */
67*4d9fdb46SRobert Mustacchi #define CHUNK_SIZE (4096 - sizeof (struct Dwarf_P_Section_Data_s))
6849d3bc91SRichard Lowe 
6949d3bc91SRichard Lowe /*
70*4d9fdb46SRobert Mustacchi     chunk alloc routine -
71*4d9fdb46SRobert Mustacchi     if chunk->ds_data is nil, it will alloc CHUNK_SIZE bytes,
72*4d9fdb46SRobert Mustacchi     and return pointer to the beginning. If chunk is not nil,
73*4d9fdb46SRobert Mustacchi     it will see if there's enoungh space for nbytes in current
74*4d9fdb46SRobert Mustacchi     chunk, if not, add new chunk to linked list, and return
75*4d9fdb46SRobert Mustacchi     a char * pointer to it. Return null if unsuccessful.
7649d3bc91SRichard Lowe */
7749d3bc91SRichard Lowe Dwarf_Small *_dwarf_pro_buffer(Dwarf_P_Debug dbg, int sectno,
78*4d9fdb46SRobert Mustacchi     unsigned long nbytes);
79*4d9fdb46SRobert 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 }
8849d3bc91SRichard Lowe #define GET_CHUNK(dbg,sectno,ptr,nbytes,error) \
89*4d9fdb46SRobert Mustacchi { \
90*4d9fdb46SRobert Mustacchi     (ptr) = _dwarf_pro_buffer((dbg),(sectno),(nbytes)); \
91*4d9fdb46SRobert Mustacchi     if ((ptr) == NULL) { \
92*4d9fdb46SRobert Mustacchi         DWARF_P_DBG_ERROR(dbg,DW_DLE_CHUNK_ALLOC,-1); \
93*4d9fdb46SRobert Mustacchi     } \
94*4d9fdb46SRobert Mustacchi }
95*4d9fdb46SRobert Mustacchi 
96*4d9fdb46SRobert Mustacchi 
97*4d9fdb46SRobert Mustacchi 
98*4d9fdb46SRobert Mustacchi int _dwarf_transform_arange_to_disk(Dwarf_P_Debug dbg,
99*4d9fdb46SRobert Mustacchi     Dwarf_Signed *nbufs,
100*4d9fdb46SRobert Mustacchi     Dwarf_Error * error);
101*4d9fdb46SRobert Mustacchi 
102*4d9fdb46SRobert 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.
11649d3bc91SRichard Lowe */
117*4d9fdb46SRobert Mustacchi #define SECTION_TYPE 1  /* SHT_PROGBITS in Elf. */