1*5ac3bc71Schristos.\" $NetBSD: dwarf_get_relocation_info.3,v 1.6 2024/03/03 17:37:31 christos Exp $ 2e81373b4Schristos.\" 39dd9d0cfSchristos.\" Copyright (c) 2011 Kai Wang 49dd9d0cfSchristos.\" All rights reserved. 59dd9d0cfSchristos.\" 69dd9d0cfSchristos.\" Redistribution and use in source and binary forms, with or without 79dd9d0cfSchristos.\" modification, are permitted provided that the following conditions 89dd9d0cfSchristos.\" are met: 99dd9d0cfSchristos.\" 1. Redistributions of source code must retain the above copyright 109dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer. 119dd9d0cfSchristos.\" 2. Redistributions in binary form must reproduce the above copyright 129dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer in the 139dd9d0cfSchristos.\" documentation and/or other materials provided with the distribution. 149dd9d0cfSchristos.\" 159dd9d0cfSchristos.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 169dd9d0cfSchristos.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 179dd9d0cfSchristos.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 189dd9d0cfSchristos.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 199dd9d0cfSchristos.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 209dd9d0cfSchristos.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 219dd9d0cfSchristos.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 229dd9d0cfSchristos.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 239dd9d0cfSchristos.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 249dd9d0cfSchristos.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 259dd9d0cfSchristos.\" SUCH DAMAGE. 269dd9d0cfSchristos.\" 27cdbf1fe1Sjkoshy.\" Id: dwarf_get_relocation_info.3 3963 2022-03-12 16:07:32Z jkoshy 289dd9d0cfSchristos.\" 299dd9d0cfSchristos.Dd September 3, 2011 309dd9d0cfSchristos.Dt DWARF_GET_RELOCATION_INFO 3 31604b0842Sjkoshy.Os 329dd9d0cfSchristos.Sh NAME 339dd9d0cfSchristos.Nm dwarf_get_relocation_info 349dd9d0cfSchristos.Nd retrieve generated relocation arrays 359dd9d0cfSchristos.Sh LIBRARY 369dd9d0cfSchristos.Lb libdwarf 379dd9d0cfSchristos.Sh SYNOPSIS 389dd9d0cfSchristos.In libdwarf.h 399dd9d0cfSchristos.Ft int 409dd9d0cfSchristos.Fo dwarf_get_relocation_info 419dd9d0cfSchristos.Fa "Dwarf_P_Debug dbg" 429dd9d0cfSchristos.Fa "Dwarf_Signed *elf_section_index" 439dd9d0cfSchristos.Fa "Dwarf_Signed *elf_section_link" 449dd9d0cfSchristos.Fa "Dwarf_Unsigned *reloc_entry_count" 459dd9d0cfSchristos.Fa "Dwarf_Relocation_Data *reloc_buf" 469dd9d0cfSchristos.Fa "Dwarf_Error *err" 479dd9d0cfSchristos.Fc 489dd9d0cfSchristos.Sh DESCRIPTION 499dd9d0cfSchristosThe function 509dd9d0cfSchristos.Fn dwarf_get_relocation_info 519dd9d0cfSchristosis used to retrieve the relocation arrays generated by a prior call to 529dd9d0cfSchristos.Xr dwarf_transform_to_disk_form 3 . 539dd9d0cfSchristos.Pp 549dd9d0cfSchristosEach call to this function retrieves the next available relocation 559dd9d0cfSchristosarray. 569dd9d0cfSchristosApplication code should call this function repeatly to retrieve all 579dd9d0cfSchristosthe relocation arrays. 589dd9d0cfSchristosThe total number of generated relocation arrays retrievable 599dd9d0cfSchristosby this function may be obtained by calling function 609dd9d0cfSchristos.Xr dwarf_get_relocation_info_count 3 . 619dd9d0cfSchristos.Pp 629dd9d0cfSchristosArgument 63cdbf1fe1Sjkoshy.Fa dbg 649dd9d0cfSchristosshould reference a DWARF producer instance allocated using 659dd9d0cfSchristos.Xr dwarf_producer_init 3 in sequence. 669dd9d0cfSchristosor 679dd9d0cfSchristos.Xr dwarf_producer_init_b 3 . 689dd9d0cfSchristosThe 699dd9d0cfSchristos.Dv DW_DLC_SYMBOLIC_RELOCATIONS 709dd9d0cfSchristosflag should have been set on the DWARF producer instance. 719dd9d0cfSchristos.Pp 729dd9d0cfSchristosArgument 73cdbf1fe1Sjkoshy.Fa elf_section_index 749dd9d0cfSchristosshould point to a location which will be set to the ELF section index 759dd9d0cfSchristosof the relocation section to which the retrieved relocation array 769dd9d0cfSchristosbelongs. 779dd9d0cfSchristos.Pp 789dd9d0cfSchristosArgument 79cdbf1fe1Sjkoshy.Fa elf_section_link 809dd9d0cfSchristosshould point to a location which will be set to the section index of 819dd9d0cfSchristosthe ELF section to which the retrieved relocation array applies. 829dd9d0cfSchristos.Pp 839dd9d0cfSchristosArgument 84cdbf1fe1Sjkoshy.Fa reloc_entry_count 859dd9d0cfSchristosshould point to a location which will be set to the total number of 869dd9d0cfSchristosrelocation entries contained in the relocation array. 879dd9d0cfSchristos.Pp 889dd9d0cfSchristosArgument 89cdbf1fe1Sjkoshy.Fa reloc_buf 909dd9d0cfSchristosshould point to a location which will be set to a pointer to the 919dd9d0cfSchristosretrieved array of relocation entries. 929dd9d0cfSchristos.Pp 939dd9d0cfSchristosIf argument 94cdbf1fe1Sjkoshy.Fa err 95cdbf1fe1Sjkoshyis not 96cdbf1fe1Sjkoshy.Dv NULL , 97cdbf1fe1Sjkoshyit will be used to store error information in case of an error. 989dd9d0cfSchristos.Pp 999dd9d0cfSchristosThe retrieved relocation entries are described using structure 1009dd9d0cfSchristos.Vt Dwarf_Relocation_Data_s , 1019dd9d0cfSchristosdefined in the header file 1029dd9d0cfSchristos.In libdwarf.h : 1039dd9d0cfSchristos.Bd -literal -offset indent 1049dd9d0cfSchristostypedef struct Dwarf_Relocation_Data_s { 1059dd9d0cfSchristos unsigned char drd_type; 1069dd9d0cfSchristos unsigned char drd_length; 1079dd9d0cfSchristos Dwarf_Unsigned drd_offset; 1089dd9d0cfSchristos Dwarf_Unsigned drd_symbol_index; 1099dd9d0cfSchristos} *Dwarf_Relocation_Data; 1109dd9d0cfSchristos.Ed 1119dd9d0cfSchristos.Pp 1129dd9d0cfSchristosStruct 1139dd9d0cfSchristos.Vt Dwarf_Relocation_Data_s 1149dd9d0cfSchristosconsists of following fields: 1159dd9d0cfSchristos.Bl -tag -width ".Va drd_symbol_index" -compact -offset indent 1169dd9d0cfSchristos.It Va drd_type 1179dd9d0cfSchristosThe type code of the relocation entry. 1189dd9d0cfSchristosThe 1199dd9d0cfSchristos.Vt Dwarf_Rel_Type 1209dd9d0cfSchristosenumeration defined in the header file 1219dd9d0cfSchristos.In libdwarf.h 1229dd9d0cfSchristosspecifies legal values for this field. 1239dd9d0cfSchristos.It Va drd_length 1249dd9d0cfSchristosThe size in bytes of the field to be relocated. 1259dd9d0cfSchristos.It Va drd_offset 1269dd9d0cfSchristosThe section-relative offset of the field to be relocated. 1279dd9d0cfSchristos.It Va drd_symbol_index 1289dd9d0cfSchristosThe symbol index associated with the relocation entry. 1299dd9d0cfSchristos.El 1309dd9d0cfSchristos.Ss Memory Management 1319dd9d0cfSchristosThe memory area used for the relocation arrays is managed by the 1329dd9d0cfSchristos.Lb libdwarf . 1339dd9d0cfSchristosThe function 1349dd9d0cfSchristos.Fn dwarf_producer_finish 1359dd9d0cfSchristosmay be used to release it, along with other resources associated 1369dd9d0cfSchristoswith the producer instance. 1379dd9d0cfSchristos.Sh RETURN VALUES 1389dd9d0cfSchristosOn success, function 1399dd9d0cfSchristos.Fn dwarf_get_relocation_info 1409dd9d0cfSchristosreturns 1419dd9d0cfSchristos.Dv DW_DLV_OK . 1429dd9d0cfSchristosIt returns 1439dd9d0cfSchristos.Dv DW_DLV_NO_ENTRY 1449dd9d0cfSchristosif there were no more relocation arrays to retrieve, or if the flag 1459dd9d0cfSchristos.Dv DW_DLC_SYMBOLIC_RELOCATIONS 1469dd9d0cfSchristoswas not set on the producer instance. 1479dd9d0cfSchristosIn case of an error, function 1489dd9d0cfSchristos.Fn dwarf_get_relocation_info 1499dd9d0cfSchristosreturns 1509dd9d0cfSchristos.Dv DW_DLV_ERROR 1519dd9d0cfSchristosand sets the argument 152cdbf1fe1Sjkoshy.Fa err . 1539dd9d0cfSchristos.Sh EXAMPLES 1549dd9d0cfSchristosTo generate relocation entries and retrieve them, use: 1559dd9d0cfSchristos.Bd -literal -offset indent 1569dd9d0cfSchristosDwarf_P_Debug dbg; 1579dd9d0cfSchristosDwarf_Relocation_Data buf; 1589dd9d0cfSchristosDwarf_Signed count, index, link; 1599dd9d0cfSchristosDwarf_Unsigned reloc_cnt, entry_cnt; 1609dd9d0cfSchristosDwarf_Error de; 1619dd9d0cfSchristosint version, i, j; 1629dd9d0cfSchristos 1639dd9d0cfSchristos/* 1649dd9d0cfSchristos * Assume that dbg refers to a DWARF producer instance created 1659dd9d0cfSchristos * created with DW_DLC_SYMBOLIC_RELOCATIONS flag set and that 1669dd9d0cfSchristos * application code has added DWARF debugging information 1679dd9d0cfSchristos * to the producer instance. 1689dd9d0cfSchristos */ 1699dd9d0cfSchristosif ((count = dwarf_transform_to_disk_form(dbg, &de)) == 1709dd9d0cfSchristos DW_DLV_NOCOUNT) { 1719dd9d0cfSchristos warnx("dwarf_transform_to_disk_form failed: %s", 1729dd9d0cfSchristos dwarf_errmsg(-1)); 1739dd9d0cfSchristos return; 1749dd9d0cfSchristos} 1759dd9d0cfSchristos 1769dd9d0cfSchristos/* ... process generated section byte streams ... */ 1779dd9d0cfSchristosif (dwarf_get_relocation_info_count(dbg, &reloc_cnt, &version, &de) != 1789dd9d0cfSchristos DW_DLV_OK) { 1799dd9d0cfSchristos warnx("dwarf_get_relocation_info_count failed: %s", 1809dd9d0cfSchristos dwarf_errmsg(-1)); 1819dd9d0cfSchristos return; 1829dd9d0cfSchristos} 1839dd9d0cfSchristos 1849dd9d0cfSchristosfor (i = 0; (Dwarf_Unsigned) i < reloc_cnt; i++) { 1859dd9d0cfSchristos if (dwarf_get_relocation_info(dbg, &index, &link, &entry_cnt, 1869dd9d0cfSchristos &buf, &de) != DW_DLV_OK) { 1879dd9d0cfSchristos warnx("dwarf_get_relocation_info failed: %s", 1889dd9d0cfSchristos dwarf_errmsg(-1)); 1899dd9d0cfSchristos continue; 1909dd9d0cfSchristos } 1919dd9d0cfSchristos for (j = 0; (Dwarf_Unsigned) j < entry_cnt; j++) { 1929dd9d0cfSchristos /* ...use each reloc data in buf[j]... */ 1939dd9d0cfSchristos } 1949dd9d0cfSchristos} 1959dd9d0cfSchristos 1969dd9d0cfSchristosdwarf_producer_finish(dbg, &de); 1979dd9d0cfSchristos.Ed 198604b0842Sjkoshy.Sh ERRORS 199604b0842SjkoshyFunction 200604b0842Sjkoshy.Fn dwarf_get_relocation_info 201604b0842Sjkoshycan fail with: 202604b0842Sjkoshy.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY" 203604b0842Sjkoshy.It Bq Er DW_DLE_ARGUMENT 204604b0842SjkoshyOne of the arguments 205cdbf1fe1Sjkoshy.Fa dbg , 206cdbf1fe1Sjkoshy.Fa elf_section_index , 207cdbf1fe1Sjkoshy.Fa elf_section_link , 208cdbf1fe1Sjkoshy.Fa reloc_entry_count 209604b0842Sjkoshyor 210cdbf1fe1Sjkoshy.Fa reloc_buf 211cdbf1fe1Sjkoshywas 212cdbf1fe1Sjkoshy.Dv NULL . 213604b0842Sjkoshy.It Bq Er DW_DLE_NO_ENTRY 214604b0842SjkoshyThere were no more ELF relocation arrays to retrieve. 215604b0842Sjkoshy.It Bq Er DW_DLE_NO_ENTRY 216604b0842SjkoshyThe flag 217604b0842Sjkoshy.Dv DW_DLC_SYMBOLIC_RELOCATIONS 218604b0842Sjkoshywas not set on the producer instance. 219604b0842Sjkoshy.It Bq Er DW_DLE_NO_ENTRY 220604b0842SjkoshyFunction 221604b0842Sjkoshy.Xr dwarf_transform_to_disk_form 3 222604b0842Sjkoshywas not called prior to calling function 223604b0842Sjkoshy.Fn dwarf_get_relocation_info . 224604b0842Sjkoshy.El 2259dd9d0cfSchristos.Sh SEE ALSO 2269dd9d0cfSchristos.Xr dwarf 3 , 2279dd9d0cfSchristos.Xr dwarf_get_relocation_info_count 3 , 2289dd9d0cfSchristos.Xr dwarf_producer_finish 3 , 2299dd9d0cfSchristos.Xr dwarf_producer_init 3 , 2309dd9d0cfSchristos.Xr dwarf_producer_init_b 3 , 231604b0842Sjkoshy.Xr dwarf_reset_section_bytes 3 , 2329dd9d0cfSchristos.Xr dwarf_transform_to_disk_form 3 233