xref: /minix3/external/bsd/elftoolchain/dist/libdwarf/dwarf_get_relocation_info.3 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc.\"	$NetBSD: dwarf_get_relocation_info.3,v 1.2 2014/03/09 16:58:04 christos Exp $
2*0a6a1f1dSLionel Sambuc.\"
3*0a6a1f1dSLionel Sambuc.\" Copyright (c) 2011 Kai Wang
4*0a6a1f1dSLionel Sambuc.\" All rights reserved.
5*0a6a1f1dSLionel Sambuc.\"
6*0a6a1f1dSLionel Sambuc.\" Redistribution and use in source and binary forms, with or without
7*0a6a1f1dSLionel Sambuc.\" modification, are permitted provided that the following conditions
8*0a6a1f1dSLionel Sambuc.\" are met:
9*0a6a1f1dSLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright
10*0a6a1f1dSLionel Sambuc.\"    notice, this list of conditions and the following disclaimer.
11*0a6a1f1dSLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright
12*0a6a1f1dSLionel Sambuc.\"    notice, this list of conditions and the following disclaimer in the
13*0a6a1f1dSLionel Sambuc.\"    documentation and/or other materials provided with the distribution.
14*0a6a1f1dSLionel Sambuc.\"
15*0a6a1f1dSLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*0a6a1f1dSLionel Sambuc.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*0a6a1f1dSLionel Sambuc.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*0a6a1f1dSLionel Sambuc.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*0a6a1f1dSLionel Sambuc.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*0a6a1f1dSLionel Sambuc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*0a6a1f1dSLionel Sambuc.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*0a6a1f1dSLionel Sambuc.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*0a6a1f1dSLionel Sambuc.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*0a6a1f1dSLionel Sambuc.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*0a6a1f1dSLionel Sambuc.\" SUCH DAMAGE.
26*0a6a1f1dSLionel Sambuc.\"
27*0a6a1f1dSLionel Sambuc.\" Id: dwarf_get_relocation_info.3 2071 2011-10-27 03:20:00Z jkoshy
28*0a6a1f1dSLionel Sambuc.\"
29*0a6a1f1dSLionel Sambuc.Dd September 3, 2011
30*0a6a1f1dSLionel Sambuc.Os
31*0a6a1f1dSLionel Sambuc.Dt DWARF_GET_RELOCATION_INFO 3
32*0a6a1f1dSLionel Sambuc.Sh NAME
33*0a6a1f1dSLionel Sambuc.Nm dwarf_get_relocation_info
34*0a6a1f1dSLionel Sambuc.Nd retrieve generated relocation arrays
35*0a6a1f1dSLionel Sambuc.Sh LIBRARY
36*0a6a1f1dSLionel Sambuc.Lb libdwarf
37*0a6a1f1dSLionel Sambuc.Sh SYNOPSIS
38*0a6a1f1dSLionel Sambuc.In libdwarf.h
39*0a6a1f1dSLionel Sambuc.Ft int
40*0a6a1f1dSLionel Sambuc.Fo dwarf_get_relocation_info
41*0a6a1f1dSLionel Sambuc.Fa "Dwarf_P_Debug dbg"
42*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Signed *elf_section_index"
43*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Signed *elf_section_link"
44*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Unsigned *reloc_entry_count"
45*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Relocation_Data *reloc_buf"
46*0a6a1f1dSLionel Sambuc.Fa "Dwarf_Error *err"
47*0a6a1f1dSLionel Sambuc.Fc
48*0a6a1f1dSLionel Sambuc.Sh DESCRIPTION
49*0a6a1f1dSLionel SambucThe function
50*0a6a1f1dSLionel Sambuc.Fn dwarf_get_relocation_info
51*0a6a1f1dSLionel Sambucis used to retrieve the relocation arrays generated by a prior call to
52*0a6a1f1dSLionel Sambuc.Xr dwarf_transform_to_disk_form 3 .
53*0a6a1f1dSLionel Sambuc.Pp
54*0a6a1f1dSLionel SambucEach call to this function retrieves the next available relocation
55*0a6a1f1dSLionel Sambucarray.
56*0a6a1f1dSLionel SambucApplication code should call this function repeatly to retrieve all
57*0a6a1f1dSLionel Sambucthe relocation arrays.
58*0a6a1f1dSLionel SambucThe total number of generated relocation arrays retrievable
59*0a6a1f1dSLionel Sambucby this function may be obtained by calling function
60*0a6a1f1dSLionel Sambuc.Xr dwarf_get_relocation_info_count 3 .
61*0a6a1f1dSLionel Sambuc.Pp
62*0a6a1f1dSLionel SambucArgument
63*0a6a1f1dSLionel Sambuc.Ar dbg
64*0a6a1f1dSLionel Sambucshould reference a DWARF producer instance allocated using
65*0a6a1f1dSLionel Sambuc.Xr dwarf_producer_init 3 in sequence.
66*0a6a1f1dSLionel Sambucor
67*0a6a1f1dSLionel Sambuc.Xr dwarf_producer_init_b 3 .
68*0a6a1f1dSLionel SambucThe
69*0a6a1f1dSLionel Sambuc.Dv DW_DLC_SYMBOLIC_RELOCATIONS
70*0a6a1f1dSLionel Sambucflag should have been set on the DWARF producer instance.
71*0a6a1f1dSLionel Sambuc.Pp
72*0a6a1f1dSLionel SambucArgument
73*0a6a1f1dSLionel Sambuc.Ar elf_section_index
74*0a6a1f1dSLionel Sambucshould point to a location which will be set to the ELF section index
75*0a6a1f1dSLionel Sambucof the relocation section to which the retrieved relocation array
76*0a6a1f1dSLionel Sambucbelongs.
77*0a6a1f1dSLionel Sambuc.Pp
78*0a6a1f1dSLionel SambucArgument
79*0a6a1f1dSLionel Sambuc.Ar elf_section_link
80*0a6a1f1dSLionel Sambucshould point to a location which will be set to the section index of
81*0a6a1f1dSLionel Sambucthe ELF section to which the retrieved relocation array applies.
82*0a6a1f1dSLionel Sambuc.Pp
83*0a6a1f1dSLionel SambucArgument
84*0a6a1f1dSLionel Sambuc.Ar reloc_entry_count
85*0a6a1f1dSLionel Sambucshould point to a location which will be set to the total number of
86*0a6a1f1dSLionel Sambucrelocation entries contained in the relocation array.
87*0a6a1f1dSLionel Sambuc.Pp
88*0a6a1f1dSLionel SambucArgument
89*0a6a1f1dSLionel Sambuc.Ar reloc_buf
90*0a6a1f1dSLionel Sambucshould point to a location which will be set to a pointer to the
91*0a6a1f1dSLionel Sambucretrieved array of relocation entries.
92*0a6a1f1dSLionel Sambuc.Pp
93*0a6a1f1dSLionel SambucIf argument
94*0a6a1f1dSLionel Sambuc.Ar err
95*0a6a1f1dSLionel Sambucis not NULL, it will be used to store error information in case
96*0a6a1f1dSLionel Sambucof an error.
97*0a6a1f1dSLionel Sambuc.Pp
98*0a6a1f1dSLionel SambucThe retrieved relocation entries are described using structure
99*0a6a1f1dSLionel Sambuc.Vt Dwarf_Relocation_Data_s ,
100*0a6a1f1dSLionel Sambucdefined in the header file
101*0a6a1f1dSLionel Sambuc.In libdwarf.h :
102*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent
103*0a6a1f1dSLionel Sambuctypedef struct Dwarf_Relocation_Data_s {
104*0a6a1f1dSLionel Sambuc	unsigned char drd_type;
105*0a6a1f1dSLionel Sambuc	unsigned char drd_length;
106*0a6a1f1dSLionel Sambuc	Dwarf_Unsigned drd_offset;
107*0a6a1f1dSLionel Sambuc	Dwarf_Unsigned drd_symbol_index;
108*0a6a1f1dSLionel Sambuc} *Dwarf_Relocation_Data;
109*0a6a1f1dSLionel Sambuc.Ed
110*0a6a1f1dSLionel Sambuc.Pp
111*0a6a1f1dSLionel SambucStruct
112*0a6a1f1dSLionel Sambuc.Vt Dwarf_Relocation_Data_s
113*0a6a1f1dSLionel Sambucconsists of following fields:
114*0a6a1f1dSLionel Sambuc.Bl -tag -width ".Va drd_symbol_index" -compact -offset indent
115*0a6a1f1dSLionel Sambuc.It Va drd_type
116*0a6a1f1dSLionel SambucThe type code of the relocation entry.
117*0a6a1f1dSLionel SambucThe
118*0a6a1f1dSLionel Sambuc.Vt Dwarf_Rel_Type
119*0a6a1f1dSLionel Sambucenumeration defined in the header file
120*0a6a1f1dSLionel Sambuc.In libdwarf.h
121*0a6a1f1dSLionel Sambucspecifies legal values for this field.
122*0a6a1f1dSLionel Sambuc.It Va drd_length
123*0a6a1f1dSLionel SambucThe size in bytes of the field to be relocated.
124*0a6a1f1dSLionel Sambuc.It Va drd_offset
125*0a6a1f1dSLionel SambucThe section-relative offset of the field to be relocated.
126*0a6a1f1dSLionel Sambuc.It Va drd_symbol_index
127*0a6a1f1dSLionel SambucThe symbol index associated with the relocation entry.
128*0a6a1f1dSLionel Sambuc.El
129*0a6a1f1dSLionel Sambuc.Ss Memory Management
130*0a6a1f1dSLionel SambucThe memory area used for the relocation arrays is managed by the
131*0a6a1f1dSLionel Sambuc.Lb libdwarf .
132*0a6a1f1dSLionel SambucThe function
133*0a6a1f1dSLionel Sambuc.Fn dwarf_producer_finish
134*0a6a1f1dSLionel Sambucmay be used to release it, along with other resources associated
135*0a6a1f1dSLionel Sambucwith the producer instance.
136*0a6a1f1dSLionel Sambuc.Sh RETURN VALUES
137*0a6a1f1dSLionel SambucOn success, function
138*0a6a1f1dSLionel Sambuc.Fn dwarf_get_relocation_info
139*0a6a1f1dSLionel Sambucreturns
140*0a6a1f1dSLionel Sambuc.Dv DW_DLV_OK .
141*0a6a1f1dSLionel SambucIt returns
142*0a6a1f1dSLionel Sambuc.Dv DW_DLV_NO_ENTRY
143*0a6a1f1dSLionel Sambucif there were no more relocation arrays to retrieve, or if the flag
144*0a6a1f1dSLionel Sambuc.Dv DW_DLC_SYMBOLIC_RELOCATIONS
145*0a6a1f1dSLionel Sambucwas not set on the producer instance.
146*0a6a1f1dSLionel SambucIn case of an error, function
147*0a6a1f1dSLionel Sambuc.Fn dwarf_get_relocation_info
148*0a6a1f1dSLionel Sambucreturns
149*0a6a1f1dSLionel Sambuc.Dv DW_DLV_ERROR
150*0a6a1f1dSLionel Sambucand sets the argument
151*0a6a1f1dSLionel Sambuc.Ar err .
152*0a6a1f1dSLionel Sambuc.Sh ERRORS
153*0a6a1f1dSLionel SambucFunction
154*0a6a1f1dSLionel Sambuc.Fn dwarf_get_relocation_info
155*0a6a1f1dSLionel Sambuccan fail with:
156*0a6a1f1dSLionel Sambuc.Bl -tag -width ".Bq Er DW_DLE_NO_ENTRY"
157*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_ARGUMENT
158*0a6a1f1dSLionel SambucOne of the arguments
159*0a6a1f1dSLionel Sambuc.Ar dbg ,
160*0a6a1f1dSLionel Sambuc.Ar elf_section_index ,
161*0a6a1f1dSLionel Sambuc.Ar elf_section_link ,
162*0a6a1f1dSLionel Sambuc.Ar reloc_entry_count
163*0a6a1f1dSLionel Sambucor
164*0a6a1f1dSLionel Sambuc.Ar reloc_buf
165*0a6a1f1dSLionel Sambucwas NULL.
166*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_NO_ENTRY
167*0a6a1f1dSLionel SambucThere were no more ELF relocation arrays to retrieve.
168*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_NO_ENTRY
169*0a6a1f1dSLionel SambucThe flag
170*0a6a1f1dSLionel Sambuc.Dv DW_DLC_SYMBOLIC_RELOCATIONS
171*0a6a1f1dSLionel Sambucwas not set on the producer instance.
172*0a6a1f1dSLionel Sambuc.It Bq Er DW_DLE_NO_ENTRY
173*0a6a1f1dSLionel SambucFunction
174*0a6a1f1dSLionel Sambuc.Xr dwarf_transform_to_disk_form 3
175*0a6a1f1dSLionel Sambucwas not called prior to calling function
176*0a6a1f1dSLionel Sambuc.Fn dwarf_get_relocation_info .
177*0a6a1f1dSLionel Sambuc.El
178*0a6a1f1dSLionel Sambuc.Sh EXAMPLES
179*0a6a1f1dSLionel SambucTo generate relocation entries and retrieve them, use:
180*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent
181*0a6a1f1dSLionel SambucDwarf_P_Debug dbg;
182*0a6a1f1dSLionel SambucDwarf_Relocation_Data buf;
183*0a6a1f1dSLionel SambucDwarf_Signed count, index, link;
184*0a6a1f1dSLionel SambucDwarf_Unsigned reloc_cnt, entry_cnt;
185*0a6a1f1dSLionel SambucDwarf_Error de;
186*0a6a1f1dSLionel Sambucint version, i, j;
187*0a6a1f1dSLionel Sambuc
188*0a6a1f1dSLionel Sambuc/*
189*0a6a1f1dSLionel Sambuc * Assume that dbg refers to a DWARF producer instance created
190*0a6a1f1dSLionel Sambuc * created with DW_DLC_SYMBOLIC_RELOCATIONS flag set and that
191*0a6a1f1dSLionel Sambuc * application code has added DWARF debugging information
192*0a6a1f1dSLionel Sambuc * to the producer instance.
193*0a6a1f1dSLionel Sambuc */
194*0a6a1f1dSLionel Sambucif ((count = dwarf_transform_to_disk_form(dbg, &de)) ==
195*0a6a1f1dSLionel Sambuc    DW_DLV_NOCOUNT) {
196*0a6a1f1dSLionel Sambuc	warnx("dwarf_transform_to_disk_form failed: %s",
197*0a6a1f1dSLionel Sambuc	    dwarf_errmsg(-1));
198*0a6a1f1dSLionel Sambuc	return;
199*0a6a1f1dSLionel Sambuc}
200*0a6a1f1dSLionel Sambuc
201*0a6a1f1dSLionel Sambuc/* ... process generated section byte streams ... */
202*0a6a1f1dSLionel Sambucif (dwarf_get_relocation_info_count(dbg, &reloc_cnt, &version, &de) !=
203*0a6a1f1dSLionel Sambuc    DW_DLV_OK) {
204*0a6a1f1dSLionel Sambuc	warnx("dwarf_get_relocation_info_count failed: %s",
205*0a6a1f1dSLionel Sambuc	    dwarf_errmsg(-1));
206*0a6a1f1dSLionel Sambuc	return;
207*0a6a1f1dSLionel Sambuc}
208*0a6a1f1dSLionel Sambuc
209*0a6a1f1dSLionel Sambucfor (i = 0; (Dwarf_Unsigned) i < reloc_cnt; i++) {
210*0a6a1f1dSLionel Sambuc	if (dwarf_get_relocation_info(dbg, &index, &link, &entry_cnt,
211*0a6a1f1dSLionel Sambuc	    &buf, &de) != DW_DLV_OK) {
212*0a6a1f1dSLionel Sambuc		warnx("dwarf_get_relocation_info failed: %s",
213*0a6a1f1dSLionel Sambuc		    dwarf_errmsg(-1));
214*0a6a1f1dSLionel Sambuc		continue;
215*0a6a1f1dSLionel Sambuc	}
216*0a6a1f1dSLionel Sambuc	for (j = 0; (Dwarf_Unsigned) j < entry_cnt; j++) {
217*0a6a1f1dSLionel Sambuc		/* ...use each reloc data in buf[j]... */
218*0a6a1f1dSLionel Sambuc	}
219*0a6a1f1dSLionel Sambuc}
220*0a6a1f1dSLionel Sambuc
221*0a6a1f1dSLionel Sambucdwarf_producer_finish(dbg, &de);
222*0a6a1f1dSLionel Sambuc.Ed
223*0a6a1f1dSLionel Sambuc.Sh SEE ALSO
224*0a6a1f1dSLionel Sambuc.Xr dwarf 3 ,
225*0a6a1f1dSLionel Sambuc.Xr dwarf_get_relocation_info_count 3 ,
226*0a6a1f1dSLionel Sambuc.Xr dwarf_reset_section_bytes 3 ,
227*0a6a1f1dSLionel Sambuc.Xr dwarf_producer_finish 3 ,
228*0a6a1f1dSLionel Sambuc.Xr dwarf_producer_init 3 ,
229*0a6a1f1dSLionel Sambuc.Xr dwarf_producer_init_b 3 ,
230*0a6a1f1dSLionel Sambuc.Xr dwarf_transform_to_disk_form 3
231