Linux — The Auxiliary Vector (AUXV)

Shlomi Boutnaru, Ph.D.
2 min readAug 24, 2022

There are specific OS variables that a program would probably want to query such as the size of a page (part of memory management — for a future writeup). So how can it be done?

When the OS executes a program it exposes information about the environment in a key-value data store called “auxiliary vector” (in short auxv/AUXV). If we want to check which keys are available we can go over https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/auxvec.h#L10 (on older versions it was part of elf.h) and look for all the defines that start with “AT_”.

Among the information that is included in AUXV we can find: the effective uid of the program, the real uid of the program, the system page size, number of program headers (of the ELF — more on that in the future), minimal stack size for signal delivery (and there is more).

If we want to see all the info of AUXV while running a program we can set the LD_AUXV_SHOW environment variable to 1 and execute the requested program (see the screenshot below, it was taken from JSLinux running Fedora 33 based on a riscv64 CPU- https://bellard.org/jslinux/). We can see that the name of the variable starts with “LD_”, it is because it is used/parsed by the dynamic linker/loader (aka ld.so).

Thus, if we statically link our program (like using the -static flag on gcc) setting the variable won’t print the values of AUXV. Anyhow, we can also access the values in AUXV using the “unsigned long getauxval(unsigned long type)” library function (https://man7.org/linux/man-pages/man3/getauxval.3.html). A nice fact is that the auxiliary vector is located next to the environment variables check the following illustration — https://static.lwn.net/images/2012/auxvec.png.

You can also check my twitter account — @boutnaru (https://twitter.com/boutnaru)

See you next time ;-)

#linux #kernel #elf

Showing AUXV for an executing program (uname)

--

--