END(3) — UNIX Programmer’s Manual
NAME
_mh_execute_header, _end, _etext, _edata, _shared_library_initialization − link editor defined symbols
SYNOPSIS
#include <sys/loader.h>
#include <ldsyms.h>
extern const struct mach_header ∗_mh_execute_header;
extern /∗ void ∗/ _end;
extern /∗ void ∗/ _etext;
extern /∗ void ∗/ _edata;
extern int _shared_library_initialization[];
DESCRIPTION
These are the names of symbols defined by the link editor. The semantics of link editor symbols is that they are defined by the link editor only if referenced, and it is an error for the user to define them (see ld(1)). In some cases only the value of the symbol is interesting and there is no interesting contents of these symbols.
The link editor defined symbol _mh_execute_header is the address of the Mach header in a Mach-O (Mach object) executable file type (MH_EXECUTE). It does not appear in any other Mach-O file type. It should be used to get to the addresses and sizes of all the segments and sections in the executable and any shared libraries it uses. This can be done by parsing the headers and load commands.
The link editor defined symbols _etext, _edata and _end are hold overs from traditional UNIX a.out files. They are defined in a Mach-O file as follows: _etext is the first address after the last non-zero fill section in the the __TEXT segment. _edata is the first address after the last non-zero fill section in the __DATA segment. And _end is the first address after the last section in the __DATA segment.
When execution begins, the program break coincides with _end but it is reset by the routines brk(2), malloc(3), standard input/output (stdio(3S)), the profile (−p) option of cc(1), etc. The current value of the program break is reliably returned by ‘sbrk(0)’, see brk(2).
For MN_PRELOAD file types there are symbols for the beginning and ending of each segment and each section in each segment in a Mach-O object file. These names are provided for use in a Mach-O preloaded file that does not have its headers loaded as part of the first segment. The names for the symbols for a segment’s beginning and end will have the form: _SEGNAME__begin and _SEGNAME__end where __SEGNAME is the name of the segment. The names for the symbols for a section’s beginning and end will have the form: _SEGNAME__sectname__begin and _SEGNAME__sectname__end where __sectname is the name of the section and __SEGNAME is the segment it is in.
The above symbols’ types are those of the section they are referring to. This is true even for symbols whose values are ends of a section and that value is next address after that section and not really in that section. This results in these symbols having types referring to sections whose values are not in that section.
Both these beginning and ending symbols and the traditional UNIX link editor symbols are not part of shared libraries but rather the executable that uses them and thus are not defined in a shared library.
The link editor defined symbol _shared_library_initialization is the shared library initialization table. It is a pointer to an array of pointers that point at arrays of shared library initialization structures (zero terminated).
The prefix to the symbol names of the arrays of shared library initialization structures is .shared_library_initialization_. The base name of the object file is the rest of the name. Each of these arrays’ last structure must have zeros in all its fields. The link editor looks for these symbol names if the link editor symbol _shared_library_initialization is referenced and builds that table.
SEE ALSO
BUGS
For a Mach-O executable file, the one and only link editor symbol should be _mh_execute_header.
7th Edition — June 20, 1989