GET_END(3)

πŸ“¦ version 1010.6, in nixpkgs unstable

πŸ’… GET_END(3) πŸ’…

okay bestie, welcome to GET_END(3) from the Library Functions Manual β€” yes, that manual name is folded in right here at the top, and the whole page is about getting the values of UNIX link editor defined symbols. the tea is: you probably shouldn't use these, but let's read the receipts anyway 🫢✨

🌸 NAME 🌸

get_end, get_etext, get_edata β€” get values of UNIX link editor defined symbols.

✨ SYNOPSIS ✨

#include <mach-o/getsect.h>

unsigned long get_end();
unsigned long get_etext();
unsigned long get_edata();

πŸ’– DESCRIPTION πŸ’–

okay so these routines are a stopgap measure for programs that use the UNIX link-editor defined symbols. and the manual is not subtle about it: use of these routines is very strongly discouraged. like, highkey do not.

🚨 bestie, this is a "use at your own risk" situation. the exact energy is: very strongly discouraged.

the problem is that any program using UNIX link editor defined symbols (_end, _etext or _edata) is making assumptions that the program has the memory layout of a UNIX program. and that? that assumption is incorrect for a program built by the Mach-O link editor. πŸ’€

so why do these routines exist at all? the reason given is that if very minimal assumptions about the layout are used, and the default format and memory layout of the Mach-O link editor is used to build the program, some things may work by using the values returned by these routines in place of the addresses of their UNIX link-editor defined symbols. translation: it's a little stopgap, not a whole lifestyle. ngl, use at your own risk, and only if you know what your doing. (the page says "your", not "you're" β€” we're not fixing it, it's part of the lore πŸ™ˆ.)

or better yet: convert the program to use the appropriate Mach or Mach-O functions. if you are trying to allocate memory use vm_allocate(2), if you are trying to find out about your address space use vm_region(2), and if you are trying to find out where your program is loaded use the dyld(3) functions. those are the actual main character recommendations πŸ’…

the values of the UNIX link-editor defined symbols _etext, _edata and _end are returned by the routines get_etext, get_edata, and get_end respectively. in a Mach-O file they have the following values:

  • get_etext β€” returns the first address after the (__TEXT,__text) section. note this my or may not be the only section in the __TEXT segment. (yes, "my" is in the original; it's iconic. 😭)
  • get_edata β€” returns the first address after the (__DATA,__data) section. note this my or may not be the last non-zero fill section in the __DATA segment.
  • get_end β€” returns the first address after the last segment in the executable. note a shared library may be loaded at this address.

πŸ‘€ SEE ALSO πŸ‘€

go peek at ld(1) and dyld(3), bestie. that's the whole guest list.


mwah πŸ’‹ this page was brought to you by Apple Computer, Inc., dated April 10, 1998, and it's GET_END(3) all the way down. that's the source/version and date, periodt. πŸŽ€βœ¨

πŸ“¦ where this page comes from