xref: /dflybsd-src/contrib/binutils-2.27/libiberty/simple-object.txh (revision e656dc90e3d65d744d534af2f5ea88cf8101ebcf)
1*a9fa9459Szrj@c -*- mode: texinfo -*-
2*a9fa9459Szrj@deftypefn Extension {simple_object_read *} simple_object_open_read @
3*a9fa9459Szrj  (int @var{descriptor}, off_t @var{offset}, const char *{segment_name}, @
4*a9fa9459Szrj  const char **@var{errmsg}, int *@var{err})
5*a9fa9459Szrj
6*a9fa9459SzrjOpens an object file for reading.  Creates and returns an
7*a9fa9459Szrj@code{simple_object_read} pointer which may be passed to other
8*a9fa9459Szrjfunctions to extract data from the object file.
9*a9fa9459Szrj
10*a9fa9459Szrj@var{descriptor} holds a file descriptor which permits reading.
11*a9fa9459Szrj
12*a9fa9459Szrj@var{offset} is the offset into the file; this will be @code{0} in the
13*a9fa9459Szrjnormal case, but may be a different value when reading an object file
14*a9fa9459Szrjin an archive file.
15*a9fa9459Szrj
16*a9fa9459Szrj@var{segment_name} is only used with the Mach-O file format used on
17*a9fa9459SzrjDarwin aka Mac OS X.  It is required on that platform, and means to
18*a9fa9459Szrjonly look at sections within the segment with that name.  The
19*a9fa9459Szrjparameter is ignored on other systems.
20*a9fa9459Szrj
21*a9fa9459SzrjIf an error occurs, this functions returns @code{NULL} and sets
22*a9fa9459Szrj@code{*@var{errmsg}} to an error string and sets @code{*@var{err}} to
23*a9fa9459Szrjan errno value or @code{0} if there is no relevant errno.
24*a9fa9459Szrj
25*a9fa9459Szrj@end deftypefn
26*a9fa9459Szrj
27*a9fa9459Szrj@deftypefn Extension {const char *} simple_object_find_sections @
28*a9fa9459Szrj  (simple_object_read *@var{simple_object}, int (*@var{pfn}) (void *@var{data}, @
29*a9fa9459Szrj  const char *@var{name}, off_t @var{offset}, off_t @var{length}), @
30*a9fa9459Szrj  void *@var{data}, int *@var{err})
31*a9fa9459Szrj
32*a9fa9459SzrjThis function calls @var{pfn} for each section in @var{simple_object}.
33*a9fa9459SzrjIt calls @var{pfn} with the section name, the offset within the file
34*a9fa9459Szrjof the section contents, and the length of the section contents.  The
35*a9fa9459Szrjoffset within the file is relative to the offset passed to
36*a9fa9459Szrj@code{simple_object_open_read}.  The @var{data} argument to this
37*a9fa9459Szrjfunction is passed along to @var{pfn}.
38*a9fa9459Szrj
39*a9fa9459SzrjIf @var{pfn} returns @code{0}, the loop over the sections stops and
40*a9fa9459Szrj@code{simple_object_find_sections} returns.  If @var{pfn} returns some
41*a9fa9459Szrjother value, the loop continues.
42*a9fa9459Szrj
43*a9fa9459SzrjOn success @code{simple_object_find_sections} returns.  On error it
44*a9fa9459Szrjreturns an error string, and sets @code{*@var{err}} to an errno value
45*a9fa9459Szrjor @code{0} if there is no relevant errno.
46*a9fa9459Szrj
47*a9fa9459Szrj@end deftypefn
48*a9fa9459Szrj
49*a9fa9459Szrj@deftypefn Extension {int} simple_object_find_section @
50*a9fa9459Szrj  (simple_object_read *@var{simple_object} off_t *@var{offset}, @
51*a9fa9459Szrj  off_t *@var{length}, const char **@var{errmsg}, int *@var{err})
52*a9fa9459Szrj
53*a9fa9459SzrjLook for the section @var{name} in @var{simple_object}.  This returns
54*a9fa9459Szrjinformation for the first section with that name.
55*a9fa9459Szrj
56*a9fa9459SzrjIf found, return 1 and set @code{*@var{offset}} to the offset in the
57*a9fa9459Szrjfile of the section contents and set @code{*@var{length}} to the
58*a9fa9459Szrjlength of the section contents.  The value in @code{*@var{offset}}
59*a9fa9459Szrjwill be relative to the offset passed to
60*a9fa9459Szrj@code{simple_object_open_read}.
61*a9fa9459Szrj
62*a9fa9459SzrjIf the section is not found, and no error occurs,
63*a9fa9459Szrj@code{simple_object_find_section} returns @code{0} and set
64*a9fa9459Szrj@code{*@var{errmsg}} to @code{NULL}.
65*a9fa9459Szrj
66*a9fa9459SzrjIf an error occurs, @code{simple_object_find_section} returns
67*a9fa9459Szrj@code{0}, sets @code{*@var{errmsg}} to an error message, and sets
68*a9fa9459Szrj@code{*@var{err}} to an errno value or @code{0} if there is no
69*a9fa9459Szrjrelevant errno.
70*a9fa9459Szrj
71*a9fa9459Szrj@end deftypefn
72*a9fa9459Szrj
73*a9fa9459Szrj@deftypefn Extension {void} simple_object_release_read @
74*a9fa9459Szrj  (simple_object_read *@var{simple_object})
75*a9fa9459Szrj
76*a9fa9459SzrjRelease all resources associated with @var{simple_object}.  This does
77*a9fa9459Szrjnot close the file descriptor.
78*a9fa9459Szrj
79*a9fa9459Szrj@end deftypefn
80*a9fa9459Szrj
81*a9fa9459Szrj@deftypefn Extension {simple_object_attributes *} simple_object_fetch_attributes @
82*a9fa9459Szrj  (simple_object_read *@var{simple_object}, const char **@var{errmsg}, int *@var{err})
83*a9fa9459Szrj
84*a9fa9459SzrjFetch the attributes of @var{simple_object}.  The attributes are
85*a9fa9459Szrjinternal information such as the format of the object file, or the
86*a9fa9459Szrjarchitecture it was compiled for.  This information will persist until
87*a9fa9459Szrj@code{simple_object_attributes_release} is called, even if
88*a9fa9459Szrj@var{simple_object} itself is released.
89*a9fa9459Szrj
90*a9fa9459SzrjOn error this returns @code{NULL}, sets @code{*@var{errmsg}} to an
91*a9fa9459Szrjerror message, and sets @code{*@var{err}} to an errno value or
92*a9fa9459Szrj@code{0} if there is no relevant errno.
93*a9fa9459Szrj
94*a9fa9459Szrj@end deftypefn
95*a9fa9459Szrj
96*a9fa9459Szrj@deftypefn Extension {const char *} simple_object_attributes_compare @
97*a9fa9459Szrj  (simple_object_attributes *@var{attrs1}, simple_object_attributes *@var{attrs2}, @
98*a9fa9459Szrj   int *@var{err})
99*a9fa9459Szrj
100*a9fa9459SzrjCompare @var{attrs1} and @var{attrs2}.  If they could be linked
101*a9fa9459Szrjtogether without error, return @code{NULL}.  Otherwise, return an
102*a9fa9459Szrjerror message and set @code{*@var{err}} to an errno value or @code{0}
103*a9fa9459Szrjif there is no relevant errno.
104*a9fa9459Szrj
105*a9fa9459Szrj@end deftypefn
106*a9fa9459Szrj
107*a9fa9459Szrj@deftypefn Extension {void} simple_object_release_attributes @
108*a9fa9459Szrj  (simple_object_attributes *@var{attrs})
109*a9fa9459Szrj
110*a9fa9459SzrjRelease all resources associated with @var{attrs}.
111*a9fa9459Szrj
112*a9fa9459Szrj@end deftypefn
113*a9fa9459Szrj
114*a9fa9459Szrj@deftypefn Extension {simple_object_write *} simple_object_start_write @
115*a9fa9459Szrj  (simple_object_attributes @var{attrs}, const char *@var{segment_name}, @
116*a9fa9459Szrj  const char **@var{errmsg}, int *@var{err})
117*a9fa9459Szrj
118*a9fa9459SzrjStart creating a new object file using the object file format
119*a9fa9459Szrjdescribed in @var{attrs}.  You must fetch attribute information from
120*a9fa9459Szrjan existing object file before you can create a new one.  There is
121*a9fa9459Szrjcurrently no support for creating an object file de novo.
122*a9fa9459Szrj
123*a9fa9459Szrj@var{segment_name} is only used with Mach-O as found on Darwin aka Mac
124*a9fa9459SzrjOS X.  The parameter is required on that target.  It means that all
125*a9fa9459Szrjsections are created within the named segment.  It is ignored for
126*a9fa9459Szrjother object file formats.
127*a9fa9459Szrj
128*a9fa9459SzrjOn error @code{simple_object_start_write} returns @code{NULL}, sets
129*a9fa9459Szrj@code{*@var{ERRMSG}} to an error message, and sets @code{*@var{err}}
130*a9fa9459Szrjto an errno value or @code{0} if there is no relevant errno.
131*a9fa9459Szrj
132*a9fa9459Szrj@end deftypefn
133*a9fa9459Szrj
134*a9fa9459Szrj@deftypefn Extension {simple_object_write_section *} simple_object_write_create_section @
135*a9fa9459Szrj  (simple_object_write *@var{simple_object}, const char *@var{name}, @
136*a9fa9459Szrj  unsigned int @var{align}, const char **@var{errmsg}, int *@var{err})
137*a9fa9459Szrj
138*a9fa9459SzrjAdd a section to @var{simple_object}.  @var{name} is the name of the
139*a9fa9459Szrjnew section.  @var{align} is the required alignment expressed as the
140*a9fa9459Szrjnumber of required low-order 0 bits (e.g., 2 for alignment to a 32-bit
141*a9fa9459Szrjboundary).
142*a9fa9459Szrj
143*a9fa9459SzrjThe section is created as containing data, readable, not writable, not
144*a9fa9459Szrjexecutable, not loaded at runtime.  The section is not written to the
145*a9fa9459Szrjfile until @code{simple_object_write_to_file} is called.
146*a9fa9459Szrj
147*a9fa9459SzrjOn error this returns @code{NULL}, sets @code{*@var{errmsg}} to an
148*a9fa9459Szrjerror message, and sets @code{*@var{err}} to an errno value or
149*a9fa9459Szrj@code{0} if there is no relevant errno.
150*a9fa9459Szrj
151*a9fa9459Szrj@end deftypefn
152*a9fa9459Szrj
153*a9fa9459Szrj@deftypefn Extension {const char *} simple_object_write_add_data @
154*a9fa9459Szrj  (simple_object_write *@var{simple_object}, @
155*a9fa9459Szrj  simple_object_write_section *@var{section}, const void *@var{buffer}, @
156*a9fa9459Szrj  size_t @var{size}, int @var{copy}, int *@var{err})
157*a9fa9459Szrj
158*a9fa9459SzrjAdd data @var{buffer}/@var{size} to @var{section} in
159*a9fa9459Szrj@var{simple_object}.  If @var{copy} is non-zero, the data will be
160*a9fa9459Szrjcopied into memory if necessary.  If @var{copy} is zero, @var{buffer}
161*a9fa9459Szrjmust persist until @code{simple_object_write_to_file} is called.  is
162*a9fa9459Szrjreleased.
163*a9fa9459Szrj
164*a9fa9459SzrjOn success this returns @code{NULL}.  On error this returns an error
165*a9fa9459Szrjmessage, and sets @code{*@var{err}} to an errno value or 0 if there is
166*a9fa9459Szrjno relevant erro.
167*a9fa9459Szrj
168*a9fa9459Szrj@end deftypefn
169*a9fa9459Szrj
170*a9fa9459Szrj@deftypefn Extension {const char *} simple_object_write_to_file @
171*a9fa9459Szrj  (simple_object_write *@var{simple_object}, int @var{descriptor}, int *@var{err})
172*a9fa9459Szrj
173*a9fa9459SzrjWrite the complete object file to @var{descriptor}, an open file
174*a9fa9459Szrjdescriptor.  This writes out all the data accumulated by calls to
175*a9fa9459Szrj@code{simple_object_write_create_section} and
176*a9fa9459Szrj@var{simple_object_write_add_data}.
177*a9fa9459Szrj
178*a9fa9459SzrjThis returns @code{NULL} on success.  On error this returns an error
179*a9fa9459Szrjmessage and sets @code{*@var{err}} to an errno value or @code{0} if
180*a9fa9459Szrjthere is no relevant errno.
181*a9fa9459Szrj
182*a9fa9459Szrj@end deftypefn
183*a9fa9459Szrj
184*a9fa9459Szrj@deftypefn Extension {void} simple_object_release_write @
185*a9fa9459Szrj  (simple_object_write *@var{simple_object})
186*a9fa9459Szrj
187*a9fa9459SzrjRelease all resources associated with @var{simple_object}.
188*a9fa9459Szrj
189*a9fa9459Szrj@end deftypefn
190