149d3bc91SRichard Lowe /*
207dc1947SRichard Lowe   Copyright (C) 2000-2006 Silicon Graphics, Inc.  All Rights Reserved.
3*4d9fdb46SRobert Mustacchi   Portions Copyright (C) 2007-2019 David Anderson. All Rights Reserved.
4*4d9fdb46SRobert Mustacchi   Portions Copyright 2012 SN Systems Ltd. All rights reserved.
5*4d9fdb46SRobert Mustacchi 
6*4d9fdb46SRobert Mustacchi   This program is free software; you can redistribute it
7*4d9fdb46SRobert Mustacchi   and/or modify it under the terms of version 2.1 of the
8*4d9fdb46SRobert Mustacchi   GNU Lesser General Public License as published by the Free
9*4d9fdb46SRobert Mustacchi   Software Foundation.
10*4d9fdb46SRobert Mustacchi 
11*4d9fdb46SRobert Mustacchi   This program is distributed in the hope that it would be
12*4d9fdb46SRobert Mustacchi   useful, but WITHOUT ANY WARRANTY; without even the implied
13*4d9fdb46SRobert Mustacchi   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14*4d9fdb46SRobert Mustacchi   PURPOSE.
15*4d9fdb46SRobert Mustacchi 
16*4d9fdb46SRobert Mustacchi   Further, this software is distributed without any warranty
17*4d9fdb46SRobert Mustacchi   that it is free of the rightful claim of any third person
18*4d9fdb46SRobert Mustacchi   regarding infringement or the like.  Any license provided
19*4d9fdb46SRobert Mustacchi   herein, whether implied or otherwise, applies only to this
20*4d9fdb46SRobert Mustacchi   software file.  Patent licenses, if any, provided herein
21*4d9fdb46SRobert Mustacchi   do not apply to combinations of this program with other
22*4d9fdb46SRobert Mustacchi   software, or any other product whatsoever.
23*4d9fdb46SRobert Mustacchi 
24*4d9fdb46SRobert Mustacchi   You should have received a copy of the GNU Lesser General
25*4d9fdb46SRobert Mustacchi   Public License along with this program; if not, write the
26*4d9fdb46SRobert Mustacchi   Free Software Foundation, Inc., 51 Franklin Street - Fifth
27*4d9fdb46SRobert Mustacchi   Floor, Boston MA 02110-1301, USA.
2849d3bc91SRichard Lowe 
29*4d9fdb46SRobert Mustacchi */
3049d3bc91SRichard Lowe 
31*4d9fdb46SRobert Mustacchi #include "config.h"
32*4d9fdb46SRobert Mustacchi #include <stdio.h>
33*4d9fdb46SRobert Mustacchi #include "dwarf_incl.h"
34*4d9fdb46SRobert Mustacchi #include "dwarf_alloc.h"
35*4d9fdb46SRobert Mustacchi #include "dwarf_error.h"
36*4d9fdb46SRobert Mustacchi #include "dwarf_util.h"
37*4d9fdb46SRobert Mustacchi #include "dwarfstring.h"
38*4d9fdb46SRobert Mustacchi #include "dwarf_die_deliv.h"
3949d3bc91SRichard Lowe 
40*4d9fdb46SRobert Mustacchi #define FALSE 0
41*4d9fdb46SRobert Mustacchi #define TRUE 1
42*4d9fdb46SRobert Mustacchi 
43*4d9fdb46SRobert Mustacchi /* These are sanity checks, not 'rules'. */
44*4d9fdb46SRobert Mustacchi #define MINIMUM_ADDRESS_SIZE 2
45*4d9fdb46SRobert Mustacchi #define MAXIMUM_ADDRESS_SIZE 8
46*4d9fdb46SRobert Mustacchi 
47*4d9fdb46SRobert Mustacchi static void assign_correct_unit_type(Dwarf_CU_Context cu_context);
48*4d9fdb46SRobert Mustacchi static int find_cu_die_base_fields(Dwarf_Debug dbg,
49*4d9fdb46SRobert Mustacchi     Dwarf_CU_Context cucon,
50*4d9fdb46SRobert Mustacchi     Dwarf_Die cudie,
51*4d9fdb46SRobert Mustacchi     Dwarf_Error*    error);
52*4d9fdb46SRobert Mustacchi 
53*4d9fdb46SRobert Mustacchi static int _dwarf_siblingof_internal(Dwarf_Debug dbg,
54*4d9fdb46SRobert Mustacchi     Dwarf_Die die,
55*4d9fdb46SRobert Mustacchi     Dwarf_CU_Context context,
56*4d9fdb46SRobert Mustacchi     Dwarf_Bool is_info,
57*4d9fdb46SRobert Mustacchi     Dwarf_Die * caller_ret_die, Dwarf_Error * error);
58*4d9fdb46SRobert Mustacchi 
59*4d9fdb46SRobert Mustacchi /*  see cuandunit.txt for an overview of the
60*4d9fdb46SRobert Mustacchi     DWARF5 split dwarf sections and values
61*4d9fdb46SRobert Mustacchi     and the DWARF4 GNU cc version of a draft
62*4d9fdb46SRobert Mustacchi     version of DWARF5 (quite different from
63*4d9fdb46SRobert Mustacchi     the final DWARF5).
6407dc1947SRichard Lowe */
6507dc1947SRichard Lowe 
66*4d9fdb46SRobert Mustacchi /*  New October 2011.  Enables client code to know if
67*4d9fdb46SRobert Mustacchi     it is a debug_info or debug_types context. */
68*4d9fdb46SRobert Mustacchi Dwarf_Bool
dwarf_get_die_infotypes_flag(Dwarf_Die die)69*4d9fdb46SRobert Mustacchi dwarf_get_die_infotypes_flag(Dwarf_Die die)
70*4d9fdb46SRobert Mustacchi {
71*4d9fdb46SRobert Mustacchi     return die->di_is_info;
72*4d9fdb46SRobert Mustacchi }
7349d3bc91SRichard Lowe 
74*4d9fdb46SRobert Mustacchi #if 0
75*4d9fdb46SRobert Mustacchi static void
76*4d9fdb46SRobert Mustacchi dump_bytes(char * msg,Dwarf_Small * start, long len)
77*4d9fdb46SRobert Mustacchi {
78*4d9fdb46SRobert Mustacchi     Dwarf_Small *end = start + len;
79*4d9fdb46SRobert Mustacchi     Dwarf_Small *cur = start;
8049d3bc91SRichard Lowe 
81*4d9fdb46SRobert Mustacchi     printf("%s ",msg);
82*4d9fdb46SRobert Mustacchi     for (; cur < end; cur++) {
83*4d9fdb46SRobert Mustacchi         printf("%02x ", *cur);
84*4d9fdb46SRobert Mustacchi     }
85*4d9fdb46SRobert Mustacchi     printf("\n");
86*4d9fdb46SRobert Mustacchi }
8749d3bc91SRichard Lowe #endif
8849d3bc91SRichard Lowe 
8949d3bc91SRichard Lowe /*
90*4d9fdb46SRobert Mustacchi     For a given Dwarf_Debug dbg, this function checks
91*4d9fdb46SRobert Mustacchi     if a CU that includes the given offset has been read
92*4d9fdb46SRobert Mustacchi     or not.  If yes, it returns the Dwarf_CU_Context
93*4d9fdb46SRobert Mustacchi     for the CU.  Otherwise it returns NULL.  Being an
94*4d9fdb46SRobert Mustacchi     internal routine, it is assumed that a valid dbg
9549d3bc91SRichard Lowe     is passed.
9649d3bc91SRichard Lowe 
9749d3bc91SRichard Lowe     **This is a sequential search.  May be too slow.
9849d3bc91SRichard Lowe 
9949d3bc91SRichard Lowe     If debug_info and debug_abbrev not loaded, this will
10049d3bc91SRichard Lowe     wind up returning NULL. So no need to load before calling
10149d3bc91SRichard Lowe     this.
10249d3bc91SRichard Lowe */
10349d3bc91SRichard Lowe static Dwarf_CU_Context
_dwarf_find_CU_Context(Dwarf_Debug dbg,Dwarf_Off offset,Dwarf_Bool is_info)104*4d9fdb46SRobert Mustacchi _dwarf_find_CU_Context(Dwarf_Debug dbg, Dwarf_Off offset,Dwarf_Bool is_info)
10549d3bc91SRichard Lowe {
10607dc1947SRichard Lowe     Dwarf_CU_Context cu_context = 0;
107*4d9fdb46SRobert Mustacchi     Dwarf_Debug_InfoTypes dis = is_info? &dbg->de_info_reading:
108*4d9fdb46SRobert Mustacchi         &dbg->de_types_reading;
10949d3bc91SRichard Lowe 
110*4d9fdb46SRobert Mustacchi     if (offset >= dis->de_last_offset)
11107dc1947SRichard Lowe         return (NULL);
11249d3bc91SRichard Lowe 
113*4d9fdb46SRobert Mustacchi     if (dis->de_cu_context != NULL &&
114*4d9fdb46SRobert Mustacchi         dis->de_cu_context->cc_next != NULL &&
115*4d9fdb46SRobert Mustacchi         dis->de_cu_context->cc_next->cc_debug_offset == offset) {
11649d3bc91SRichard Lowe 
117*4d9fdb46SRobert Mustacchi         return (dis->de_cu_context->cc_next);
11849d3bc91SRichard Lowe     }
11949d3bc91SRichard Lowe 
120*4d9fdb46SRobert Mustacchi     if (dis->de_cu_context != NULL &&
121*4d9fdb46SRobert Mustacchi         dis->de_cu_context->cc_debug_offset <= offset) {
12249d3bc91SRichard Lowe 
123*4d9fdb46SRobert Mustacchi         for (cu_context = dis->de_cu_context;
124*4d9fdb46SRobert Mustacchi             cu_context != NULL;
125*4d9fdb46SRobert Mustacchi             cu_context = cu_context->cc_next) {
12649d3bc91SRichard Lowe 
127*4d9fdb46SRobert Mustacchi             if (offset >= cu_context->cc_debug_offset &&
128*4d9fdb46SRobert Mustacchi                 offset < cu_context->cc_debug_offset +
12907dc1947SRichard Lowe                 cu_context->cc_length + cu_context->cc_length_size
13007dc1947SRichard Lowe                 + cu_context->cc_extension_size) {
13149d3bc91SRichard Lowe 
13207dc1947SRichard Lowe                 return (cu_context);
13307dc1947SRichard Lowe             }
13407dc1947SRichard Lowe         }
13549d3bc91SRichard Lowe     }
13649d3bc91SRichard Lowe 
137*4d9fdb46SRobert Mustacchi     for (cu_context = dis->de_cu_context_list;
138*4d9fdb46SRobert Mustacchi         cu_context != NULL;
139*4d9fdb46SRobert Mustacchi         cu_context = cu_context->cc_next) {
14049d3bc91SRichard Lowe 
141*4d9fdb46SRobert Mustacchi         if (offset >= cu_context->cc_debug_offset &&
142*4d9fdb46SRobert Mustacchi             offset < cu_context->cc_debug_offset +
14307dc1947SRichard Lowe             cu_context->cc_length + cu_context->cc_length_size
14407dc1947SRichard Lowe             + cu_context->cc_extension_size) {
14549d3bc91SRichard Lowe 
14607dc1947SRichard Lowe             return (cu_context);
14707dc1947SRichard Lowe         }
14849d3bc91SRichard Lowe     }
14949d3bc91SRichard Lowe 
15049d3bc91SRichard Lowe     return (NULL);
15149d3bc91SRichard Lowe }
15249d3bc91SRichard Lowe 
153*4d9fdb46SRobert Mustacchi int
dwarf_get_debugfission_for_die(Dwarf_Die die,struct Dwarf_Debug_Fission_Per_CU_s * fission_out,Dwarf_Error * error)154*4d9fdb46SRobert Mustacchi dwarf_get_debugfission_for_die(Dwarf_Die die,
155*4d9fdb46SRobert Mustacchi     struct Dwarf_Debug_Fission_Per_CU_s *fission_out,
156*4d9fdb46SRobert Mustacchi     Dwarf_Error *error)
157*4d9fdb46SRobert Mustacchi {
158*4d9fdb46SRobert Mustacchi     Dwarf_CU_Context context = 0;
159*4d9fdb46SRobert Mustacchi     Dwarf_Debug dbg = 0;
160*4d9fdb46SRobert Mustacchi     struct Dwarf_Debug_Fission_Per_CU_s * percu = 0;
16149d3bc91SRichard Lowe 
162*4d9fdb46SRobert Mustacchi     CHECK_DIE(die, DW_DLV_ERROR);
163*4d9fdb46SRobert Mustacchi     context = die->di_cu_context;
164*4d9fdb46SRobert Mustacchi     dbg = context->cc_dbg;
165*4d9fdb46SRobert Mustacchi     if (!_dwarf_file_has_debug_fission_index(dbg)) {
166*4d9fdb46SRobert Mustacchi         return DW_DLV_NO_ENTRY;
167*4d9fdb46SRobert Mustacchi     }
168*4d9fdb46SRobert Mustacchi 
169*4d9fdb46SRobert Mustacchi     /*  Logic should work for DW4 and DW5. */
170*4d9fdb46SRobert Mustacchi     if (context->cc_unit_type == DW_UT_type||
171*4d9fdb46SRobert Mustacchi         context->cc_unit_type == DW_UT_split_type ) {
172*4d9fdb46SRobert Mustacchi         if (!_dwarf_file_has_debug_fission_tu_index(dbg)) {
173*4d9fdb46SRobert Mustacchi             return DW_DLV_NO_ENTRY;
174*4d9fdb46SRobert Mustacchi         }
175*4d9fdb46SRobert Mustacchi     } else if (context->cc_unit_type == DW_UT_split_compile) {
176*4d9fdb46SRobert Mustacchi         if (!_dwarf_file_has_debug_fission_cu_index(dbg)) {
177*4d9fdb46SRobert Mustacchi             return DW_DLV_NO_ENTRY;
178*4d9fdb46SRobert Mustacchi         }
179*4d9fdb46SRobert Mustacchi     }
180*4d9fdb46SRobert Mustacchi     percu = &context->cc_dwp_offsets;
181*4d9fdb46SRobert Mustacchi     if (!percu->pcu_type) {
182*4d9fdb46SRobert Mustacchi         return DW_DLV_NO_ENTRY;
183*4d9fdb46SRobert Mustacchi     }
184*4d9fdb46SRobert Mustacchi     *fission_out = *percu;
185*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
186*4d9fdb46SRobert Mustacchi }
187*4d9fdb46SRobert Mustacchi 
188*4d9fdb46SRobert Mustacchi static Dwarf_Bool
is_unknown_UT_value(int ut)189*4d9fdb46SRobert Mustacchi is_unknown_UT_value(int ut)
190*4d9fdb46SRobert Mustacchi {
191*4d9fdb46SRobert Mustacchi     switch(ut) {
192*4d9fdb46SRobert Mustacchi     case DW_UT_compile:
193*4d9fdb46SRobert Mustacchi     case DW_UT_type:
194*4d9fdb46SRobert Mustacchi     case DW_UT_partial:
195*4d9fdb46SRobert Mustacchi         return FALSE;
196*4d9fdb46SRobert Mustacchi     case DW_UT_skeleton:
197*4d9fdb46SRobert Mustacchi     case DW_UT_split_compile:
198*4d9fdb46SRobert Mustacchi     case DW_UT_split_type:
199*4d9fdb46SRobert Mustacchi         return FALSE;
200*4d9fdb46SRobert Mustacchi     }
201*4d9fdb46SRobert Mustacchi     return TRUE;
202*4d9fdb46SRobert Mustacchi }
203*4d9fdb46SRobert Mustacchi 
204*4d9fdb46SRobert Mustacchi 
205*4d9fdb46SRobert Mustacchi /*  ASSERT: whichone is a DW_SECT* macro value. */
206*4d9fdb46SRobert Mustacchi Dwarf_Unsigned
_dwarf_get_dwp_extra_offset(struct Dwarf_Debug_Fission_Per_CU_s * dwp,unsigned whichone,Dwarf_Unsigned * size)207*4d9fdb46SRobert Mustacchi _dwarf_get_dwp_extra_offset(struct Dwarf_Debug_Fission_Per_CU_s* dwp,
208*4d9fdb46SRobert Mustacchi     unsigned whichone, Dwarf_Unsigned * size)
209*4d9fdb46SRobert Mustacchi {
210*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned sectoff = 0;
211*4d9fdb46SRobert Mustacchi     if (!dwp->pcu_type) {
212*4d9fdb46SRobert Mustacchi         return 0;
213*4d9fdb46SRobert Mustacchi     }
214*4d9fdb46SRobert Mustacchi     sectoff = dwp->pcu_offset[whichone];
215*4d9fdb46SRobert Mustacchi     *size = dwp->pcu_size[whichone];
216*4d9fdb46SRobert Mustacchi     return sectoff;
217*4d9fdb46SRobert Mustacchi }
218*4d9fdb46SRobert Mustacchi 
219*4d9fdb46SRobert Mustacchi 
220*4d9fdb46SRobert Mustacchi /*  _dwarf_get_fission_addition_die returns DW_DLV_OK etc.
22149d3bc91SRichard Lowe */
222*4d9fdb46SRobert Mustacchi int
_dwarf_get_fission_addition_die(Dwarf_Die die,int dw_sect_index,Dwarf_Unsigned * offset,Dwarf_Unsigned * size,Dwarf_Error * error)223*4d9fdb46SRobert Mustacchi _dwarf_get_fission_addition_die(Dwarf_Die die, int dw_sect_index,
224*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned *offset,
225*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned *size,
226*4d9fdb46SRobert Mustacchi    Dwarf_Error *error)
22749d3bc91SRichard Lowe {
228*4d9fdb46SRobert Mustacchi     /* We do not yet know the DIE hash, so we cannot use it
229*4d9fdb46SRobert Mustacchi         to identify the offset. */
230*4d9fdb46SRobert Mustacchi     Dwarf_CU_Context context = 0;
231*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned dwpadd = 0;
232*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned dwpsize = 0;
23349d3bc91SRichard Lowe 
234*4d9fdb46SRobert Mustacchi     CHECK_DIE(die, DW_DLV_ERROR);
235*4d9fdb46SRobert Mustacchi     context = die->di_cu_context;
236*4d9fdb46SRobert Mustacchi     dwpadd =  _dwarf_get_dwp_extra_offset(
237*4d9fdb46SRobert Mustacchi         &context->cc_dwp_offsets,
238*4d9fdb46SRobert Mustacchi         dw_sect_index,&dwpsize);
239*4d9fdb46SRobert Mustacchi     *offset = dwpadd;
240*4d9fdb46SRobert Mustacchi     *size = dwpsize;
241*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
242*4d9fdb46SRobert Mustacchi }
24349d3bc91SRichard Lowe 
244*4d9fdb46SRobert Mustacchi /*  Not sure if this is the only way to be sure early on in
245*4d9fdb46SRobert Mustacchi     reading a compile unit.  */
246*4d9fdb46SRobert Mustacchi static int
section_name_ends_with_dwo(const char * name)247*4d9fdb46SRobert Mustacchi section_name_ends_with_dwo(const char *name)
248*4d9fdb46SRobert Mustacchi {
249*4d9fdb46SRobert Mustacchi     int lenstr = 0;
250*4d9fdb46SRobert Mustacchi     int dotpos = 0;
251*4d9fdb46SRobert Mustacchi     if (!name) {
252*4d9fdb46SRobert Mustacchi         return FALSE;
253*4d9fdb46SRobert Mustacchi     }
254*4d9fdb46SRobert Mustacchi     lenstr = strlen(name);
255*4d9fdb46SRobert Mustacchi     if (lenstr < 5) {
256*4d9fdb46SRobert Mustacchi         return FALSE;
257*4d9fdb46SRobert Mustacchi     }
258*4d9fdb46SRobert Mustacchi     dotpos = lenstr - 4;
259*4d9fdb46SRobert Mustacchi     if(strcmp(name+dotpos,".dwo")) {
260*4d9fdb46SRobert Mustacchi         return FALSE;
261*4d9fdb46SRobert Mustacchi     }
262*4d9fdb46SRobert Mustacchi     return TRUE;
263*4d9fdb46SRobert Mustacchi }
26449d3bc91SRichard Lowe 
265*4d9fdb46SRobert Mustacchi void
_dwarf_create_address_size_dwarf_error(Dwarf_Debug dbg,Dwarf_Error * error,Dwarf_Unsigned addrsize,int errcode,const char * errname)266*4d9fdb46SRobert Mustacchi _dwarf_create_address_size_dwarf_error(Dwarf_Debug dbg,
267*4d9fdb46SRobert Mustacchi     Dwarf_Error *error,
268*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned addrsize,
269*4d9fdb46SRobert Mustacchi     int errcode,const char *errname)
270*4d9fdb46SRobert Mustacchi {
271*4d9fdb46SRobert Mustacchi     dwarfstring m;
272*4d9fdb46SRobert Mustacchi     const char *bites = "bytes";
273*4d9fdb46SRobert Mustacchi     if (addrsize == 1) {
274*4d9fdb46SRobert Mustacchi         bites = "byte";
275*4d9fdb46SRobert Mustacchi     }
27649d3bc91SRichard Lowe 
277*4d9fdb46SRobert Mustacchi     dwarfstring_constructor(&m);
278*4d9fdb46SRobert Mustacchi     dwarfstring_append(&m,(char *)errname);
279*4d9fdb46SRobert Mustacchi     dwarfstring_append_printf_u(&m,
280*4d9fdb46SRobert Mustacchi         ": Address size of %u ",
281*4d9fdb46SRobert Mustacchi         addrsize);
282*4d9fdb46SRobert Mustacchi     dwarfstring_append_printf_s(&m,
283*4d9fdb46SRobert Mustacchi         "%s is not supported. Corrupt DWARF.",
284*4d9fdb46SRobert Mustacchi         (char *)bites);
285*4d9fdb46SRobert Mustacchi     _dwarf_error_string(dbg,error,errcode,
286*4d9fdb46SRobert Mustacchi         dwarfstring_string(&m));
287*4d9fdb46SRobert Mustacchi     dwarfstring_destructor(&m);
28849d3bc91SRichard Lowe }
28949d3bc91SRichard Lowe 
290*4d9fdb46SRobert Mustacchi /*  New January 2017 */
291*4d9fdb46SRobert Mustacchi static int
_dwarf_read_cu_version_and_abbrev_offset(Dwarf_Debug dbg,Dwarf_Small * data,Dwarf_Bool is_info,UNUSEDARG unsigned group_number,unsigned offset_size,Dwarf_CU_Context cu_context,Dwarf_Small * end_data,Dwarf_Unsigned * bytes_read_out,Dwarf_Error * error)292*4d9fdb46SRobert Mustacchi _dwarf_read_cu_version_and_abbrev_offset(Dwarf_Debug dbg,
293*4d9fdb46SRobert Mustacchi     Dwarf_Small *data,
294*4d9fdb46SRobert Mustacchi     Dwarf_Bool is_info,
295*4d9fdb46SRobert Mustacchi     UNUSEDARG unsigned group_number,
296*4d9fdb46SRobert Mustacchi     unsigned offset_size, /* 4 or 8 */
297*4d9fdb46SRobert Mustacchi     Dwarf_CU_Context cu_context,
298*4d9fdb46SRobert Mustacchi     /* end_data used for sanity checking */
299*4d9fdb46SRobert Mustacchi     Dwarf_Small *    end_data,
300*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned * bytes_read_out,
301*4d9fdb46SRobert Mustacchi     Dwarf_Error *    error)
302*4d9fdb46SRobert Mustacchi {
303*4d9fdb46SRobert Mustacchi     Dwarf_Small *  data_start = data;
304*4d9fdb46SRobert Mustacchi     Dwarf_Small *  dataptr = data;
305*4d9fdb46SRobert Mustacchi     int            unit_type = 0;
306*4d9fdb46SRobert Mustacchi     Dwarf_Ubyte    addrsize =  0;
307*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned abbrev_offset = 0;
308*4d9fdb46SRobert Mustacchi     Dwarf_Half version = 0;
309*4d9fdb46SRobert Mustacchi 
310*4d9fdb46SRobert Mustacchi     READ_UNALIGNED_CK(dbg, version, Dwarf_Half,
311*4d9fdb46SRobert Mustacchi         dataptr,DWARF_HALF_SIZE,error,end_data);
312*4d9fdb46SRobert Mustacchi     dataptr += DWARF_HALF_SIZE;
313*4d9fdb46SRobert Mustacchi     if (version == DW_CU_VERSION5) {
314*4d9fdb46SRobert Mustacchi         Dwarf_Ubyte unit_typeb = 0;
315*4d9fdb46SRobert Mustacchi 
316*4d9fdb46SRobert Mustacchi         READ_UNALIGNED_CK(dbg, unit_typeb, Dwarf_Ubyte,
317*4d9fdb46SRobert Mustacchi             dataptr, sizeof(unit_typeb),error,end_data);
318*4d9fdb46SRobert Mustacchi         dataptr += sizeof(unit_typeb);
319*4d9fdb46SRobert Mustacchi 
320*4d9fdb46SRobert Mustacchi         unit_type = unit_typeb;
321*4d9fdb46SRobert Mustacchi         /* We do not need is_info flag in DWARF5 */
322*4d9fdb46SRobert Mustacchi         if (is_unknown_UT_value(unit_type)) {
323*4d9fdb46SRobert Mustacchi             /*  DWARF5 object file is corrupt. Invalid value */
324*4d9fdb46SRobert Mustacchi             dwarfstring m;
325*4d9fdb46SRobert Mustacchi             dwarfstring_constructor(&m);
326*4d9fdb46SRobert Mustacchi             dwarfstring_append_printf_u(&m,
327*4d9fdb46SRobert Mustacchi                 "DW_DLE_CU_UT_TYPE_ERROR: we do not know "
328*4d9fdb46SRobert Mustacchi                 " the CU header unit_type 0x%x",unit_type);
329*4d9fdb46SRobert Mustacchi             dwarfstring_append_printf_u(&m," (%u) so cannot"
330*4d9fdb46SRobert Mustacchi                 "process this compilation_unit. A valid type ",
331*4d9fdb46SRobert Mustacchi                 unit_type);
332*4d9fdb46SRobert Mustacchi             dwarfstring_append(&m,"would be DW_UT_compile"
333*4d9fdb46SRobert Mustacchi                 ", for example");
334*4d9fdb46SRobert Mustacchi             _dwarf_error_string(dbg, error,
335*4d9fdb46SRobert Mustacchi                 DW_DLE_CU_UT_TYPE_ERROR,
336*4d9fdb46SRobert Mustacchi                 dwarfstring_string(&m));
337*4d9fdb46SRobert Mustacchi             dwarfstring_destructor(&m);
338*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
339*4d9fdb46SRobert Mustacchi         }
340*4d9fdb46SRobert Mustacchi         READ_UNALIGNED_CK(dbg, addrsize, unsigned char,
341*4d9fdb46SRobert Mustacchi             dataptr, sizeof(addrsize),error,end_data);
342*4d9fdb46SRobert Mustacchi         dataptr += sizeof(char);
343*4d9fdb46SRobert Mustacchi 
344*4d9fdb46SRobert Mustacchi         READ_UNALIGNED_CK(dbg, abbrev_offset, Dwarf_Unsigned,
345*4d9fdb46SRobert Mustacchi             dataptr, offset_size,error,end_data);
346*4d9fdb46SRobert Mustacchi         dataptr += offset_size;
347*4d9fdb46SRobert Mustacchi 
348*4d9fdb46SRobert Mustacchi     } else if (version == DW_CU_VERSION2 ||
349*4d9fdb46SRobert Mustacchi         version == DW_CU_VERSION3 ||
350*4d9fdb46SRobert Mustacchi         version == DW_CU_VERSION4) {
351*4d9fdb46SRobert Mustacchi         /*  DWARF2,3,4  */
352*4d9fdb46SRobert Mustacchi         READ_UNALIGNED_CK(dbg, abbrev_offset, Dwarf_Unsigned,
353*4d9fdb46SRobert Mustacchi             dataptr, offset_size,error,end_data);
354*4d9fdb46SRobert Mustacchi         dataptr += offset_size;
355*4d9fdb46SRobert Mustacchi 
356*4d9fdb46SRobert Mustacchi         READ_UNALIGNED_CK(dbg, addrsize, Dwarf_Ubyte,
357*4d9fdb46SRobert Mustacchi             dataptr, sizeof(addrsize),error,end_data);
358*4d9fdb46SRobert Mustacchi         dataptr += sizeof(addrsize);
359*4d9fdb46SRobert Mustacchi 
360*4d9fdb46SRobert Mustacchi         /*  This is an initial approximation of unit_type.
361*4d9fdb46SRobert Mustacchi             For DW4 we will refine this after we
362*4d9fdb46SRobert Mustacchi             have built the CU header (by reading
363*4d9fdb46SRobert Mustacchi             CU_die)
364*4d9fdb46SRobert Mustacchi         */
365*4d9fdb46SRobert Mustacchi         unit_type = is_info?DW_UT_compile:DW_UT_type;
366*4d9fdb46SRobert Mustacchi     } else {
367*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_VERSION_STAMP_ERROR);
368*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
369*4d9fdb46SRobert Mustacchi     }
370*4d9fdb46SRobert Mustacchi     cu_context->cc_version_stamp = version;
371*4d9fdb46SRobert Mustacchi     cu_context->cc_unit_type = unit_type;
372*4d9fdb46SRobert Mustacchi     cu_context->cc_address_size = addrsize;
373*4d9fdb46SRobert Mustacchi     cu_context->cc_abbrev_offset = abbrev_offset;
374*4d9fdb46SRobert Mustacchi     if (!addrsize) {
375*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg,error,DW_DLE_ADDRESS_SIZE_ZERO);
376*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
377*4d9fdb46SRobert Mustacchi     }
378*4d9fdb46SRobert Mustacchi     if (addrsize < MINIMUM_ADDRESS_SIZE ||
379*4d9fdb46SRobert Mustacchi         addrsize > MAXIMUM_ADDRESS_SIZE ) {
380*4d9fdb46SRobert Mustacchi         _dwarf_create_address_size_dwarf_error(dbg,error,addrsize,
381*4d9fdb46SRobert Mustacchi             DW_DLE_ADDRESS_SIZE_ERROR,
382*4d9fdb46SRobert Mustacchi             "DW_DLE_ADDRESS_SIZE_ERROR::");
383*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
384*4d9fdb46SRobert Mustacchi     }
385*4d9fdb46SRobert Mustacchi     if (addrsize  > sizeof(Dwarf_Addr)) {
386*4d9fdb46SRobert Mustacchi         _dwarf_create_address_size_dwarf_error(dbg,error,addrsize,
387*4d9fdb46SRobert Mustacchi             DW_DLE_ADDRESS_SIZE_ERROR,
388*4d9fdb46SRobert Mustacchi             "DW_DLE_ADDRESS_SIZE_ERROR: not representable"
389*4d9fdb46SRobert Mustacchi             " in Dwarf_Addr field.");
390*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
391*4d9fdb46SRobert Mustacchi     }
39249d3bc91SRichard Lowe 
393*4d9fdb46SRobert Mustacchi 
394*4d9fdb46SRobert Mustacchi 
395*4d9fdb46SRobert Mustacchi     /* We are ignoring this. Can get it from DWARF5. */
396*4d9fdb46SRobert Mustacchi     cu_context->cc_segment_selector_size = 0;
397*4d9fdb46SRobert Mustacchi     *bytes_read_out = (dataptr - data_start);
398*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
399*4d9fdb46SRobert Mustacchi }
400*4d9fdb46SRobert Mustacchi 
401*4d9fdb46SRobert Mustacchi /*  .debug_info[.dwo]   .debug_types[.dwo]
402*4d9fdb46SRobert Mustacchi     the latter only DWARF4. */
403*4d9fdb46SRobert Mustacchi static int
read_info_area_length_and_check(Dwarf_Debug dbg,Dwarf_CU_Context cu_context,Dwarf_Unsigned offset,Dwarf_Byte_Ptr * cu_ptr_io,Dwarf_Unsigned section_size,Dwarf_Byte_Ptr section_end_ptr,Dwarf_Unsigned * max_cu_global_offset_out,Dwarf_Error * error)404*4d9fdb46SRobert Mustacchi read_info_area_length_and_check(Dwarf_Debug dbg,
405*4d9fdb46SRobert Mustacchi     Dwarf_CU_Context cu_context,
406*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned offset,
407*4d9fdb46SRobert Mustacchi     Dwarf_Byte_Ptr *cu_ptr_io,
408*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned section_size,
409*4d9fdb46SRobert Mustacchi     Dwarf_Byte_Ptr section_end_ptr,
410*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned *max_cu_global_offset_out,
411*4d9fdb46SRobert Mustacchi     Dwarf_Error *error)
412*4d9fdb46SRobert Mustacchi {
413*4d9fdb46SRobert Mustacchi     Dwarf_Byte_Ptr  cu_ptr = 0;
414*4d9fdb46SRobert Mustacchi     int local_length_size = 0;
415*4d9fdb46SRobert Mustacchi     int local_extension_size = 0;
416*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned max_cu_global_offset = 0;
417*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned length = 0;
418*4d9fdb46SRobert Mustacchi 
419*4d9fdb46SRobert Mustacchi     cu_ptr = *cu_ptr_io;
420*4d9fdb46SRobert Mustacchi     /* READ_AREA_LENGTH updates cu_ptr for consumed bytes */
421*4d9fdb46SRobert Mustacchi     READ_AREA_LENGTH_CK(dbg, length, Dwarf_Unsigned,
422*4d9fdb46SRobert Mustacchi         cu_ptr, local_length_size, local_extension_size,
423*4d9fdb46SRobert Mustacchi         error,section_size,section_end_ptr);
424*4d9fdb46SRobert Mustacchi     if (!length) {
425*4d9fdb46SRobert Mustacchi         return DW_DLV_NO_ENTRY;
426*4d9fdb46SRobert Mustacchi     }
427*4d9fdb46SRobert Mustacchi 
428*4d9fdb46SRobert Mustacchi     cu_context->cc_length_size = local_length_size;
429*4d9fdb46SRobert Mustacchi     cu_context->cc_extension_size = local_extension_size;
430*4d9fdb46SRobert Mustacchi     cu_context->cc_length = length;
431*4d9fdb46SRobert Mustacchi 
432*4d9fdb46SRobert Mustacchi     /*  This is a bare minimum, not the real max offset.
433*4d9fdb46SRobert Mustacchi         A preliminary sanity check. */
434*4d9fdb46SRobert Mustacchi     max_cu_global_offset =  offset + length +
435*4d9fdb46SRobert Mustacchi         local_extension_size + local_length_size;
436*4d9fdb46SRobert Mustacchi     if(length > section_size) {
437*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_CU_LENGTH_ERROR);
438*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
439*4d9fdb46SRobert Mustacchi     }
440*4d9fdb46SRobert Mustacchi     if(max_cu_global_offset > section_size) {
441*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_CU_LENGTH_ERROR);
442*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
443*4d9fdb46SRobert Mustacchi     }
444*4d9fdb46SRobert Mustacchi     *cu_ptr_io = cu_ptr;
445*4d9fdb46SRobert Mustacchi     *max_cu_global_offset_out = max_cu_global_offset;
446*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
447*4d9fdb46SRobert Mustacchi }
448*4d9fdb46SRobert Mustacchi 
449*4d9fdb46SRobert Mustacchi 
450*4d9fdb46SRobert Mustacchi /*  In DWARF4  GNU dwp there is a problem.
451*4d9fdb46SRobert Mustacchi     We cannot read the CU die  and it's
452*4d9fdb46SRobert Mustacchi     DW_AT_GNU_dwo_id until we know the
453*4d9fdb46SRobert Mustacchi     section offsets from the index files.
454*4d9fdb46SRobert Mustacchi     Hence we do not know how to search the
455*4d9fdb46SRobert Mustacchi     index files by key. So search by offset.
456*4d9fdb46SRobert Mustacchi 
457*4d9fdb46SRobert Mustacchi     There is no such problem in DWARF5.
458*4d9fdb46SRobert Mustacchi 
459*4d9fdb46SRobert Mustacchi     We have not yet corrected the unit_type so, for DWARF4,
460*4d9fdb46SRobert Mustacchi     we check for simpler unit types.
461*4d9fdb46SRobert Mustacchi */
462*4d9fdb46SRobert Mustacchi 
463*4d9fdb46SRobert Mustacchi static int
fill_in_dwp_offsets_if_present(Dwarf_Debug dbg,Dwarf_CU_Context cu_context,Dwarf_Sig8 * signaturedata,Dwarf_Off offset,Dwarf_Error * error)464*4d9fdb46SRobert Mustacchi fill_in_dwp_offsets_if_present(Dwarf_Debug dbg,
465*4d9fdb46SRobert Mustacchi     Dwarf_CU_Context cu_context,
466*4d9fdb46SRobert Mustacchi     Dwarf_Sig8 * signaturedata,
467*4d9fdb46SRobert Mustacchi     Dwarf_Off    offset,
468*4d9fdb46SRobert Mustacchi     Dwarf_Error *error)
469*4d9fdb46SRobert Mustacchi {
470*4d9fdb46SRobert Mustacchi     Dwarf_Half unit_type = cu_context->cc_unit_type;
471*4d9fdb46SRobert Mustacchi     const char * typename = 0;
472*4d9fdb46SRobert Mustacchi     Dwarf_Half ver = cu_context->cc_version_stamp;
473*4d9fdb46SRobert Mustacchi 
474*4d9fdb46SRobert Mustacchi     if (unit_type == DW_UT_split_type ||
475*4d9fdb46SRobert Mustacchi         (ver == DW_CU_VERSION4 && unit_type == DW_UT_type)){
476*4d9fdb46SRobert Mustacchi         typename = "tu";
477*4d9fdb46SRobert Mustacchi         if (!_dwarf_file_has_debug_fission_tu_index(dbg) ){
478*4d9fdb46SRobert Mustacchi             /* nothing to do. */
479*4d9fdb46SRobert Mustacchi             return DW_DLV_OK;
480*4d9fdb46SRobert Mustacchi         }
481*4d9fdb46SRobert Mustacchi     } else if (unit_type == DW_UT_split_compile ||
482*4d9fdb46SRobert Mustacchi         (ver == DW_CU_VERSION4 &&
483*4d9fdb46SRobert Mustacchi         unit_type == DW_UT_compile)){
484*4d9fdb46SRobert Mustacchi         typename = "cu";
485*4d9fdb46SRobert Mustacchi         if (!_dwarf_file_has_debug_fission_cu_index(dbg) ){
486*4d9fdb46SRobert Mustacchi             /* nothing to do. */
487*4d9fdb46SRobert Mustacchi             return DW_DLV_OK;
488*4d9fdb46SRobert Mustacchi         }
489*4d9fdb46SRobert Mustacchi     } else {
490*4d9fdb46SRobert Mustacchi         /* nothing to do. */
491*4d9fdb46SRobert Mustacchi         return DW_DLV_OK;
492*4d9fdb46SRobert Mustacchi     }
493*4d9fdb46SRobert Mustacchi 
494*4d9fdb46SRobert Mustacchi     if (cu_context->cc_signature_present) {
495*4d9fdb46SRobert Mustacchi         int resdf = 0;
496*4d9fdb46SRobert Mustacchi 
497*4d9fdb46SRobert Mustacchi         resdf = dwarf_get_debugfission_for_key(dbg,
498*4d9fdb46SRobert Mustacchi             signaturedata,
499*4d9fdb46SRobert Mustacchi             typename,
500*4d9fdb46SRobert Mustacchi             &cu_context->cc_dwp_offsets,
501*4d9fdb46SRobert Mustacchi             error);
502*4d9fdb46SRobert Mustacchi         if (resdf == DW_DLV_ERROR) {
503*4d9fdb46SRobert Mustacchi             return resdf;
504*4d9fdb46SRobert Mustacchi         } else if (resdf == DW_DLV_NO_ENTRY) {
505*4d9fdb46SRobert Mustacchi             _dwarf_error_string(dbg, error,
506*4d9fdb46SRobert Mustacchi                 DW_DLE_MISSING_REQUIRED_CU_OFFSET_HASH,
507*4d9fdb46SRobert Mustacchi                 "DW_DLE_MISSING_REQUIRED_CU_OFFSET_HASH: "
508*4d9fdb46SRobert Mustacchi                 " dwarf_get_debugfission_for_key returned"
509*4d9fdb46SRobert Mustacchi                 " DW_DLV_NO_ENTRY, something is wrong");
510*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
511*4d9fdb46SRobert Mustacchi         }
512*4d9fdb46SRobert Mustacchi     } else {
513*4d9fdb46SRobert Mustacchi         int resdf = 0;
514*4d9fdb46SRobert Mustacchi 
515*4d9fdb46SRobert Mustacchi         resdf = _dwarf_get_debugfission_for_offset(dbg,
516*4d9fdb46SRobert Mustacchi             offset,
517*4d9fdb46SRobert Mustacchi             typename,
518*4d9fdb46SRobert Mustacchi             &cu_context->cc_dwp_offsets,
519*4d9fdb46SRobert Mustacchi             error);
520*4d9fdb46SRobert Mustacchi         if (resdf == DW_DLV_ERROR) {
521*4d9fdb46SRobert Mustacchi             return resdf;
522*4d9fdb46SRobert Mustacchi         } else if (resdf == DW_DLV_NO_ENTRY) {
523*4d9fdb46SRobert Mustacchi             _dwarf_error_string(dbg, error,
524*4d9fdb46SRobert Mustacchi                 DW_DLE_MISSING_REQUIRED_CU_OFFSET_HASH,
525*4d9fdb46SRobert Mustacchi                 "DW_DLE_MISSING_REQUIRED_CU_OFFSET_HASH: "
526*4d9fdb46SRobert Mustacchi                 " dwarf_get_debugfission_for_offset returned"
527*4d9fdb46SRobert Mustacchi                 " DW_DLV_NO_ENTRY, something is wrong");
528*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
529*4d9fdb46SRobert Mustacchi         }
530*4d9fdb46SRobert Mustacchi         cu_context->cc_signature =
531*4d9fdb46SRobert Mustacchi             cu_context->cc_dwp_offsets.pcu_hash;
532*4d9fdb46SRobert Mustacchi         cu_context->cc_signature_present = TRUE;
533*4d9fdb46SRobert Mustacchi     }
534*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
535*4d9fdb46SRobert Mustacchi }
536*4d9fdb46SRobert Mustacchi 
537*4d9fdb46SRobert Mustacchi static Dwarf_Bool
_dwarf_may_have_base_fields(Dwarf_CU_Context cu_context)538*4d9fdb46SRobert Mustacchi _dwarf_may_have_base_fields(Dwarf_CU_Context cu_context)
539*4d9fdb46SRobert Mustacchi {
540*4d9fdb46SRobert Mustacchi     if (cu_context->cc_version_stamp < DW_CU_VERSION4) {
541*4d9fdb46SRobert Mustacchi         return FALSE;
542*4d9fdb46SRobert Mustacchi     }
543*4d9fdb46SRobert Mustacchi     return TRUE;
544*4d9fdb46SRobert Mustacchi }
545*4d9fdb46SRobert Mustacchi 
546*4d9fdb46SRobert Mustacchi static int
finish_cu_context_via_cudie_inner(Dwarf_Debug dbg,Dwarf_CU_Context cu_context,Dwarf_Error * error)547*4d9fdb46SRobert Mustacchi finish_cu_context_via_cudie_inner(
548*4d9fdb46SRobert Mustacchi     Dwarf_Debug dbg,
549*4d9fdb46SRobert Mustacchi     Dwarf_CU_Context cu_context,
550*4d9fdb46SRobert Mustacchi     Dwarf_Error *error)
551*4d9fdb46SRobert Mustacchi {
552*4d9fdb46SRobert Mustacchi     if (_dwarf_may_have_base_fields(cu_context)) {
553*4d9fdb46SRobert Mustacchi         /*  DW4: Look for DW_AT_dwo_id and
554*4d9fdb46SRobert Mustacchi             if there is one pick up the hash
555*4d9fdb46SRobert Mustacchi             DW5: hash in skeleton CU die
556*4d9fdb46SRobert Mustacchi             Also pick up cc_str_offset_base and
557*4d9fdb46SRobert Mustacchi             any other base values. */
558*4d9fdb46SRobert Mustacchi 
559*4d9fdb46SRobert Mustacchi         Dwarf_Die cudie = 0;
560*4d9fdb46SRobert Mustacchi         int resdwo = 0;
561*4d9fdb46SRobert Mustacchi 
562*4d9fdb46SRobert Mustacchi         /*  Must call the internal siblingof so
563*4d9fdb46SRobert Mustacchi             we do not depend on the dbg...de_cu_context
564*4d9fdb46SRobert Mustacchi             used by and for dwarf_cu_header_* calls. */
565*4d9fdb46SRobert Mustacchi         resdwo = _dwarf_siblingof_internal(dbg,NULL,
566*4d9fdb46SRobert Mustacchi             cu_context,
567*4d9fdb46SRobert Mustacchi             cu_context->cc_is_info,
568*4d9fdb46SRobert Mustacchi             &cudie, error);
569*4d9fdb46SRobert Mustacchi         if (resdwo == DW_DLV_OK) {
570*4d9fdb46SRobert Mustacchi             Dwarf_Half cutag = 0;
571*4d9fdb46SRobert Mustacchi             int resdwob = 0;
572*4d9fdb46SRobert Mustacchi             resdwob = find_cu_die_base_fields(dbg,
573*4d9fdb46SRobert Mustacchi                 cu_context,
574*4d9fdb46SRobert Mustacchi                 cudie,
575*4d9fdb46SRobert Mustacchi                 error);
576*4d9fdb46SRobert Mustacchi             if (resdwob == DW_DLV_NO_ENTRY) {
577*4d9fdb46SRobert Mustacchi                 /* The CU die has no children */
578*4d9fdb46SRobert Mustacchi                 dwarf_dealloc(dbg,cudie,DW_DLA_DIE);
579*4d9fdb46SRobert Mustacchi                 cudie = 0;
580*4d9fdb46SRobert Mustacchi                 cu_context->cc_cu_die_has_children = FALSE;
581*4d9fdb46SRobert Mustacchi                 return DW_DLV_OK;
582*4d9fdb46SRobert Mustacchi             } else if (resdwob == DW_DLV_ERROR) {
583*4d9fdb46SRobert Mustacchi                 /*  Not applicable or an error */
584*4d9fdb46SRobert Mustacchi                 dwarf_dealloc(dbg,cudie,DW_DLA_DIE);
585*4d9fdb46SRobert Mustacchi                 cudie = 0;
586*4d9fdb46SRobert Mustacchi                 return resdwob;
587*4d9fdb46SRobert Mustacchi             }
588*4d9fdb46SRobert Mustacchi             resdwob = dwarf_tag(cudie,&cutag,error);
589*4d9fdb46SRobert Mustacchi             if (resdwob == DW_DLV_OK) {
590*4d9fdb46SRobert Mustacchi                 cu_context->cc_cu_die_tag = cutag;
591*4d9fdb46SRobert Mustacchi             }
592*4d9fdb46SRobert Mustacchi             dwarf_dealloc(dbg,cudie,DW_DLA_DIE);
593*4d9fdb46SRobert Mustacchi             return resdwob;
594*4d9fdb46SRobert Mustacchi         } else  if (resdwo == DW_DLV_NO_ENTRY) {
595*4d9fdb46SRobert Mustacchi             /* no cudie. Empty CU. */
596*4d9fdb46SRobert Mustacchi             return DW_DLV_OK;
597*4d9fdb46SRobert Mustacchi         } else {
598*4d9fdb46SRobert Mustacchi             /* no cudie. Error.*/
599*4d9fdb46SRobert Mustacchi             return resdwo;
600*4d9fdb46SRobert Mustacchi         }
601*4d9fdb46SRobert Mustacchi     }
602*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
603*4d9fdb46SRobert Mustacchi }
604*4d9fdb46SRobert Mustacchi 
605*4d9fdb46SRobert Mustacchi static void
local_dealloc_cu_context(Dwarf_Debug dbg,Dwarf_CU_Context context)606*4d9fdb46SRobert Mustacchi local_dealloc_cu_context(Dwarf_Debug dbg,
607*4d9fdb46SRobert Mustacchi     Dwarf_CU_Context context)
608*4d9fdb46SRobert Mustacchi {
609*4d9fdb46SRobert Mustacchi     Dwarf_Hash_Table hash_table = 0;
610*4d9fdb46SRobert Mustacchi 
611*4d9fdb46SRobert Mustacchi     if (!context) {
612*4d9fdb46SRobert Mustacchi         return;
613*4d9fdb46SRobert Mustacchi     }
614*4d9fdb46SRobert Mustacchi     hash_table = context->cc_abbrev_hash_table;
615*4d9fdb46SRobert Mustacchi     if (hash_table) {
616*4d9fdb46SRobert Mustacchi         _dwarf_free_abbrev_hash_table_contents(dbg,hash_table);
617*4d9fdb46SRobert Mustacchi         hash_table->tb_entries = 0;
618*4d9fdb46SRobert Mustacchi         dwarf_dealloc(dbg,hash_table, DW_DLA_HASH_TABLE);
619*4d9fdb46SRobert Mustacchi         context->cc_abbrev_hash_table = 0;
620*4d9fdb46SRobert Mustacchi     }
621*4d9fdb46SRobert Mustacchi     dwarf_dealloc(dbg, context, DW_DLA_CU_CONTEXT);
622*4d9fdb46SRobert Mustacchi }
623*4d9fdb46SRobert Mustacchi 
624*4d9fdb46SRobert Mustacchi static void
report_local_unit_type_error(Dwarf_Debug dbg,int unit_type,const char * msg,Dwarf_Error * err)625*4d9fdb46SRobert Mustacchi report_local_unit_type_error(Dwarf_Debug dbg,
626*4d9fdb46SRobert Mustacchi     int unit_type,
627*4d9fdb46SRobert Mustacchi     const char *msg,
628*4d9fdb46SRobert Mustacchi     Dwarf_Error *err)
629*4d9fdb46SRobert Mustacchi {
630*4d9fdb46SRobert Mustacchi     dwarfstring m;
631*4d9fdb46SRobert Mustacchi 
632*4d9fdb46SRobert Mustacchi     dwarfstring_constructor(&m);
633*4d9fdb46SRobert Mustacchi     dwarfstring_append_printf_s(&m,
634*4d9fdb46SRobert Mustacchi         "DW_DLE_CU_UT_TYPE_VALUE: %s ",(char *)msg);
635*4d9fdb46SRobert Mustacchi     dwarfstring_append_printf_u(&m,
636*4d9fdb46SRobert Mustacchi         "the compilation unit unit_type is 0x%x,"
637*4d9fdb46SRobert Mustacchi         " which is unknown to libdwarf. Corrupt DWARF.",
638*4d9fdb46SRobert Mustacchi         unit_type);
639*4d9fdb46SRobert Mustacchi     _dwarf_error_string(dbg,err,DW_DLE_CU_UT_TYPE_VALUE,
640*4d9fdb46SRobert Mustacchi         dwarfstring_string(&m));
641*4d9fdb46SRobert Mustacchi     dwarfstring_destructor(&m);
642*4d9fdb46SRobert Mustacchi }
643*4d9fdb46SRobert Mustacchi 
644*4d9fdb46SRobert Mustacchi /*  This function is used to create a CU Context for
645*4d9fdb46SRobert Mustacchi     a compilation-unit that begins at offset in
64649d3bc91SRichard Lowe     .debug_info.  The CU Context is attached to the
64749d3bc91SRichard Lowe     list of CU Contexts for this dbg.  It is assumed
64849d3bc91SRichard Lowe     that the CU at offset has not been read before,
64949d3bc91SRichard Lowe     and so do not call this routine before making
65049d3bc91SRichard Lowe     sure of this with _dwarf_find_CU_Context().
65149d3bc91SRichard Lowe     Returns NULL on error.  As always, being an
65249d3bc91SRichard Lowe     internal routine, assumes a good dbg.
65349d3bc91SRichard Lowe 
654*4d9fdb46SRobert Mustacchi     The offset argument is global offset, the offset
655*4d9fdb46SRobert Mustacchi     in the section, irrespective of CUs.
656*4d9fdb46SRobert Mustacchi     The offset has the DWP Package File offset built in
657*4d9fdb46SRobert Mustacchi     as it comes from the actual section.
658*4d9fdb46SRobert Mustacchi 
659*4d9fdb46SRobert Mustacchi     max_cu_local_offset is a local offset in this CU.
660*4d9fdb46SRobert Mustacchi     So zero of this field is immediately following the length
661*4d9fdb46SRobert Mustacchi     field of the CU header. so max_cu_local_offset is
662*4d9fdb46SRobert Mustacchi     identical to the CU length field.
663*4d9fdb46SRobert Mustacchi     max_cu_global_offset is the offset one-past the end
664*4d9fdb46SRobert Mustacchi     of this entire CU.  */
665*4d9fdb46SRobert Mustacchi static int
_dwarf_make_CU_Context(Dwarf_Debug dbg,Dwarf_Off offset,Dwarf_Bool is_info,Dwarf_CU_Context * context_out,Dwarf_Error * error)66649d3bc91SRichard Lowe _dwarf_make_CU_Context(Dwarf_Debug dbg,
667*4d9fdb46SRobert Mustacchi     Dwarf_Off offset,Dwarf_Bool is_info,
668*4d9fdb46SRobert Mustacchi     Dwarf_CU_Context * context_out,Dwarf_Error * error)
66949d3bc91SRichard Lowe {
67007dc1947SRichard Lowe     Dwarf_CU_Context cu_context = 0;
671*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned   length = 0;
672*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned   typeoffset = 0;
673*4d9fdb46SRobert Mustacchi     Dwarf_Sig8       signaturedata;
674*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned   types_extra_len = 0;
675*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned   max_cu_local_offset =  0;
676*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned   max_cu_global_offset =  0;
677*4d9fdb46SRobert Mustacchi     Dwarf_Byte_Ptr   cu_ptr = 0;
678*4d9fdb46SRobert Mustacchi     Dwarf_Byte_Ptr   section_end_ptr = 0;
679*4d9fdb46SRobert Mustacchi     int              local_length_size = 0;
680*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned   bytes_read = 0;
681*4d9fdb46SRobert Mustacchi     const char *     secname = is_info?dbg->de_debug_info.dss_name:
682*4d9fdb46SRobert Mustacchi         dbg->de_debug_types.dss_name;
683*4d9fdb46SRobert Mustacchi     Dwarf_Debug_InfoTypes dis = is_info? &dbg->de_info_reading:
684*4d9fdb46SRobert Mustacchi         &dbg->de_types_reading;
685*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned   section_size = is_info? dbg->de_debug_info.dss_size:
686*4d9fdb46SRobert Mustacchi         dbg->de_debug_types.dss_size;
687*4d9fdb46SRobert Mustacchi     int              unit_type = 0;
688*4d9fdb46SRobert Mustacchi     int              version = 0;
689*4d9fdb46SRobert Mustacchi     Dwarf_Small *    dataptr = 0;
690*4d9fdb46SRobert Mustacchi     int              res = 0;
691*4d9fdb46SRobert Mustacchi 
692*4d9fdb46SRobert Mustacchi     memset(&signaturedata,0,sizeof(signaturedata));
69349d3bc91SRichard Lowe     cu_context =
694*4d9fdb46SRobert Mustacchi         (Dwarf_CU_Context)_dwarf_get_alloc(dbg, DW_DLA_CU_CONTEXT, 1);
695*4d9fdb46SRobert Mustacchi     if (!cu_context) {
69607dc1947SRichard Lowe         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
697*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
69849d3bc91SRichard Lowe     }
69949d3bc91SRichard Lowe     cu_context->cc_dbg = dbg;
700*4d9fdb46SRobert Mustacchi     cu_context->cc_is_info = is_info;
701*4d9fdb46SRobert Mustacchi 
702*4d9fdb46SRobert Mustacchi     dataptr = is_info? dbg->de_debug_info.dss_data:
703*4d9fdb46SRobert Mustacchi         dbg->de_debug_types.dss_data;
704*4d9fdb46SRobert Mustacchi     /*  Preliminary sanity checking. */
705*4d9fdb46SRobert Mustacchi     if (!dataptr) {
706*4d9fdb46SRobert Mustacchi         local_dealloc_cu_context(dbg,cu_context);
707*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_INFO_HEADER_ERROR);
708*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
709*4d9fdb46SRobert Mustacchi     }
710*4d9fdb46SRobert Mustacchi     if (offset >= section_size) {
711*4d9fdb46SRobert Mustacchi         local_dealloc_cu_context(dbg,cu_context);
712*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
713*4d9fdb46SRobert Mustacchi     }
714*4d9fdb46SRobert Mustacchi     if ((offset+4) > section_size) {
715*4d9fdb46SRobert Mustacchi         local_dealloc_cu_context(dbg,cu_context);
716*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
717*4d9fdb46SRobert Mustacchi     }
718*4d9fdb46SRobert Mustacchi     section_end_ptr = dataptr+section_size;
719*4d9fdb46SRobert Mustacchi     cu_ptr = (Dwarf_Byte_Ptr) (dataptr+offset);
72049d3bc91SRichard Lowe 
721*4d9fdb46SRobert Mustacchi     if (section_name_ends_with_dwo(secname)) {
722*4d9fdb46SRobert Mustacchi         cu_context->cc_is_dwo = TRUE;
723*4d9fdb46SRobert Mustacchi     }
724*4d9fdb46SRobert Mustacchi     res = read_info_area_length_and_check(dbg,
725*4d9fdb46SRobert Mustacchi         cu_context,
726*4d9fdb46SRobert Mustacchi         offset,
727*4d9fdb46SRobert Mustacchi         &cu_ptr,
728*4d9fdb46SRobert Mustacchi         section_size,
729*4d9fdb46SRobert Mustacchi         section_end_ptr,
730*4d9fdb46SRobert Mustacchi         &max_cu_global_offset,
731*4d9fdb46SRobert Mustacchi         error);
732*4d9fdb46SRobert Mustacchi     if (res != DW_DLV_OK) {
733*4d9fdb46SRobert Mustacchi         local_dealloc_cu_context(dbg,cu_context);
734*4d9fdb46SRobert Mustacchi         return res;
735*4d9fdb46SRobert Mustacchi     }
736*4d9fdb46SRobert Mustacchi     local_length_size = cu_context->cc_length_size;
737*4d9fdb46SRobert Mustacchi     length = cu_context->cc_length;
738*4d9fdb46SRobert Mustacchi     max_cu_local_offset =  length;
739*4d9fdb46SRobert Mustacchi     res  = _dwarf_read_cu_version_and_abbrev_offset(dbg,
740*4d9fdb46SRobert Mustacchi         cu_ptr,
741*4d9fdb46SRobert Mustacchi         is_info,
742*4d9fdb46SRobert Mustacchi         dbg->de_groupnumber,
743*4d9fdb46SRobert Mustacchi         local_length_size,
744*4d9fdb46SRobert Mustacchi         cu_context,
745*4d9fdb46SRobert Mustacchi         section_end_ptr,
746*4d9fdb46SRobert Mustacchi         &bytes_read,error);
747*4d9fdb46SRobert Mustacchi     if (res != DW_DLV_OK) {
748*4d9fdb46SRobert Mustacchi         local_dealloc_cu_context(dbg,cu_context);
749*4d9fdb46SRobert Mustacchi         return res;
750*4d9fdb46SRobert Mustacchi     }
751*4d9fdb46SRobert Mustacchi     version = cu_context->cc_version_stamp;
752*4d9fdb46SRobert Mustacchi     cu_ptr += bytes_read;
753*4d9fdb46SRobert Mustacchi     unit_type = cu_context->cc_unit_type;
754*4d9fdb46SRobert Mustacchi     if (cu_ptr > section_end_ptr) {
755*4d9fdb46SRobert Mustacchi         local_dealloc_cu_context(dbg,cu_context);
756*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_INFO_HEADER_ERROR);
757*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
758*4d9fdb46SRobert Mustacchi     }
75949d3bc91SRichard Lowe 
760*4d9fdb46SRobert Mustacchi     /*  In a dwp context, the abbrev_offset is
761*4d9fdb46SRobert Mustacchi         still  incomplete.
762*4d9fdb46SRobert Mustacchi         We need to add in the base from the .debug_cu_index
763*4d9fdb46SRobert Mustacchi         or .debug_tu_index . Done below */
764*4d9fdb46SRobert Mustacchi 
765*4d9fdb46SRobert Mustacchi     /*  At this point, for DW4, the unit_type is not fully
766*4d9fdb46SRobert Mustacchi         correct as we don't know if it is a skeleton or
767*4d9fdb46SRobert Mustacchi         a split_compile or split_type */
768*4d9fdb46SRobert Mustacchi     if (version ==  DW_CU_VERSION5 ||
769*4d9fdb46SRobert Mustacchi         version == DW_CU_VERSION4) {
770*4d9fdb46SRobert Mustacchi         /*  DW4/DW5  header fields, depending on UT type.
771*4d9fdb46SRobert Mustacchi             See DW5  section 7.5.1.x, DW4
772*4d9fdb46SRobert Mustacchi             data is a GNU extension of DW4. */
773*4d9fdb46SRobert Mustacchi         switch(unit_type) {
774*4d9fdb46SRobert Mustacchi         case DW_UT_split_type:
775*4d9fdb46SRobert Mustacchi         case DW_UT_type: {
776*4d9fdb46SRobert Mustacchi             types_extra_len = sizeof(Dwarf_Sig8) /* 8 */ +
777*4d9fdb46SRobert Mustacchi                 local_length_size /*type_offset size*/;
778*4d9fdb46SRobert Mustacchi             break;
779*4d9fdb46SRobert Mustacchi         }
780*4d9fdb46SRobert Mustacchi         case DW_UT_skeleton:
781*4d9fdb46SRobert Mustacchi         case DW_UT_split_compile: {
782*4d9fdb46SRobert Mustacchi             types_extra_len = sizeof(Dwarf_Sig8) /* 8 */;
783*4d9fdb46SRobert Mustacchi             break;
784*4d9fdb46SRobert Mustacchi         }
785*4d9fdb46SRobert Mustacchi         case DW_UT_compile: /*  No additional fields */
786*4d9fdb46SRobert Mustacchi         case DW_UT_partial: /*  No additional fields */
787*4d9fdb46SRobert Mustacchi             break;
788*4d9fdb46SRobert Mustacchi         default:
789*4d9fdb46SRobert Mustacchi             /*  Data corruption in libdwarf? */
790*4d9fdb46SRobert Mustacchi             report_local_unit_type_error(dbg, unit_type,
791*4d9fdb46SRobert Mustacchi                 "(DW4 or DW5)",error);
792*4d9fdb46SRobert Mustacchi             local_dealloc_cu_context(dbg,cu_context);
793*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
794*4d9fdb46SRobert Mustacchi         }
795*4d9fdb46SRobert Mustacchi     }
79649d3bc91SRichard Lowe 
797*4d9fdb46SRobert Mustacchi     /*  Compare the space following the length field
798*4d9fdb46SRobert Mustacchi         to the bytes in the CU header. */
799*4d9fdb46SRobert Mustacchi     if (length <
800*4d9fdb46SRobert Mustacchi         (CU_VERSION_STAMP_SIZE /* is 2 */ +
801*4d9fdb46SRobert Mustacchi         local_length_size /*for debug_abbrev offset */ +
802*4d9fdb46SRobert Mustacchi         CU_ADDRESS_SIZE_SIZE /* is 1 */ +
803*4d9fdb46SRobert Mustacchi         /* and finally size of the rest of the header: */
804*4d9fdb46SRobert Mustacchi         types_extra_len)) {
80549d3bc91SRichard Lowe 
806*4d9fdb46SRobert Mustacchi         local_dealloc_cu_context(dbg,cu_context);
807*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_CU_LENGTH_ERROR);
808*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
809*4d9fdb46SRobert Mustacchi     }
810*4d9fdb46SRobert Mustacchi     /*  Now we can read the fields with some confidence,
811*4d9fdb46SRobert Mustacchi         we know the fields of the header are inside
812*4d9fdb46SRobert Mustacchi         the section. */
813*4d9fdb46SRobert Mustacchi 
814*4d9fdb46SRobert Mustacchi     cu_context->cc_unit_type = unit_type;
815*4d9fdb46SRobert Mustacchi     switch(unit_type) {
816*4d9fdb46SRobert Mustacchi     case DW_UT_split_type:
817*4d9fdb46SRobert Mustacchi     case DW_UT_type: {
818*4d9fdb46SRobert Mustacchi         int tres = 0;
819*4d9fdb46SRobert Mustacchi         /*  ASSERT: DW_CU_VERSION4 or DW_CU_VERSION5,
820*4d9fdb46SRobert Mustacchi             determined by logic above.
821*4d9fdb46SRobert Mustacchi             Now read the debug_types extra header fields of
822*4d9fdb46SRobert Mustacchi             the signature (8 bytes) and the typeoffset.
823*4d9fdb46SRobert Mustacchi             This can be in executable, ordinary object
824*4d9fdb46SRobert Mustacchi             (as in Type Unit),
825*4d9fdb46SRobert Mustacchi             there was no dwo in DWARF4
826*4d9fdb46SRobert Mustacchi         */
827*4d9fdb46SRobert Mustacchi         memcpy(&signaturedata,cu_ptr,sizeof(signaturedata));
828*4d9fdb46SRobert Mustacchi         cu_ptr += sizeof(signaturedata);
829*4d9fdb46SRobert Mustacchi #if 0
830*4d9fdb46SRobert Mustacchi         READ_UNALIGNED_CK(dbg, typeoffset, Dwarf_Unsigned,
831*4d9fdb46SRobert Mustacchi             cu_ptr, local_length_size,error,section_end_ptr);
832*4d9fdb46SRobert Mustacchi #endif
833*4d9fdb46SRobert Mustacchi         tres = _dwarf_read_unaligned_ck_wrapper(dbg,
834*4d9fdb46SRobert Mustacchi             &typeoffset,cu_ptr,local_length_size,
835*4d9fdb46SRobert Mustacchi             section_end_ptr,error);
836*4d9fdb46SRobert Mustacchi         if (tres != DW_DLV_OK ) {
837*4d9fdb46SRobert Mustacchi             local_dealloc_cu_context(dbg,cu_context);
838*4d9fdb46SRobert Mustacchi             return tres;
839*4d9fdb46SRobert Mustacchi         }
840*4d9fdb46SRobert Mustacchi         cu_context->cc_signature = signaturedata;
841*4d9fdb46SRobert Mustacchi         cu_context->cc_signature_present = TRUE;
842*4d9fdb46SRobert Mustacchi         cu_context->cc_signature_offset = typeoffset;
843*4d9fdb46SRobert Mustacchi         if (typeoffset >= max_cu_local_offset) {
844*4d9fdb46SRobert Mustacchi             local_dealloc_cu_context(dbg,cu_context);
845*4d9fdb46SRobert Mustacchi             _dwarf_error(dbg, error,
846*4d9fdb46SRobert Mustacchi                 DW_DLE_DEBUG_TYPEOFFSET_BAD);
847*4d9fdb46SRobert Mustacchi             return DW_DLV_ERROR;
848*4d9fdb46SRobert Mustacchi         }
849*4d9fdb46SRobert Mustacchi         }
850*4d9fdb46SRobert Mustacchi         break;
851*4d9fdb46SRobert Mustacchi     case DW_UT_skeleton:
852*4d9fdb46SRobert Mustacchi     case DW_UT_split_compile: {
853*4d9fdb46SRobert Mustacchi         /*  These unit types make a pair and
854*4d9fdb46SRobert Mustacchi             paired units have identical signature.*/
855*4d9fdb46SRobert Mustacchi         memcpy(&signaturedata,cu_ptr,sizeof(signaturedata));
856*4d9fdb46SRobert Mustacchi         cu_context->cc_signature = signaturedata;
857*4d9fdb46SRobert Mustacchi         cu_context->cc_signature_present = TRUE;
858*4d9fdb46SRobert Mustacchi 
859*4d9fdb46SRobert Mustacchi         break;
860*4d9fdb46SRobert Mustacchi         }
861*4d9fdb46SRobert Mustacchi     /* The following with no additional fields */
862*4d9fdb46SRobert Mustacchi     case DW_UT_compile:
863*4d9fdb46SRobert Mustacchi     case DW_UT_partial:
864*4d9fdb46SRobert Mustacchi         break;
865*4d9fdb46SRobert Mustacchi     default: {
866*4d9fdb46SRobert Mustacchi         /*  Data corruption in libdwarf? */
867*4d9fdb46SRobert Mustacchi         report_local_unit_type_error(dbg, unit_type,
868*4d9fdb46SRobert Mustacchi             "",error);
869*4d9fdb46SRobert Mustacchi         local_dealloc_cu_context(dbg,cu_context);
870*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
871*4d9fdb46SRobert Mustacchi         }
872*4d9fdb46SRobert Mustacchi     }
873*4d9fdb46SRobert Mustacchi     cu_context->cc_abbrev_hash_table =
874*4d9fdb46SRobert Mustacchi         (Dwarf_Hash_Table) _dwarf_get_alloc(dbg, DW_DLA_HASH_TABLE, 1);
875*4d9fdb46SRobert Mustacchi     if (cu_context->cc_abbrev_hash_table == NULL) {
876*4d9fdb46SRobert Mustacchi         local_dealloc_cu_context(dbg,cu_context);
877*4d9fdb46SRobert Mustacchi         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL);
878*4d9fdb46SRobert Mustacchi         return DW_DLV_ERROR;
879*4d9fdb46SRobert Mustacchi     }
88049d3bc91SRichard Lowe 
881*4d9fdb46SRobert Mustacchi     cu_context->cc_debug_offset = offset;
88249d3bc91SRichard Lowe 
883*4d9fdb46SRobert Mustacchi     /*  This is recording an overall section value for later
884*4d9fdb46SRobert Mustacchi         sanity checking. */
885*4d9fdb46SRobert Mustacchi     dis->de_last_offset = max_cu_global_offset;
886*4d9fdb46SRobert Mustacchi     *context_out  = cu_context;
887*4d9fdb46SRobert Mustacchi     return DW_DLV_OK;
888*4d9fdb46SRobert Mustacchi }
88949d3bc91SRichard Lowe 
890*4d9fdb46SRobert Mustacchi static int
reloc_incomplete(int res,Dwarf_Error err)891*4d9fdb46SRobert Mustacchi reloc_incomplete(int res,Dwarf_Error err)
892*4d9fdb46SRobert Mustacchi {
893*4d9fdb46SRobert Mustacchi     int e = 0;
89449d3bc91SRichard Lowe 
895*4d9fdb46SRobert Mustacchi     if (res == DW_DLV_OK) {
896*4d9fdb46SRobert Mustacchi         return FALSE;
897*4d9fdb46SRobert Mustacchi     }
898*4d9fdb46SRobert Mustacchi     if (res == DW_DLV_NO_ENTRY) {
899*4d9fdb46SRobert Mustacchi         return FALSE;
900*4d9fdb46SRobert Mustacchi     }
901*4d9fdb46SRobert Mustacchi     e = dwarf_errno(err);
902*4d9fdb46SRobert Mustacchi     if (e == DW_DLE_RELOC_MISMATCH_INDEX        ||
903*4d9fdb46SRobert Mustacchi         e == DW_DLE_RELOC_MISMATCH_RELOC_INDEX  ||