REDO_PREBINDING(3)
β¨ REDO_PREBINDING(3) β¨ β the redo_prebinding library functions, bestie
okay so this is page 3 of the library functions manual, and it's literally the whole redo_prebinding function family. buckle up, we're going in π
πΈ NAME πΈ
redo_prebinding library functions β yes that's the whole name, she's mysterious like that π
π¦ SYNOPSIS π¦
first things first, you gotta include the header:
#include <mach-o/redo_prebinding.h>
and then these icons show up:
extern char ** dependent_libs(
const char *file_name,
const char *program_name,
char **error_message);
extern char * install_name(
const char *file_name,
const char *program_name,
char **error_message);
extern enum redo_prebinding_retval redo_prebinding(
const char *file_name,
const char *executable_path,
const char *root_dir,
const char *output_file,
const char *program_name,
char **error_message,
unsigned long slide_to_address,
int only_if_needed,
int zero_out_prebind_checksum,
cpu_type_t allow_missing_architectures,
unsigned long *throttle);
extern enum needs_redo_prebinding_retval needs_redo_prebinding(
const char *file_name,
const char *executable_path,
const char *root_dir,
const char *program_name,
char **error_message,
unsigned long expected_address,
cpu_type_t allow_missing_architectures);
extern enum redo_prebinding_retval unprebind(
const char *file_name,
const char *output_file,
const char *program_name,
char **error_message,
int zero_checksum);
extern enum object_file_type_retval object_file_type(
const char *file_name,
const char *program_name,
char **error_message);
extern int get_prebind_cksums(
const char *file_name,
struct prebind_cksum_arch **cksums,
unsigned long *ncksums,
const char *program_name,
char **error_message);
π DESCRIPTION π
so these functions? they're intended for use by update_prebinding(1) and Mac OS X Build and Integration tools. that's their whole ~thing~, main character energy only π«Ά
the ground rules (apply to literally all of them)
For every single one of these functions, the params program_name and error_message work exactly the same way, no cap:
- For unrecoverable resource errors β like being unable to allocate memory β each function prints a message to
stderrpreceded withprogram_name, then callsexit(2)with the valueEXIT_FAILURE. yeah. it just dips π - If a function is unsuccessful, and if the
error_messagepassed to it is notNULL, it gets set to amalloc(3)'ed buffer holding aNULL-terminated string with the error message. so basically you get receipts π - For all functions, when they return they release all resources β memory, open file descriptors, etc. clean girl aesthetic, we love to see it β¨
the file_name tea β
The file_name parameter for these functions may be of the form foo(bar) β which is NOT interpreted as an archive name and a member name in that archive. Read that again, bestie, because these functions deal with prebinding, and prebound binaries ready for execution can't be in archives. it's giving "physically impossible", periodt π«
executable_path and root_dir π§
- If the
executable_pathparameter is notNULLit's used for any dependent library that has a path that starts with@executable_path. Then@executable_pathis replaced withexecutable_path. swaperoo π« - If the
root_dirparameter is notNULLit's prepended to all the rooted dependent library paths.
π dependent_libs()
takes a file_name of a binary and returns a malloc(3)'ed array of pointers (NULL terminated) to names β also malloc(3)'ed and '\0' terminated names β of all the dependent libraries for that binary (not recursive!) for all of the architectures of that binary. yes queen, all of them π
- If successful,
dependent_libs()returns a non-NULLvalue (at minimum a pointer to oneNULLpointer). - If unsuccessful,
dependent_libs()returnsNULL. sad girl hours π
π install_name()
takes a file_name of a binary and returns a malloc(3)'ed pointer to a NULL-terminated string containing the install_name value for the binary. If unsuccessful, install_name() returns NULL.
and here's the fine print, because of course there is:
- In particular,
NULLis returned if the binary is not a dylib and there is noerror_messageset. - If all of the arch's are dylibs but all the install names don't match,
NULLis returned and anerror_messageis set. - If some but not all of the archs are dylibs,
NULLis returned and anerror_messageis set.
it's giving strict parents, honestly π
π₯ redo_prebinding()
the titular icon herself π takes a file_name of a binary and redoes the prebinding on it.
- If
output_fileis notNULLthe update file is written tooutput_file; if not, it's written tofile_name. - If
redo_prebinding()is successful it returnsREDO_PREBINDING_SUCCESS, otherwise it returnsREDO_PREBINDING_FAILURE. - If the
slide_to_addressparameter is non-zero and the binary is a dynamic library, it's relocated to have that has its prefered address. (yes, that sentence is exactly as chaotic as the original, I'm not fixing her π) - If the parameter
allow_missing_architecturesis zero and not all architectures can be updated, it's not successful and nothing is done, and this returnsREDO_PREBINDING_FAILURE. zero. zip. nada. - If the parameter
allow_missing_architecturesis non-zero then only problems with missing architectures for the architecure of the cputype specified byallow_missing_architectureswill cause this call to fail. Other architectures that could not be prebound due to missing architectures in depending libraries will not have their prebinding updated but will not cause the call to fail. forgiving queen πΈ - If the parameter
only_if_neededis non-zero the prebinding is checked first and only done if needed. The checking includes checking the prefered address against theslide_to_addressvalue if it's non-zero. and then:- If
only_if_neededis non-zero and the prebinding does not have to be redone,REDO_PREBINDING_NOT_NEEDEDis returned. - If the binary is not prebound,
REDO_PREBINDING_NOT_PREBOUNDis returned. - If the new load commands do not fit in the binary and it needs to be rebuilt,
REDO_PREBINDING_NEEDS_REBUILDINGis returned.
- If
- If
zero_out_prebind_checksumis non-zero then thecksumfield of theLC_PREBIND_CKSUMload command (if any) is set to zero on output. and listen β this should always be set by B&I tools and never set by theupdate_prebinding(1)command. write that down π - If
throttleis non-NULLit points to a value of the maximum bytes per second to use for writting the output. If the value isULONG_MAXthen the actual bytes per second is returned indirectly through*throttle. speed demon energy ποΈ
π unprebind()
takes a file_name of a binary and resets or removes prebinding information from it.
- If
output_fileis notNULLthe updated file is written tooutput_file; if not, it's written tofile_name. - If
unprebind()is successful it returnsREDO_PREBINDING_SUCCESS, otherwise it returnsREDO_PREBINDING_FAILURE. - If the binary is already unprebound (it has the
MH_PREBINDABLEflag set) thenREDO_PREBINDING_NOT_NEEDEDis returned. - If
zero_out_prebind_checksumis non-zero then thecksumfield of theLC_PREBIND_CKSUMload command (if any) is set to zero on output, otherwise it's left alone. (for the purpose of patching, this parameter should be non-zero, such that for binaries which are the same β minus prebinding β the unprebinding process produces binaries that are identical. cute, matching outfits π)
now the actual glow-down she performs. Unprebinding:
- slides dynamic libraries to address zero
- resets prebound symbols to address zero and type undefined
- resets symbol pointers
- removes
LC_PREBOUND_DYLIBcommands - resets library timestamps
- resets two-level hints
- updates relocation entries if necessary
Unprebound binaries have the MH_PREBINDABLE flag set, but not MH_PREBOUND. It will also set the the MH_ALLMODSBOUND flag if all two-level libraries were used and all modules were found to be bound in the LC_PREBOUND_DYLIB commands. (and yes, "the the" is in the original, I'm preserving her legacy π
)
As unprebinding is intended to produce a canonical Mach-O binary, bundles and non-prebound executables and dylibs are acceptable as input. For these files, the unprebind operation will zero library time stamps and version numbers and zero entries in the two-level hints table. These files will not gain the MH_PREBINDABLE flag. All resulting binaries successfully processed by unprebind() will have the MH_CANONICAL flag. iconic behavior only π
β needs_redo_prebinding()
takes a file_name and determines if it's a binary and if its prebinding is uptodate. returns one of the return values below depending on the state of the binary and libraries.
- If the parameter
allow_missing_architecturesis zero then architectures for universal files are checked. - If the parameter
allow_missing_architecturesis non-zero then the value returned is based on the cputype specified byallow_missing_architectures. If that architecture is not present thenPREBINDING_UPTODATEis returned. absence = uptodate, apparently, we love a lenient queen π - If the parameter
expected_addressis not zero and the binary is a dynamic library then the library is checked to see if it's at theexpected_addressβ if not, the prebinding is assumed to be out of date andPREBINDING_OUTOFDATEis returned.
return values for needs_redo_prebinding() π«
PREBINDING_UPTODATEβ a binary who's prebinding is up todate. slay πPREBINDING_OUTOFDATEβ a binary who's prebinding is out of date. she needs a refresh πNOT_PREBOUNDβ a binary, but not built prebound.NOT_PREBINDABLEβ not a binary or statically linked, prebinding does not apply. not her department πPREBINDING_UNKNOWNβ a binary who's prebinding can't be determined because it's malformed, a library it depends on is missing, etc. mysterious and unwell π«
πΈ object_file_type()
takes a file_name and determines what type of object file it is, then returns one of the values below.
OFT_EXECUTABLE, β the file is an Mach-O executable.OFT_DYLIB, β the file is an Mach-O dyanmic library. (her spelling, not mine π)OFT_BUNDLE, β the file is an Mach-O bundle.OFT_ARCHIVE, β the file is an archive.OFT_OTHER, β the file is something other than the above files.OFT_INCONSISTENT, β the file is a universal file and the architectures are not of the same type.OFT_FILE_ERRORβ The file can't be opened, read or malformed.
π§ get_prebind_cksums()
takes a file_name that is a Mach-O file or universal file containing Mach-O files, and returns a malloc(3)'ed array of prebind_cksum_arch structures indirectly through the cksums parameter. The number of prebind_cksum_arch structures is returned indirectly through the ncksums parameter. If successful it returns zero, else it returns non-zero.
The structure prebind_cksum_arch is defined in <mach-o/redo_prebinding.h> as follows:
struct prebind_cksum_arch {
cpu_type_t cputype;
cpu_subtype_t cpusubtype;
unsigned long has_cksum;
unsigned long cksum;
};
and here's what goes in each field, bestie:
cputypeandcpusubtypeare filled in with the cpu specifier and the machine specifier for the architecture of the Mach-O file (or zero if not a Mach-O file).- The field
has_cksumis set to one if the architecture as anLC_PREBIND_CKSUMload command and zero otherwise. - The field
cksumis set to the value of thecksuminLC_PREBIND_CKSUMload command (or zero if it does not have one).
π SEE ALSO π
go read these next, iykyk:
redo_prebinding(1)update_prebinding(1)
π and that's the page!! written by Apple Computer, Inc., dated July 28, 2005, and yes this is REDO_PREBINDING(3) from the Library Functions Manual. mwah, go prebind something π
β¨
π¦ where this page comes from
- nixpkgs unstable: cctools 1010.6
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms