12de3b87aSKai Wang.\" Copyright (c) 2011 Kai Wang 22de3b87aSKai Wang.\" All rights reserved. 32de3b87aSKai Wang.\" 42de3b87aSKai Wang.\" Redistribution and use in source and binary forms, with or without 52de3b87aSKai Wang.\" modification, are permitted provided that the following conditions 62de3b87aSKai Wang.\" are met: 72de3b87aSKai Wang.\" 1. Redistributions of source code must retain the above copyright 82de3b87aSKai Wang.\" notice, this list of conditions and the following disclaimer. 92de3b87aSKai Wang.\" 2. Redistributions in binary form must reproduce the above copyright 102de3b87aSKai Wang.\" notice, this list of conditions and the following disclaimer in the 112de3b87aSKai Wang.\" documentation and/or other materials provided with the distribution. 122de3b87aSKai Wang.\" 132de3b87aSKai Wang.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 142de3b87aSKai Wang.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 152de3b87aSKai Wang.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 162de3b87aSKai Wang.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 172de3b87aSKai Wang.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 182de3b87aSKai Wang.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 192de3b87aSKai Wang.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 202de3b87aSKai Wang.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 212de3b87aSKai Wang.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 222de3b87aSKai Wang.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 232de3b87aSKai Wang.\" SUCH DAMAGE. 242de3b87aSKai Wang.\" 25*ae500c1fSEd Maste.\" $Id: dwarf_get_relocation_info.3 3644 2018-10-15 19:55:01Z jkoshy $ 262de3b87aSKai Wang.\" 272de3b87aSKai Wang.Dd September 3, 2011 282de3b87aSKai Wang.Dt DWARF_GET_RELOCATION_INFO 3 29*ae500c1fSEd Maste.Os 302de3b87aSKai Wang.Sh NAME 312de3b87aSKai Wang.Nm dwarf_get_relocation_info 322de3b87aSKai Wang.Nd retrieve generated relocation arrays 332de3b87aSKai Wang.Sh LIBRARY 342de3b87aSKai Wang.Lb libdwarf 352de3b87aSKai Wang.Sh SYNOPSIS 362de3b87aSKai Wang.In libdwarf.h 372de3b87aSKai Wang.Ft int 382de3b87aSKai Wang.Fo dwarf_get_relocation_info 392de3b87aSKai Wang.Fa "Dwarf_P_Debug dbg" 402de3b87aSKai Wang.Fa "Dwarf_Signed *elf_section_index" 412de3b87aSKai Wang.Fa "Dwarf_Signed *elf_section_link" 422de3b87aSKai Wang.Fa "Dwarf_Unsigned *reloc_entry_count" 432de3b87aSKai Wang.Fa "Dwarf_Relocation_Data *reloc_buf" 442de3b87aSKai Wang.Fa "Dwarf_Error *err" 452de3b87aSKai Wang.Fc 462de3b87aSKai Wang.Sh DESCRIPTION 472de3b87aSKai WangThe function 482de3b87aSKai Wang.Fn dwarf_get_relocation_info 492de3b87aSKai Wangis used to retrieve the relocation arrays generated by a prior call to 502de3b87aSKai Wang.Xr dwarf_transform_to_disk_form 3 . 512de3b87aSKai Wang.Pp 522de3b87aSKai WangEach call to this function retrieves the next available relocation 532de3b87aSKai Wangarray. 542de3b87aSKai WangApplication code should call this function repeatly to retrieve all 552de3b87aSKai Wangthe relocation arrays. 562de3b87aSKai WangThe total number of generated relocation arrays retrievable 572de3b87aSKai Wangby this function may be obtained by calling function 582de3b87aSKai Wang.Xr dwarf_get_relocation_info_count 3 . 592de3b87aSKai Wang.Pp 602de3b87aSKai WangArgument 612de3b87aSKai Wang.Ar dbg 622de3b87aSKai Wangshould reference a DWARF producer instance allocated using 632de3b87aSKai Wang.Xr dwarf_producer_init 3 in sequence. 642de3b87aSKai Wangor 652de3b87aSKai Wang.Xr dwarf_producer_init_b 3 . 662de3b87aSKai WangThe 672de3b87aSKai Wang.Dv DW_DLC_SYMBOLIC_RELOCATIONS 682de3b87aSKai Wangflag should have been set on the DWARF producer instance. 692de3b87aSKai Wang.Pp 702de3b87aSKai WangArgument 712de3b87aSKai Wang.Ar elf_section_index 722de3b87aSKai Wangshould point to a location which will be set to the ELF section index 732de3b87aSKai Wangof the relocation section to which the retrieved relocation array 742de3b87aSKai Wangbelongs. 752de3b87aSKai Wang.Pp 762de3b87aSKai WangArgument 772de3b87aSKai Wang.Ar elf_section_link 782de3b87aSKai Wangshould point to a location which will be set to the section index of 792de3b87aSKai Wangthe ELF section to which the retrieved relocation array applies. 802de3b87aSKai Wang.Pp 812de3b87aSKai WangArgument 822de3b87aSKai Wang.Ar reloc_entry_count 832de3b87aSKai Wangshould point to a location which will be set to the total number of 842de3b87aSKai Wangrelocation entries contained in the relocation array. 852de3b87aSKai Wang.Pp 862de3b87aSKai WangArgument 872de3b87aSKai Wang.Ar reloc_buf 882de3b87aSKai Wangshould point to a location which will be set to a pointer to the 892de3b87aSKai Wangretrieved array of relocation entries. 902de3b87aSKai Wang.Pp 912de3b87aSKai WangIf argument 922de3b87aSKai Wang.Ar err 932de3b87aSKai Wangis not NULL, it will be used to store error information in case 942de3b87aSKai Wangof an error. 952de3b87aSKai Wang.Pp 962de3b87aSKai WangThe retrieved relocation entries are described using structure 972de3b87aSKai Wang.Vt Dwarf_Relocation_Data_s , 982de3b87aSKai Wangdefined in the header file 992de3b87aSKai Wang.In libdwarf.h : 1002de3b87aSKai Wang.Bd -literal -offset indent 1012de3b87aSKai Wangtypedef struct Dwarf_Relocation_Data_s { 1022de3b87aSKai Wang unsigned char drd_type; 1032de3b87aSKai Wang unsigned char drd_length; 1042de3b87aSKai Wang Dwarf_Unsigned drd_offset; 1052de3b87aSKai Wang Dwarf_Unsigned drd_symbol_index; 1062de3b87aSKai Wang} *Dwarf_Relocation_Data; 1072de3b87aSKai Wang.Ed 1082de3b87aSKai Wang.Pp 1092de3b87aSKai WangStruct 1102de3b87aSKai Wang.Vt Dwarf_Relocation_Data_s 1112de3b87aSKai Wangconsists of following fields: 1122de3b87aSKai Wang.Bl -tag -width ".Va drd_symbol_index" -compact -offset indent 1132de3b87aSKai Wang.It Va drd_type 1142de3b87aSKai WangThe type code of the relocation entry. 1152de3b87aSKai WangThe 1162de3b87aSKai Wang.Vt Dwarf_Rel_Type 1172de3b87aSKai Wangenumeration defined in the header file 1182de3b87aSKai Wang.In libdwarf.h 1192de3b87aSKai Wangspecifies legal values for this field. 1202de3b87aSKai Wang.It Va drd_length 1212de3b87aSKai WangThe size in bytes of the field to be relocated. 1222de3b87aSKai Wang.It Va drd_offset 1232de3b87aSKai WangThe section-relative offset of the field to be relocated. 1242de3b87aSKai Wang.It Va drd_symbol_index 1252de3b87aSKai WangThe symbol index associated with the relocation entry. 1262de3b87aSKai Wang.El 1272de3b87aSKai Wang.Ss Memory Management 1282de3b87aSKai WangThe memory area used for the relocation arrays is managed by the 1292de3b87aSKai Wang.Lb libdwarf . 1302de3b87aSKai WangThe function 1312de3b87aSKai Wang.Fn dwarf_producer_finish 1322de3b87aSKai Wangmay be used to release it, along with other resources associated 1332de3b87aSKai Wangwith the producer instance. 1342de3b87aSKai Wang.Sh RETURN VALUES 1352de3b87aSKai WangOn success, function 1362de3b87aSKai Wang.Fn dwarf_get_relocation_info 1372de3b87aSKai Wangreturns 1382de3b87aSKai Wang.Dv DW_DLV_OK . 1392de3b87aSKai WangIt returns 1402de3b87aSKai Wang.Dv DW_DLV_NO_ENTRY 1412de3b87aSKai Wangif there were no more relocation arrays to retrieve, or if the flag 1422de3b87aSKai Wang.Dv DW_DLC_SYMBOLIC_RELOCATIONS 1432de3b87aSKai Wangwas not set on the producer instance. 1442de3b87aSKai WangIn case of an error, function 1452de3b87aSKai Wang.Fn dwarf_get_relocation_info 1462de3b87aSKai Wangreturns 1472de3b87aSKai Wang.Dv DW_DLV_ERROR 1482de3b87aSKai Wangand sets the argument 1492de3b87aSKai Wang.Ar err . 1502de3b87aSKai Wang.Sh EXAMPLES 1512de3b87aSKai WangTo generate relocation entries and retrieve them, use: 1522de3b87aSKai Wang.Bd -literal -offset indent 1532de3b87aSKai WangDwarf_P_Debug dbg; 1542de3b87aSKai WangDwarf_Relocation_Data buf; 1552de3b87aSKai WangDwarf_Signed count, index, link; 1562de3b87aSKai WangDwarf_Unsigned reloc_cnt, entry_cnt; 1572de3b87aSKai WangDwarf_Error de; 1582de3b87aSKai Wangint version, i, j; 1592de3b87aSKai Wang 1602de3b87aSKai Wang/* 1612de3b87aSKai Wang * Assume that dbg refers to a DWARF producer instance created 1622de3b87aSKai Wang * created with DW_DLC_SYMBOLIC_RELOCATIONS flag set and that 1632de3b87aSKai Wang * application code has added DWARF debugging information 1642de3b87aSKai Wang * to the producer instance. 1652de3b87aSKai Wang */ 1662de3b87aSKai Wangif ((count = dwarf_transform_to_disk_form(dbg, &de)) == 1672de3b87aSKai Wang DW_DLV_NOCOUNT) { 1682de3b87aSKai Wang warnx("dwarf_transform_to_disk_form failed: %s", 1692de3b87aSKai Wang dwarf_errmsg(-1)); 1702de3b87aSKai Wang return; 1712de3b87aSKai Wang} 1722de3b87aSKai Wang 1732de3b87aSKai Wang/* ... process generated section byte streams ... */ 1742de3b87aSKai Wangif (dwarf_get_relocation_info_count(dbg, &reloc_cnt, &version, &de) != 1752de3b87aSKai Wang DW_DLV_OK) { 1762de3b87aSKai Wang warnx("dwarf_get_relocation_info_count failed: %s", 1772de3b87aSKai Wang dwarf_errmsg(-1)); 1782de3b87aSKai Wang return; 1792de3b87aSKai Wang} 1802de3b87aSKai Wang 1812de3b87aSKai Wangfor (i = 0; (Dwarf_Unsigned) i < reloc_cnt; i++) { 1822de3b87aSKai Wang if (dwarf_get_relocation_info(dbg, &index, &link, &entry_cnt, 1832de3b87aSKai Wang &buf, &de) != DW_DLV_OK) { 1842de3b87aSKai Wang warnx("dwarf_get_relocation_info failed: %s", 1852de3b87aSKai Wang dwarf_errmsg(-1)); 1862de3b87aSKai Wang continue; 1872de3b87aSKai Wang } 1882de3b87aSKai Wang for (j = 0; (Dwarf_Unsigned) j < entry_cnt; j++) { 1892de3b87aSKai Wang /* ...use each reloc data in buf[j]... */ 1902de3b87aSKai Wang } 1912de3b87aSKai Wang} 1922de3b87aSKai Wang 1932de3b87aSKai Wangdwarf_producer_finish(dbg, &de); 1942de3b87aSKai Wang.Ed 195*ae500c1fSEd Maste.Sh ERRORS 196*ae500c1fSEd MasteFunction 197*ae500c1fSEd Maste.Fn dwarf_get_relocation_info 198*ae500c1fSEd Mastecan fail with: 199*ae500c1fSEd Maste.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY" 200*ae500c1fSEd Maste.It Bq Er DW_DLE_ARGUMENT 201*ae500c1fSEd MasteOne of the arguments 202*ae500c1fSEd Maste.Ar dbg , 203*ae500c1fSEd Maste.Ar elf_section_index , 204*ae500c1fSEd Maste.Ar elf_section_link , 205*ae500c1fSEd Maste.Ar reloc_entry_count 206*ae500c1fSEd Masteor 207*ae500c1fSEd Maste.Ar reloc_buf 208*ae500c1fSEd Mastewas NULL. 209*ae500c1fSEd Maste.It Bq Er DW_DLE_NO_ENTRY 210*ae500c1fSEd MasteThere were no more ELF relocation arrays to retrieve. 211*ae500c1fSEd Maste.It Bq Er DW_DLE_NO_ENTRY 212*ae500c1fSEd MasteThe flag 213*ae500c1fSEd Maste.Dv DW_DLC_SYMBOLIC_RELOCATIONS 214*ae500c1fSEd Mastewas not set on the producer instance. 215*ae500c1fSEd Maste.It Bq Er DW_DLE_NO_ENTRY 216*ae500c1fSEd MasteFunction 217*ae500c1fSEd Maste.Xr dwarf_transform_to_disk_form 3 218*ae500c1fSEd Mastewas not called prior to calling function 219*ae500c1fSEd Maste.Fn dwarf_get_relocation_info . 220*ae500c1fSEd Maste.El 2212de3b87aSKai Wang.Sh SEE ALSO 2222de3b87aSKai Wang.Xr dwarf 3 , 2232de3b87aSKai Wang.Xr dwarf_get_relocation_info_count 3 , 2242de3b87aSKai Wang.Xr dwarf_producer_finish 3 , 2252de3b87aSKai Wang.Xr dwarf_producer_init 3 , 2262de3b87aSKai Wang.Xr dwarf_producer_init_b 3 , 227*ae500c1fSEd Maste.Xr dwarf_reset_section_bytes 3 , 2282de3b87aSKai Wang.Xr dwarf_transform_to_disk_form 3 229