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

/*
 * Assume that dbg refers to a DWARF producer instance created
 * created with DW_DLC_SYMBOLIC_RELOCATIONS flag set and that
 * application code has added DWARF debugging information
 * to the producer instance.
 */
if ((count = dwarf_transform_to_disk_form(dbg, &de)) ==
    DW_DLV_NOCOUNT) {
	warnx("dwarf_transform_to_disk_form failed: %s",
	    dwarf_errmsg(-1));
	return;
}

/* ... process generated section byte streams ... */
if (dwarf_get_relocation_info_count(dbg, &reloc_cnt, &version, &de) !=
    DW_DLV_OK) {
	warnx("dwarf_get_relocation_info_count failed: %s",
	    dwarf_errmsg(-1));
	return;
}

for (i = 0; (Dwarf_Unsigned) i < reloc_cnt; i++) {
	if (dwarf_get_relocation_info(dbg, &index, &link, &entry_cnt,
	    &buf, &de) != DW_DLV_OK) {
		warnx("dwarf_get_relocation_info failed: %s",
		    dwarf_errmsg(-1));
		continue;
	}
	for (j = 0; (Dwarf_Unsigned) j < entry_cnt; j++) {
		/* ...use each reloc data in buf[j]... */
	}
}

dwarf_producer_finish(dbg, &de);
.Ed
.Sh SEE ALSO
.Xr dwarf 3 ,
.Xr dwarf_get_relocation_info_count 3 ,
.Xr dwarf_reset_section_bytes 3 ,
.Xr dwarf_producer_finish 3 ,
.Xr dwarf_producer_init 3 ,
.Xr dwarf_producer_init_b 3 ,
.Xr dwarf_transform_to_disk_form 3