Does the setenv()->malloc() call always have to go through the plt and got?
It doesn't have to, but many libc implementations allow end user to substitute his/her own malloc
implementation (e.g. TCMalloc or jemalloc), and calling malloc
from setenv
directly would severely limit this.
Wouldn't RIP relative addressing work better
You need to be careful with with what "work better" actually means, and along which axis you evaluate it.
IP-relative call (i.e. direct call) would be faster and more efficient, but it will not work at all for symbol interpositioning.
P.S. At least GLIBC has no similar provision for user-provided mmap
, and so makes mmap
calls directly. This actually causes problems for people who want to accurately account for all of the memory used in the process by interposing mmap
and munmap
.