PTR_MANGLE
is an internal feature in glibc, built on macros. It's not automated by the compiler in any way. You could duplicate the same thing in your applications, but you'd also have to do it manually; it works something like:
uintptr_t xor_key; // needs to be initialized with random "key" before use
#define PTR_MANGLE(p) (1 ? (void *)((uintptr_t)(p) ^ xor_key) : p)
This may be completely different from the glibc implementation; I haven't looked at it in a long time and just wrote this off the top of my head. The seemingly useless use of the conditional operator is to force the resulting expression to have the same type as the original pointer so it can be used directly.
Note that the operation is its own inverse, so PTR_MANGLE
can be used for both "encryption" and "decryption".