1*98b9484cSchristos@c -*- mode: texinfo -*- 2*98b9484cSchristos@deftypefn Extension {simple_object_read *} simple_object_open_read @ 3*98b9484cSchristos (int @var{descriptor}, off_t @var{offset}, const char *{segment_name}, @ 4*98b9484cSchristos const char **@var{errmsg}, int *@var{err}) 5*98b9484cSchristos 6*98b9484cSchristosOpens an object file for reading. Creates and returns an 7*98b9484cSchristos@code{simple_object_read} pointer which may be passed to other 8*98b9484cSchristosfunctions to extract data from the object file. 9*98b9484cSchristos 10*98b9484cSchristos@var{descriptor} holds a file descriptor which permits reading. 11*98b9484cSchristos 12*98b9484cSchristos@var{offset} is the offset into the file; this will be @code{0} in the 13*98b9484cSchristosnormal case, but may be a different value when reading an object file 14*98b9484cSchristosin an archive file. 15*98b9484cSchristos 16*98b9484cSchristos@var{segment_name} is only used with the Mach-O file format used on 17*98b9484cSchristosDarwin aka Mac OS X. It is required on that platform, and means to 18*98b9484cSchristosonly look at sections within the segment with that name. The 19*98b9484cSchristosparameter is ignored on other systems. 20*98b9484cSchristos 21*98b9484cSchristosIf an error occurs, this functions returns @code{NULL} and sets 22*98b9484cSchristos@code{*@var{errmsg}} to an error string and sets @code{*@var{err}} to 23*98b9484cSchristosan errno value or @code{0} if there is no relevant errno. 24*98b9484cSchristos 25*98b9484cSchristos@end deftypefn 26*98b9484cSchristos 27*98b9484cSchristos@deftypefn Extension {const char *} simple_object_find_sections @ 28*98b9484cSchristos (simple_object_read *@var{simple_object}, int (*@var{pfn}) (void *@var{data}, @ 29*98b9484cSchristos const char *@var{name}, off_t @var{offset}, off_t @var{length}), @ 30*98b9484cSchristos void *@var{data}, int *@var{err}) 31*98b9484cSchristos 32*98b9484cSchristosThis function calls @var{pfn} for each section in @var{simple_object}. 33*98b9484cSchristosIt calls @var{pfn} with the section name, the offset within the file 34*98b9484cSchristosof the section contents, and the length of the section contents. The 35*98b9484cSchristosoffset within the file is relative to the offset passed to 36*98b9484cSchristos@code{simple_object_open_read}. The @var{data} argument to this 37*98b9484cSchristosfunction is passed along to @var{pfn}. 38*98b9484cSchristos 39*98b9484cSchristosIf @var{pfn} returns @code{0}, the loop over the sections stops and 40*98b9484cSchristos@code{simple_object_find_sections} returns. If @var{pfn} returns some 41*98b9484cSchristosother value, the loop continues. 42*98b9484cSchristos 43*98b9484cSchristosOn success @code{simple_object_find_sections} returns. On error it 44*98b9484cSchristosreturns an error string, and sets @code{*@var{err}} to an errno value 45*98b9484cSchristosor @code{0} if there is no relevant errno. 46*98b9484cSchristos 47*98b9484cSchristos@end deftypefn 48*98b9484cSchristos 49*98b9484cSchristos@deftypefn Extension {int} simple_object_find_section @ 50*98b9484cSchristos (simple_object_read *@var{simple_object} off_t *@var{offset}, @ 51*98b9484cSchristos off_t *@var{length}, const char **@var{errmsg}, int *@var{err}) 52*98b9484cSchristos 53*98b9484cSchristosLook for the section @var{name} in @var{simple_object}. This returns 54*98b9484cSchristosinformation for the first section with that name. 55*98b9484cSchristos 56*98b9484cSchristosIf found, return 1 and set @code{*@var{offset}} to the offset in the 57*98b9484cSchristosfile of the section contents and set @code{*@var{length}} to the 58*98b9484cSchristoslength of the section contents. The value in @code{*@var{offset}} 59*98b9484cSchristoswill be relative to the offset passed to 60*98b9484cSchristos@code{simple_object_open_read}. 61*98b9484cSchristos 62*98b9484cSchristosIf the section is not found, and no error occurs, 63*98b9484cSchristos@code{simple_object_find_section} returns @code{0} and set 64*98b9484cSchristos@code{*@var{errmsg}} to @code{NULL}. 65*98b9484cSchristos 66*98b9484cSchristosIf an error occurs, @code{simple_object_find_section} returns 67*98b9484cSchristos@code{0}, sets @code{*@var{errmsg}} to an error message, and sets 68*98b9484cSchristos@code{*@var{err}} to an errno value or @code{0} if there is no 69*98b9484cSchristosrelevant errno. 70*98b9484cSchristos 71*98b9484cSchristos@end deftypefn 72*98b9484cSchristos 73*98b9484cSchristos@deftypefn Extension {void} simple_object_release_read @ 74*98b9484cSchristos (simple_object_read *@var{simple_object}) 75*98b9484cSchristos 76*98b9484cSchristosRelease all resources associated with @var{simple_object}. This does 77*98b9484cSchristosnot close the file descriptor. 78*98b9484cSchristos 79*98b9484cSchristos@end deftypefn 80*98b9484cSchristos 81*98b9484cSchristos@deftypefn Extension {simple_object_attributes *} simple_object_fetch_attributes @ 82*98b9484cSchristos (simple_object_read *@var{simple_object}, const char **@var{errmsg}, int *@var{err}) 83*98b9484cSchristos 84*98b9484cSchristosFetch the attributes of @var{simple_object}. The attributes are 85*98b9484cSchristosinternal information such as the format of the object file, or the 86*98b9484cSchristosarchitecture it was compiled for. This information will persist until 87*98b9484cSchristos@code{simple_object_attributes_release} is called, even if 88*98b9484cSchristos@var{simple_object} itself is released. 89*98b9484cSchristos 90*98b9484cSchristosOn error this returns @code{NULL}, sets @code{*@var{errmsg}} to an 91*98b9484cSchristoserror message, and sets @code{*@var{err}} to an errno value or 92*98b9484cSchristos@code{0} if there is no relevant errno. 93*98b9484cSchristos 94*98b9484cSchristos@end deftypefn 95*98b9484cSchristos 96*98b9484cSchristos@deftypefn Extension {const char *} simple_object_attributes_compare @ 97*98b9484cSchristos (simple_object_attributes *@var{attrs1}, simple_object_attributes *@var{attrs2}, @ 98*98b9484cSchristos int *@var{err}) 99*98b9484cSchristos 100*98b9484cSchristosCompare @var{attrs1} and @var{attrs2}. If they could be linked 101*98b9484cSchristostogether without error, return @code{NULL}. Otherwise, return an 102*98b9484cSchristoserror message and set @code{*@var{err}} to an errno value or @code{0} 103*98b9484cSchristosif there is no relevant errno. 104*98b9484cSchristos 105*98b9484cSchristos@end deftypefn 106*98b9484cSchristos 107*98b9484cSchristos@deftypefn Extension {void} simple_object_release_attributes @ 108*98b9484cSchristos (simple_object_attributes *@var{attrs}) 109*98b9484cSchristos 110*98b9484cSchristosRelease all resources associated with @var{attrs}. 111*98b9484cSchristos 112*98b9484cSchristos@end deftypefn 113*98b9484cSchristos 114*98b9484cSchristos@deftypefn Extension {simple_object_write *} simple_object_start_write @ 115*98b9484cSchristos (simple_object_attributes @var{attrs}, const char *@var{segment_name}, @ 116*98b9484cSchristos const char **@var{errmsg}, int *@var{err}) 117*98b9484cSchristos 118*98b9484cSchristosStart creating a new object file using the object file format 119*98b9484cSchristosdescribed in @var{attrs}. You must fetch attribute information from 120*98b9484cSchristosan existing object file before you can create a new one. There is 121*98b9484cSchristoscurrently no support for creating an object file de novo. 122*98b9484cSchristos 123*98b9484cSchristos@var{segment_name} is only used with Mach-O as found on Darwin aka Mac 124*98b9484cSchristosOS X. The parameter is required on that target. It means that all 125*98b9484cSchristossections are created within the named segment. It is ignored for 126*98b9484cSchristosother object file formats. 127*98b9484cSchristos 128*98b9484cSchristosOn error @code{simple_object_start_write} returns @code{NULL}, sets 129*98b9484cSchristos@code{*@var{ERRMSG}} to an error message, and sets @code{*@var{err}} 130*98b9484cSchristosto an errno value or @code{0} if there is no relevant errno. 131*98b9484cSchristos 132*98b9484cSchristos@end deftypefn 133*98b9484cSchristos 134*98b9484cSchristos@deftypefn Extension {simple_object_write_section *} simple_object_write_create_section @ 135*98b9484cSchristos (simple_object_write *@var{simple_object}, const char *@var{name}, @ 136*98b9484cSchristos unsigned int @var{align}, const char **@var{errmsg}, int *@var{err}) 137*98b9484cSchristos 138*98b9484cSchristosAdd a section to @var{simple_object}. @var{name} is the name of the 139*98b9484cSchristosnew section. @var{align} is the required alignment expressed as the 140*98b9484cSchristosnumber of required low-order 0 bits (e.g., 2 for alignment to a 32-bit 141*98b9484cSchristosboundary). 142*98b9484cSchristos 143*98b9484cSchristosThe section is created as containing data, readable, not writable, not 144*98b9484cSchristosexecutable, not loaded at runtime. The section is not written to the 145*98b9484cSchristosfile until @code{simple_object_write_to_file} is called. 146*98b9484cSchristos 147*98b9484cSchristosOn error this returns @code{NULL}, sets @code{*@var{errmsg}} to an 148*98b9484cSchristoserror message, and sets @code{*@var{err}} to an errno value or 149*98b9484cSchristos@code{0} if there is no relevant errno. 150*98b9484cSchristos 151*98b9484cSchristos@end deftypefn 152*98b9484cSchristos 153*98b9484cSchristos@deftypefn Extension {const char *} simple_object_write_add_data @ 154*98b9484cSchristos (simple_object_write *@var{simple_object}, @ 155*98b9484cSchristos simple_object_write_section *@var{section}, const void *@var{buffer}, @ 156*98b9484cSchristos size_t @var{size}, int @var{copy}, int *@var{err}) 157*98b9484cSchristos 158*98b9484cSchristosAdd data @var{buffer}/@var{size} to @var{section} in 159*98b9484cSchristos@var{simple_object}. If @var{copy} is non-zero, the data will be 160*98b9484cSchristoscopied into memory if necessary. If @var{copy} is zero, @var{buffer} 161*98b9484cSchristosmust persist until @code{simple_object_write_to_file} is called. is 162*98b9484cSchristosreleased. 163*98b9484cSchristos 164*98b9484cSchristosOn success this returns @code{NULL}. On error this returns an error 165*98b9484cSchristosmessage, and sets @code{*@var{err}} to an errno value or 0 if there is 166*98b9484cSchristosno relevant erro. 167*98b9484cSchristos 168*98b9484cSchristos@end deftypefn 169*98b9484cSchristos 170*98b9484cSchristos@deftypefn Extension {const char *} simple_object_write_to_file @ 171*98b9484cSchristos (simple_object_write *@var{simple_object}, int @var{descriptor}, int *@var{err}) 172*98b9484cSchristos 173*98b9484cSchristosWrite the complete object file to @var{descriptor}, an open file 174*98b9484cSchristosdescriptor. This writes out all the data accumulated by calls to 175*98b9484cSchristos@code{simple_object_write_create_section} and 176*98b9484cSchristos@var{simple_object_write_add_data}. 177*98b9484cSchristos 178*98b9484cSchristosThis returns @code{NULL} on success. On error this returns an error 179*98b9484cSchristosmessage and sets @code{*@var{err}} to an errno value or @code{0} if 180*98b9484cSchristosthere is no relevant errno. 181*98b9484cSchristos 182*98b9484cSchristos@end deftypefn 183*98b9484cSchristos 184*98b9484cSchristos@deftypefn Extension {void} simple_object_release_write @ 185*98b9484cSchristos (simple_object_write *@var{simple_object}) 186*98b9484cSchristos 187*98b9484cSchristosRelease all resources associated with @var{simple_object}. 188*98b9484cSchristos 189*98b9484cSchristos@end deftypefn 190