186d7f5d3SJohn Marino@c -*- mode: texinfo -*- 286d7f5d3SJohn Marino@deftypefn Extension {simple_object_read *} simple_object_open_read @ 386d7f5d3SJohn Marino (int @var{descriptor}, off_t @var{offset}, const char *{segment_name}, @ 486d7f5d3SJohn Marino const char **@var{errmsg}, int *@var{err}) 586d7f5d3SJohn Marino 686d7f5d3SJohn MarinoOpens an object file for reading. Creates and returns an 786d7f5d3SJohn Marino@code{simple_object_read} pointer which may be passed to other 886d7f5d3SJohn Marinofunctions to extract data from the object file. 986d7f5d3SJohn Marino 1086d7f5d3SJohn Marino@var{descriptor} holds a file descriptor which permits reading. 1186d7f5d3SJohn Marino 1286d7f5d3SJohn Marino@var{offset} is the offset into the file; this will be @code{0} in the 1386d7f5d3SJohn Marinonormal case, but may be a different value when reading an object file 1486d7f5d3SJohn Marinoin an archive file. 1586d7f5d3SJohn Marino 1686d7f5d3SJohn Marino@var{segment_name} is only used with the Mach-O file format used on 1786d7f5d3SJohn MarinoDarwin aka Mac OS X. It is required on that platform, and means to 1886d7f5d3SJohn Marinoonly look at sections within the segment with that name. The 1986d7f5d3SJohn Marinoparameter is ignored on other systems. 2086d7f5d3SJohn Marino 2186d7f5d3SJohn MarinoIf an error occurs, this functions returns @code{NULL} and sets 2286d7f5d3SJohn Marino@code{*@var{errmsg}} to an error string and sets @code{*@var{err}} to 2386d7f5d3SJohn Marinoan errno value or @code{0} if there is no relevant errno. 2486d7f5d3SJohn Marino 2586d7f5d3SJohn Marino@end deftypefn 2686d7f5d3SJohn Marino 2786d7f5d3SJohn Marino@deftypefn Extension {const char *} simple_object_find_sections @ 2886d7f5d3SJohn Marino (simple_object_read *@var{simple_object}, int (*@var{pfn}) (void *@var{data}, @ 2986d7f5d3SJohn Marino const char *@var{name}, off_t @var{offset}, off_t @var{length}), @ 3086d7f5d3SJohn Marino void *@var{data}, int *@var{err}) 3186d7f5d3SJohn Marino 3286d7f5d3SJohn MarinoThis function calls @var{pfn} for each section in @var{simple_object}. 3386d7f5d3SJohn MarinoIt calls @var{pfn} with the section name, the offset within the file 3486d7f5d3SJohn Marinoof the section contents, and the length of the section contents. The 3586d7f5d3SJohn Marinooffset within the file is relative to the offset passed to 3686d7f5d3SJohn Marino@code{simple_object_open_read}. The @var{data} argument to this 3786d7f5d3SJohn Marinofunction is passed along to @var{pfn}. 3886d7f5d3SJohn Marino 3986d7f5d3SJohn MarinoIf @var{pfn} returns @code{0}, the loop over the sections stops and 4086d7f5d3SJohn Marino@code{simple_object_find_sections} returns. If @var{pfn} returns some 4186d7f5d3SJohn Marinoother value, the loop continues. 4286d7f5d3SJohn Marino 4386d7f5d3SJohn MarinoOn success @code{simple_object_find_sections} returns. On error it 4486d7f5d3SJohn Marinoreturns an error string, and sets @code{*@var{err}} to an errno value 4586d7f5d3SJohn Marinoor @code{0} if there is no relevant errno. 4686d7f5d3SJohn Marino 4786d7f5d3SJohn Marino@end deftypefn 4886d7f5d3SJohn Marino 4986d7f5d3SJohn Marino@deftypefn Extension {int} simple_object_find_section @ 5086d7f5d3SJohn Marino (simple_object_read *@var{simple_object} off_t *@var{offset}, @ 5186d7f5d3SJohn Marino off_t *@var{length}, const char **@var{errmsg}, int *@var{err}) 5286d7f5d3SJohn Marino 5386d7f5d3SJohn MarinoLook for the section @var{name} in @var{simple_object}. This returns 5486d7f5d3SJohn Marinoinformation for the first section with that name. 5586d7f5d3SJohn Marino 5686d7f5d3SJohn MarinoIf found, return 1 and set @code{*@var{offset}} to the offset in the 5786d7f5d3SJohn Marinofile of the section contents and set @code{*@var{length}} to the 5886d7f5d3SJohn Marinolength of the section contents. The value in @code{*@var{offset}} 5986d7f5d3SJohn Marinowill be relative to the offset passed to 6086d7f5d3SJohn Marino@code{simple_object_open_read}. 6186d7f5d3SJohn Marino 6286d7f5d3SJohn MarinoIf the section is not found, and no error occurs, 6386d7f5d3SJohn Marino@code{simple_object_find_section} returns @code{0} and set 6486d7f5d3SJohn Marino@code{*@var{errmsg}} to @code{NULL}. 6586d7f5d3SJohn Marino 6686d7f5d3SJohn MarinoIf an error occurs, @code{simple_object_find_section} returns 6786d7f5d3SJohn Marino@code{0}, sets @code{*@var{errmsg}} to an error message, and sets 6886d7f5d3SJohn Marino@code{*@var{err}} to an errno value or @code{0} if there is no 6986d7f5d3SJohn Marinorelevant errno. 7086d7f5d3SJohn Marino 7186d7f5d3SJohn Marino@end deftypefn 7286d7f5d3SJohn Marino 7386d7f5d3SJohn Marino@deftypefn Extension {void} simple_object_release_read @ 7486d7f5d3SJohn Marino (simple_object_read *@var{simple_object}) 7586d7f5d3SJohn Marino 7686d7f5d3SJohn MarinoRelease all resources associated with @var{simple_object}. This does 7786d7f5d3SJohn Marinonot close the file descriptor. 7886d7f5d3SJohn Marino 7986d7f5d3SJohn Marino@end deftypefn 8086d7f5d3SJohn Marino 8186d7f5d3SJohn Marino@deftypefn Extension {simple_object_attributes *} simple_object_fetch_attributes @ 8286d7f5d3SJohn Marino (simple_object_read *@var{simple_object}, const char **@var{errmsg}, int *@var{err}) 8386d7f5d3SJohn Marino 8486d7f5d3SJohn MarinoFetch the attributes of @var{simple_object}. The attributes are 8586d7f5d3SJohn Marinointernal information such as the format of the object file, or the 8686d7f5d3SJohn Marinoarchitecture it was compiled for. This information will persist until 8786d7f5d3SJohn Marino@code{simple_object_attributes_release} is called, even if 8886d7f5d3SJohn Marino@var{simple_object} itself is released. 8986d7f5d3SJohn Marino 9086d7f5d3SJohn MarinoOn error this returns @code{NULL}, sets @code{*@var{errmsg}} to an 9186d7f5d3SJohn Marinoerror message, and sets @code{*@var{err}} to an errno value or 9286d7f5d3SJohn Marino@code{0} if there is no relevant errno. 9386d7f5d3SJohn Marino 9486d7f5d3SJohn Marino@end deftypefn 9586d7f5d3SJohn Marino 9686d7f5d3SJohn Marino@deftypefn Extension {const char *} simple_object_attributes_compare @ 9786d7f5d3SJohn Marino (simple_object_attributes *@var{attrs1}, simple_object_attributes *@var{attrs2}, @ 9886d7f5d3SJohn Marino int *@var{err}) 9986d7f5d3SJohn Marino 10086d7f5d3SJohn MarinoCompare @var{attrs1} and @var{attrs2}. If they could be linked 10186d7f5d3SJohn Marinotogether without error, return @code{NULL}. Otherwise, return an 10286d7f5d3SJohn Marinoerror message and set @code{*@var{err}} to an errno value or @code{0} 10386d7f5d3SJohn Marinoif there is no relevant errno. 10486d7f5d3SJohn Marino 10586d7f5d3SJohn Marino@end deftypefn 10686d7f5d3SJohn Marino 10786d7f5d3SJohn Marino@deftypefn Extension {void} simple_object_release_attributes @ 10886d7f5d3SJohn Marino (simple_object_attributes *@var{attrs}) 10986d7f5d3SJohn Marino 11086d7f5d3SJohn MarinoRelease all resources associated with @var{attrs}. 11186d7f5d3SJohn Marino 11286d7f5d3SJohn Marino@end deftypefn 11386d7f5d3SJohn Marino 11486d7f5d3SJohn Marino@deftypefn Extension {simple_object_write *} simple_object_start_write @ 11586d7f5d3SJohn Marino (simple_object_attributes @var{attrs}, const char *@var{segment_name}, @ 11686d7f5d3SJohn Marino const char **@var{errmsg}, int *@var{err}) 11786d7f5d3SJohn Marino 11886d7f5d3SJohn MarinoStart creating a new object file using the object file format 11986d7f5d3SJohn Marinodescribed in @var{attrs}. You must fetch attribute information from 12086d7f5d3SJohn Marinoan existing object file before you can create a new one. There is 12186d7f5d3SJohn Marinocurrently no support for creating an object file de novo. 12286d7f5d3SJohn Marino 12386d7f5d3SJohn Marino@var{segment_name} is only used with Mach-O as found on Darwin aka Mac 12486d7f5d3SJohn MarinoOS X. The parameter is required on that target. It means that all 12586d7f5d3SJohn Marinosections are created within the named segment. It is ignored for 12686d7f5d3SJohn Marinoother object file formats. 12786d7f5d3SJohn Marino 12886d7f5d3SJohn MarinoOn error @code{simple_object_start_write} returns @code{NULL}, sets 12986d7f5d3SJohn Marino@code{*@var{ERRMSG}} to an error message, and sets @code{*@var{err}} 13086d7f5d3SJohn Marinoto an errno value or @code{0} if there is no relevant errno. 13186d7f5d3SJohn Marino 13286d7f5d3SJohn Marino@end deftypefn 13386d7f5d3SJohn Marino 13486d7f5d3SJohn Marino@deftypefn Extension {simple_object_write_section *} simple_object_write_create_section @ 13586d7f5d3SJohn Marino (simple_object_write *@var{simple_object}, const char *@var{name}, @ 13686d7f5d3SJohn Marino unsigned int @var{align}, const char **@var{errmsg}, int *@var{err}) 13786d7f5d3SJohn Marino 13886d7f5d3SJohn MarinoAdd a section to @var{simple_object}. @var{name} is the name of the 13986d7f5d3SJohn Marinonew section. @var{align} is the required alignment expressed as the 14086d7f5d3SJohn Marinonumber of required low-order 0 bits (e.g., 2 for alignment to a 32-bit 14186d7f5d3SJohn Marinoboundary). 14286d7f5d3SJohn Marino 14386d7f5d3SJohn MarinoThe section is created as containing data, readable, not writable, not 14486d7f5d3SJohn Marinoexecutable, not loaded at runtime. The section is not written to the 14586d7f5d3SJohn Marinofile until @code{simple_object_write_to_file} is called. 14686d7f5d3SJohn Marino 14786d7f5d3SJohn MarinoOn error this returns @code{NULL}, sets @code{*@var{errmsg}} to an 14886d7f5d3SJohn Marinoerror message, and sets @code{*@var{err}} to an errno value or 14986d7f5d3SJohn Marino@code{0} if there is no relevant errno. 15086d7f5d3SJohn Marino 15186d7f5d3SJohn Marino@end deftypefn 15286d7f5d3SJohn Marino 15386d7f5d3SJohn Marino@deftypefn Extension {const char *} simple_object_write_add_data @ 15486d7f5d3SJohn Marino (simple_object_write *@var{simple_object}, @ 15586d7f5d3SJohn Marino simple_object_write_section *@var{section}, const void *@var{buffer}, @ 15686d7f5d3SJohn Marino size_t @var{size}, int @var{copy}, int *@var{err}) 15786d7f5d3SJohn Marino 15886d7f5d3SJohn MarinoAdd data @var{buffer}/@var{size} to @var{section} in 15986d7f5d3SJohn Marino@var{simple_object}. If @var{copy} is non-zero, the data will be 16086d7f5d3SJohn Marinocopied into memory if necessary. If @var{copy} is zero, @var{buffer} 16186d7f5d3SJohn Marinomust persist until @code{simple_object_write_to_file} is called. is 16286d7f5d3SJohn Marinoreleased. 16386d7f5d3SJohn Marino 16486d7f5d3SJohn MarinoOn success this returns @code{NULL}. On error this returns an error 16586d7f5d3SJohn Marinomessage, and sets @code{*@var{err}} to an errno value or 0 if there is 16686d7f5d3SJohn Marinono relevant erro. 16786d7f5d3SJohn Marino 16886d7f5d3SJohn Marino@end deftypefn 16986d7f5d3SJohn Marino 17086d7f5d3SJohn Marino@deftypefn Extension {const char *} simple_object_write_to_file @ 17186d7f5d3SJohn Marino (simple_object_write *@var{simple_object}, int @var{descriptor}, int *@var{err}) 17286d7f5d3SJohn Marino 17386d7f5d3SJohn MarinoWrite the complete object file to @var{descriptor}, an open file 17486d7f5d3SJohn Marinodescriptor. This writes out all the data accumulated by calls to 17586d7f5d3SJohn Marino@code{simple_object_write_create_section} and 17686d7f5d3SJohn Marino@var{simple_object_write_add_data}. 17786d7f5d3SJohn Marino 17886d7f5d3SJohn MarinoThis returns @code{NULL} on success. On error this returns an error 17986d7f5d3SJohn Marinomessage and sets @code{*@var{err}} to an errno value or @code{0} if 18086d7f5d3SJohn Marinothere is no relevant errno. 18186d7f5d3SJohn Marino 18286d7f5d3SJohn Marino@end deftypefn 18386d7f5d3SJohn Marino 18486d7f5d3SJohn Marino@deftypefn Extension {void} simple_object_release_write @ 18586d7f5d3SJohn Marino (simple_object_write *@var{simple_object}) 18686d7f5d3SJohn Marino 18786d7f5d3SJohn MarinoRelease all resources associated with @var{simple_object}. 18886d7f5d3SJohn Marino 18986d7f5d3SJohn Marino@end deftypefn 190