diff options
author | Robert Mustacchi <rm@fingolfin.org> | 2020-06-25 17:58:31 -0700 |
---|---|---|
committer | Robert Mustacchi <rm@fingolfin.org> | 2020-07-10 12:35:15 -0700 |
commit | 4d9fdb46b215739778ebc12079842c9905586999 (patch) | |
tree | 3771cce63ac88d62941f4174ee3fa58336a95775 /usr/src/lib/libdwarf/common/pro_reloc_stream.c | |
parent | 4c60ecf710115cd5ae61f6b97dafc7ff963259f4 (diff) | |
download | illumos-gate-4d9fdb46b215739778ebc12079842c9905586999.tar.gz |
12223 Update libdwarf to libdwarf-20200612
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/lib/libdwarf/common/pro_reloc_stream.c')
-rw-r--r-- | usr/src/lib/libdwarf/common/pro_reloc_stream.c | 213 |
1 files changed, 90 insertions, 123 deletions
diff --git a/usr/src/lib/libdwarf/common/pro_reloc_stream.c b/usr/src/lib/libdwarf/common/pro_reloc_stream.c index 459779ceda..ab763d4a42 100644 --- a/usr/src/lib/libdwarf/common/pro_reloc_stream.c +++ b/usr/src/lib/libdwarf/common/pro_reloc_stream.c @@ -2,45 +2,34 @@ Copyright (C) 2000,2001,2004 Silicon Graphics, Inc. All Rights Reserved. Portions Copyright 2002-2010 Sun Microsystems, Inc. All rights reserved. - Portions Copyright 2008-2010 David Anderson, Inc. All rights reserved. + Portions Copyright 2008-2016 David Anderson, Inc. All rights reserved. This program is free software; you can redistribute it and/or modify it - under the terms of version 2.1 of the GNU Lesser General Public License + under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. This program is distributed in the hope that it would be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, this software is distributed without any warranty that it is - free of the rightful claim of any third person regarding infringement - or the like. Any license provided herein, whether implied or + free of the rightful claim of any third person regarding infringement + or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if - any, provided herein do not apply to combinations of this program with - other software, or any other product whatsoever. + any, provided herein do not apply to combinations of this program with + other software, or any other product whatsoever. - You should have received a copy of the GNU Lesser General Public - License along with this program; if not, write the Free Software + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, write the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301, USA. - Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, - Mountain View, CA 94043, or: - - http://www.sgi.com - - For further information regarding this notice, see: - - http://oss.sgi.com/projects/GenInfo/NoticeExplan - */ - - #include "config.h" +#ifdef DWARF_WITH_LIBELF #include "libdwarfdefs.h" #include <stdio.h> -#include <string.h> #ifdef HAVE_ELFACCESS_H #include <elfaccess.h> #else @@ -48,19 +37,25 @@ #define Set_REL32_info(r,s,t) ((r).r_info = ELF32_R_INFO(s,t)) #define Set_REL64_info(r,s,t) ((r).r_info = ELF64_R_INFO(s,t)) #endif +#ifdef HAVE_STRING_H +#include <string.h> +#endif /* HAVE_STRING_H */ +#ifdef HAVE_STDDEF_H +#include <stddef.h> +#endif /* HAVE_STDDEF_H */ #include "pro_incl.h" +#include "dwarf.h" +#include "libdwarf.h" +#include "pro_opaque.h" +#include "pro_error.h" +#include "pro_alloc.h" #include "pro_section.h" #include "pro_reloc.h" #include "pro_reloc_stream.h" -/* - Return DW_DLV_ERROR on malloc error or reltarget_length error. - Return DW_DLV_OK otherwise - - - -*/ - /*ARGSUSED*/ int +/* Return DW_DLV_ERROR on malloc error or reltarget_length error. + Return DW_DLV_OK otherwise */ +/*ARGSUSED*/ int _dwarf_pro_reloc_name_stream64(Dwarf_P_Debug dbg, int base_sec_index, Dwarf_Unsigned offset, /* r_offset of reloc */ @@ -75,13 +70,13 @@ _dwarf_pro_reloc_name_stream64(Dwarf_P_Debug dbg, int rel_type = 0; res = _dwarf_pro_reloc_get_a_slot(dbg, base_sec_index, - &relrec_to_fill); + &relrec_to_fill); if (res != DW_DLV_OK) return res; if (type == dwarf_drt_data_reloc) { - if (reltarget_length == dbg->de_offset_size) { + if (reltarget_length == dbg->de_dwarf_offset_size) { rel_type = dbg->de_offset_reloc; } else if (reltarget_length == dbg->de_pointer_size) { rel_type = dbg->de_ptr_reloc; @@ -91,8 +86,8 @@ _dwarf_pro_reloc_name_stream64(Dwarf_P_Debug dbg, } else if (type == dwarf_drt_segment_rel) { rel_type = dbg->de_exc_reloc; } else { - /* We are in trouble: improper use of stream relocations. - Someone else will diagnose */ + /* We are in trouble: improper use of stream relocations. + Someone else will diagnose */ rel_type = 0; } @@ -105,13 +100,10 @@ _dwarf_pro_reloc_name_stream64(Dwarf_P_Debug dbg, #endif /* #if HAVE_ELF64_GETEHDR */ } -/* - Return DW_DLV_ERROR on malloc error or reltarget_length error. - Return DW_DLV_OK otherwise - a binary reloc: 32bit ABI -*/ -int -_dwarf_pro_reloc_name_stream32(Dwarf_P_Debug dbg, int base_sec_index, +/* Return DW_DLV_ERROR on malloc error or reltarget_length error. + Return DW_DLV_OK otherwise + a binary reloc: 32bit ABI */ int +_dwarf_pro_reloc_name_stream32(Dwarf_P_Debug dbg, int base_sec_index, Dwarf_Unsigned offset, /* r_offset of reloc */ Dwarf_Unsigned symidx, enum Dwarf_Rel_Type type, @@ -123,11 +115,11 @@ _dwarf_pro_reloc_name_stream32(Dwarf_P_Debug dbg, int base_sec_index, int rel_type = 0; res = _dwarf_pro_reloc_get_a_slot(dbg, base_sec_index, - &relrec_to_fill); + &relrec_to_fill); if (res != DW_DLV_OK) return res; if (type == dwarf_drt_data_reloc) { - if (reltarget_length == dbg->de_offset_size) { + if (reltarget_length == dbg->de_dwarf_offset_size) { rel_type = dbg->de_offset_reloc; } else if (reltarget_length == dbg->de_pointer_size) { rel_type = dbg->de_ptr_reloc; @@ -137,14 +129,14 @@ _dwarf_pro_reloc_name_stream32(Dwarf_P_Debug dbg, int base_sec_index, } else if (type == dwarf_drt_segment_rel) { rel_type = dbg->de_exc_reloc; } else { - /* We are in trouble: improper use of stream relocations. - Someone else will diagnose */ + /* We are in trouble: improper use of stream relocations. + Someone else will diagnose */ rel_type = 0; } elf32_reloc = (REL32*)relrec_to_fill; elf32_reloc->r_offset = (Elf32_Addr) offset; - Set_REL32_info(*elf32_reloc, (Dwarf_Word) symidx, rel_type); + Set_REL32_info(*elf32_reloc, symidx, rel_type); return DW_DLV_OK; /* get a slot, fill in the slot entry */ @@ -152,56 +144,47 @@ _dwarf_pro_reloc_name_stream32(Dwarf_P_Debug dbg, int base_sec_index, -/* - Return DW_DLV_OK. - Never can really do anything: lengths cannot - be represented as end-start in a stream. - -*/ - /*ARGSUSED*/ int -_dwarf_pro_reloc_length_stream(Dwarf_P_Debug dbg, - int base_sec_index, - Dwarf_Unsigned offset, /* r_offset of reloc */ - Dwarf_Unsigned start_symidx, - Dwarf_Unsigned end_symidx, - enum Dwarf_Rel_Type type, - int reltarget_length) +/* Return DW_DLV_OK. + Never can really do anything: lengths cannot + be represented as end-start in a stream. */ +/*ARGSUSED*/ int +_dwarf_pro_reloc_length_stream(UNUSEDARG Dwarf_P_Debug dbg, + UNUSEDARG int base_sec_index, + UNUSEDARG Dwarf_Unsigned offset, /* r_offset of reloc */ + UNUSEDARG Dwarf_Unsigned start_symidx, + UNUSEDARG Dwarf_Unsigned end_symidx, + UNUSEDARG enum Dwarf_Rel_Type type, + UNUSEDARG int reltarget_length) { /* get a slot, fill in the slot entry */ return DW_DLV_OK; } -/* - Ensure each stream is a single buffer and - add that single buffer to the set of stream buffers. - - By creating a new buffer and copying if necessary. +/* Ensure each stream is a single buffer and + add that single buffer to the set of stream buffers. - Free the input set of buffers if we consolidate. - Return -1 on error (malloc failure) + By creating a new buffer and copying if necessary. + Free the input set of buffers if we consolidate. + Return -1 on error (malloc failure) - Return DW_DLV_OK on success. Any other return indicates - malloc failed. - -*/ + Return DW_DLV_OK on success. Any other return indicates + malloc failed. */ int _dwarf_stream_relocs_to_disk(Dwarf_P_Debug dbg, Dwarf_Signed * new_sec_count) { unsigned long total_size = 0; - Dwarf_Small *data = 0; - int sec_index = 0; - unsigned long i = 0; - Dwarf_Error err = 0; - Dwarf_Error *error = &err; - + int i = 0; + Dwarf_Error erre = 0; + Dwarf_Error *error = &erre; Dwarf_Signed sec_count = 0; - Dwarf_P_Per_Reloc_Sect p_reloc = &dbg->de_reloc_sect[0]; - - for (i = 0; i < NUM_DEBUG_SECTIONS; ++i, ++p_reloc) { + for (i = 0; i < NUM_DEBUG_SECTIONS; ++i) { + Dwarf_P_Per_Reloc_Sect p_reloc = dbg->de_reloc_sect +i; + Dwarf_Small *data = 0; + int sec_index = 0; unsigned long ct = p_reloc->pr_reloc_total_count; unsigned len = 0; struct Dwarf_P_Relocation_Block_s *p_blk = 0; @@ -218,38 +201,25 @@ _dwarf_stream_relocs_to_disk(Dwarf_P_Debug dbg, total_size = ct * len; sec_index = prb->pr_sect_num_of_reloc_sect; if (sec_index == 0) { - /* Call de_callback_func or de_callback_func_b, getting - section number of reloc section. */ + /* Call de_callback_func or de_callback_func_b or _c, getting + section number of reloc section. */ int rel_section_index = 0; Dwarf_Unsigned name_idx = 0; - int int_name = 0; - int err = 0; + int erri = 0; - if (dbg->de_callback_func_b) { - rel_section_index = - dbg->de_callback_func_b(_dwarf_rel_section_names[i], - /* size */ - dbg->de_relocation_record_size, - /* type */ SHT_REL, - /* flags */ 0, - /* link to symtab, which we cannot - know */ 0, - /* info == link to sec rels apply to - */ - dbg->de_elf_sects[i], - &name_idx, &err); - } else { + if (dbg->de_callback_func) { rel_section_index = dbg->de_callback_func(_dwarf_rel_section_names[i], - /* size */ - dbg->de_relocation_record_size, - /* type */ SHT_REL, - /* flags */ 0, - /* link to symtab, which we cannot - know */ 0, - /* info == link to sec rels apply to */ - dbg->de_elf_sects[i], &int_name, &err); - name_idx = int_name; + /* size */ dbg->de_relocation_record_size, + /* type */ SHT_REL, + /* flags */ 0, + /* link to symtab, which we cannot + know */ 0, + /* info == link to sec rels apply to */ + dbg->de_elf_sects[i], + &name_idx, + dbg->de_user_data, + &erri); } if (rel_section_index == -1) { { @@ -261,37 +231,34 @@ _dwarf_stream_relocs_to_disk(Dwarf_P_Debug dbg, prb->pr_sect_num_of_reloc_sect = rel_section_index; sec_index = rel_section_index; } - GET_CHUNK(dbg, sec_index, data, total_size, &err); + GET_CHUNK(dbg, sec_index, data, total_size, &erri); p_blk = p_reloc->pr_first_block; - /* following loop executes at least once. Effects the - consolidation to a single block or, if already a single - block, simply copies to the output buffer. And frees the - input block. The new block is in the de_debug_sects list. */ + /* Following loop executes at least once. Effects the + consolidation to a single block or, if already a single + block, simply copies to the output buffer. And frees the + input block. The new block is in the de_debug_sects list. */ while (p_blk) { - - unsigned long len = + unsigned long lenk = p_blk->rb_where_to_add_next - p_blk->rb_data; - memcpy(data, p_blk->rb_data, len); - - - data += len; - + memcpy(data, p_blk->rb_data, lenk); + data += lenk; p_blk_last = p_blk; p_blk = p_blk->rb_next; - _dwarf_p_dealloc(dbg, (Dwarf_Small *) p_blk_last); } /* ASSERT: sum of len copied == total_size */ - /* - We have copied the input, now drop the pointers to it. For - debugging, leave the other data untouched. */ + /* We have copied the input, now drop the pointers to it. For + debugging, leave the other data untouched. */ p_reloc->pr_first_block = 0; p_reloc->pr_last_block = 0; } - *new_sec_count = sec_count; return DW_DLV_OK; } +#else /* DWARF_WITH_LIBELF */ +/* avoids empty file warning if no libelf */ +int dwarf_dummy_pro_reloc_stream = 2; +#endif /* DWARF_WITH_LIBELF */ |