xref: /netbsd-src/external/gpl3/binutils.old/dist/libiberty/simple-object.txh (revision 16dce51364ebe8aeafbae46bc5aa167b8115bc45)
1*16dce513Schristos@c -*- mode: texinfo -*-
2*16dce513Schristos@deftypefn Extension {simple_object_read *} simple_object_open_read @
3*16dce513Schristos  (int @var{descriptor}, off_t @var{offset}, const char *{segment_name}, @
4*16dce513Schristos  const char **@var{errmsg}, int *@var{err})
5*16dce513Schristos
6*16dce513SchristosOpens an object file for reading.  Creates and returns an
7*16dce513Schristos@code{simple_object_read} pointer which may be passed to other
8*16dce513Schristosfunctions to extract data from the object file.
9*16dce513Schristos
10*16dce513Schristos@var{descriptor} holds a file descriptor which permits reading.
11*16dce513Schristos
12*16dce513Schristos@var{offset} is the offset into the file; this will be @code{0} in the
13*16dce513Schristosnormal case, but may be a different value when reading an object file
14*16dce513Schristosin an archive file.
15*16dce513Schristos
16*16dce513Schristos@var{segment_name} is only used with the Mach-O file format used on
17*16dce513SchristosDarwin aka Mac OS X.  It is required on that platform, and means to
18*16dce513Schristosonly look at sections within the segment with that name.  The
19*16dce513Schristosparameter is ignored on other systems.
20*16dce513Schristos
21*16dce513SchristosIf an error occurs, this functions returns @code{NULL} and sets
22*16dce513Schristos@code{*@var{errmsg}} to an error string and sets @code{*@var{err}} to
23*16dce513Schristosan errno value or @code{0} if there is no relevant errno.
24*16dce513Schristos
25*16dce513Schristos@end deftypefn
26*16dce513Schristos
27*16dce513Schristos@deftypefn Extension {const char *} simple_object_find_sections @
28*16dce513Schristos  (simple_object_read *@var{simple_object}, int (*@var{pfn}) (void *@var{data}, @
29*16dce513Schristos  const char *@var{name}, off_t @var{offset}, off_t @var{length}), @
30*16dce513Schristos  void *@var{data}, int *@var{err})
31*16dce513Schristos
32*16dce513SchristosThis function calls @var{pfn} for each section in @var{simple_object}.
33*16dce513SchristosIt calls @var{pfn} with the section name, the offset within the file
34*16dce513Schristosof the section contents, and the length of the section contents.  The
35*16dce513Schristosoffset within the file is relative to the offset passed to
36*16dce513Schristos@code{simple_object_open_read}.  The @var{data} argument to this
37*16dce513Schristosfunction is passed along to @var{pfn}.
38*16dce513Schristos
39*16dce513SchristosIf @var{pfn} returns @code{0}, the loop over the sections stops and
40*16dce513Schristos@code{simple_object_find_sections} returns.  If @var{pfn} returns some
41*16dce513Schristosother value, the loop continues.
42*16dce513Schristos
43*16dce513SchristosOn success @code{simple_object_find_sections} returns.  On error it
44*16dce513Schristosreturns an error string, and sets @code{*@var{err}} to an errno value
45*16dce513Schristosor @code{0} if there is no relevant errno.
46*16dce513Schristos
47*16dce513Schristos@end deftypefn
48*16dce513Schristos
49*16dce513Schristos@deftypefn Extension {int} simple_object_find_section @
50*16dce513Schristos  (simple_object_read *@var{simple_object} off_t *@var{offset}, @
51*16dce513Schristos  off_t *@var{length}, const char **@var{errmsg}, int *@var{err})
52*16dce513Schristos
53*16dce513SchristosLook for the section @var{name} in @var{simple_object}.  This returns
54*16dce513Schristosinformation for the first section with that name.
55*16dce513Schristos
56*16dce513SchristosIf found, return 1 and set @code{*@var{offset}} to the offset in the
57*16dce513Schristosfile of the section contents and set @code{*@var{length}} to the
58*16dce513Schristoslength of the section contents.  The value in @code{*@var{offset}}
59*16dce513Schristoswill be relative to the offset passed to
60*16dce513Schristos@code{simple_object_open_read}.
61*16dce513Schristos
62*16dce513SchristosIf the section is not found, and no error occurs,
63*16dce513Schristos@code{simple_object_find_section} returns @code{0} and set
64*16dce513Schristos@code{*@var{errmsg}} to @code{NULL}.
65*16dce513Schristos
66*16dce513SchristosIf an error occurs, @code{simple_object_find_section} returns
67*16dce513Schristos@code{0}, sets @code{*@var{errmsg}} to an error message, and sets
68*16dce513Schristos@code{*@var{err}} to an errno value or @code{0} if there is no
69*16dce513Schristosrelevant errno.
70*16dce513Schristos
71*16dce513Schristos@end deftypefn
72*16dce513Schristos
73*16dce513Schristos@deftypefn Extension {void} simple_object_release_read @
74*16dce513Schristos  (simple_object_read *@var{simple_object})
75*16dce513Schristos
76*16dce513SchristosRelease all resources associated with @var{simple_object}.  This does
77*16dce513Schristosnot close the file descriptor.
78*16dce513Schristos
79*16dce513Schristos@end deftypefn
80*16dce513Schristos
81*16dce513Schristos@deftypefn Extension {simple_object_attributes *} simple_object_fetch_attributes @
82*16dce513Schristos  (simple_object_read *@var{simple_object}, const char **@var{errmsg}, int *@var{err})
83*16dce513Schristos
84*16dce513SchristosFetch the attributes of @var{simple_object}.  The attributes are
85*16dce513Schristosinternal information such as the format of the object file, or the
86*16dce513Schristosarchitecture it was compiled for.  This information will persist until
87*16dce513Schristos@code{simple_object_attributes_release} is called, even if
88*16dce513Schristos@var{simple_object} itself is released.
89*16dce513Schristos
90*16dce513SchristosOn error this returns @code{NULL}, sets @code{*@var{errmsg}} to an
91*16dce513Schristoserror message, and sets @code{*@var{err}} to an errno value or
92*16dce513Schristos@code{0} if there is no relevant errno.
93*16dce513Schristos
94*16dce513Schristos@end deftypefn
95*16dce513Schristos
96*16dce513Schristos@deftypefn Extension {const char *} simple_object_attributes_compare @
97*16dce513Schristos  (simple_object_attributes *@var{attrs1}, simple_object_attributes *@var{attrs2}, @
98*16dce513Schristos   int *@var{err})
99*16dce513Schristos
100*16dce513SchristosCompare @var{attrs1} and @var{attrs2}.  If they could be linked
101*16dce513Schristostogether without error, return @code{NULL}.  Otherwise, return an
102*16dce513Schristoserror message and set @code{*@var{err}} to an errno value or @code{0}
103*16dce513Schristosif there is no relevant errno.
104*16dce513Schristos
105*16dce513Schristos@end deftypefn
106*16dce513Schristos
107*16dce513Schristos@deftypefn Extension {void} simple_object_release_attributes @
108*16dce513Schristos  (simple_object_attributes *@var{attrs})
109*16dce513Schristos
110*16dce513SchristosRelease all resources associated with @var{attrs}.
111*16dce513Schristos
112*16dce513Schristos@end deftypefn
113*16dce513Schristos
114*16dce513Schristos@deftypefn Extension {simple_object_write *} simple_object_start_write @
115*16dce513Schristos  (simple_object_attributes @var{attrs}, const char *@var{segment_name}, @
116*16dce513Schristos  const char **@var{errmsg}, int *@var{err})
117*16dce513Schristos
118*16dce513SchristosStart creating a new object file using the object file format
119*16dce513Schristosdescribed in @var{attrs}.  You must fetch attribute information from
120*16dce513Schristosan existing object file before you can create a new one.  There is
121*16dce513Schristoscurrently no support for creating an object file de novo.
122*16dce513Schristos
123*16dce513Schristos@var{segment_name} is only used with Mach-O as found on Darwin aka Mac
124*16dce513SchristosOS X.  The parameter is required on that target.  It means that all
125*16dce513Schristossections are created within the named segment.  It is ignored for
126*16dce513Schristosother object file formats.
127*16dce513Schristos
128*16dce513SchristosOn error @code{simple_object_start_write} returns @code{NULL}, sets
129*16dce513Schristos@code{*@var{ERRMSG}} to an error message, and sets @code{*@var{err}}
130*16dce513Schristosto an errno value or @code{0} if there is no relevant errno.
131*16dce513Schristos
132*16dce513Schristos@end deftypefn
133*16dce513Schristos
134*16dce513Schristos@deftypefn Extension {simple_object_write_section *} simple_object_write_create_section @
135*16dce513Schristos  (simple_object_write *@var{simple_object}, const char *@var{name}, @
136*16dce513Schristos  unsigned int @var{align}, const char **@var{errmsg}, int *@var{err})
137*16dce513Schristos
138*16dce513SchristosAdd a section to @var{simple_object}.  @var{name} is the name of the
139*16dce513Schristosnew section.  @var{align} is the required alignment expressed as the
140*16dce513Schristosnumber of required low-order 0 bits (e.g., 2 for alignment to a 32-bit
141*16dce513Schristosboundary).
142*16dce513Schristos
143*16dce513SchristosThe section is created as containing data, readable, not writable, not
144*16dce513Schristosexecutable, not loaded at runtime.  The section is not written to the
145*16dce513Schristosfile until @code{simple_object_write_to_file} is called.
146*16dce513Schristos
147*16dce513SchristosOn error this returns @code{NULL}, sets @code{*@var{errmsg}} to an
148*16dce513Schristoserror message, and sets @code{*@var{err}} to an errno value or
149*16dce513Schristos@code{0} if there is no relevant errno.
150*16dce513Schristos
151*16dce513Schristos@end deftypefn
152*16dce513Schristos
153*16dce513Schristos@deftypefn Extension {const char *} simple_object_write_add_data @
154*16dce513Schristos  (simple_object_write *@var{simple_object}, @
155*16dce513Schristos  simple_object_write_section *@var{section}, const void *@var{buffer}, @
156*16dce513Schristos  size_t @var{size}, int @var{copy}, int *@var{err})
157*16dce513Schristos
158*16dce513SchristosAdd data @var{buffer}/@var{size} to @var{section} in
159*16dce513Schristos@var{simple_object}.  If @var{copy} is non-zero, the data will be
160*16dce513Schristoscopied into memory if necessary.  If @var{copy} is zero, @var{buffer}
161*16dce513Schristosmust persist until @code{simple_object_write_to_file} is called.  is
162*16dce513Schristosreleased.
163*16dce513Schristos
164*16dce513SchristosOn success this returns @code{NULL}.  On error this returns an error
165*16dce513Schristosmessage, and sets @code{*@var{err}} to an errno value or 0 if there is
166*16dce513Schristosno relevant erro.
167*16dce513Schristos
168*16dce513Schristos@end deftypefn
169*16dce513Schristos
170*16dce513Schristos@deftypefn Extension {const char *} simple_object_write_to_file @
171*16dce513Schristos  (simple_object_write *@var{simple_object}, int @var{descriptor}, int *@var{err})
172*16dce513Schristos
173*16dce513SchristosWrite the complete object file to @var{descriptor}, an open file
174*16dce513Schristosdescriptor.  This writes out all the data accumulated by calls to
175*16dce513Schristos@code{simple_object_write_create_section} and
176*16dce513Schristos@var{simple_object_write_add_data}.
177*16dce513Schristos
178*16dce513SchristosThis returns @code{NULL} on success.  On error this returns an error
179*16dce513Schristosmessage and sets @code{*@var{err}} to an errno value or @code{0} if
180*16dce513Schristosthere is no relevant errno.
181*16dce513Schristos
182*16dce513Schristos@end deftypefn
183*16dce513Schristos
184*16dce513Schristos@deftypefn Extension {void} simple_object_release_write @
185*16dce513Schristos  (simple_object_write *@var{simple_object})
186*16dce513Schristos
187*16dce513SchristosRelease all resources associated with @var{simple_object}.
188*16dce513Schristos
189*16dce513Schristos@end deftypefn
190