I am encountering a problem to understand what the file pointers stdin, stdout and stderr mean and how they are loaded into the memory. The program
#include <stdio.h>
int main(void) {
printf("stdin = %p\n", (void *) stdin);
printf("stdout = %p\n", (void *) stdout);
printf("stderr = %p\n", (void *) stderr);
return 0;
}
outputs
stdin = 0x7ffff7fa29a0
stdout = 0x7ffff7fa36c0
stderr = 0x7ffff7fa35e0
What I know is that stdin,stdout and stderr somehow correspond to the file descriptors 0, 1, and 2. However, if I print the value under the given address (e.g. for stdin) with gdb then I get the following line:
0x7ffff7fa29a0 <_IO_2_1_stdin_>: 0x00000000fbad2088
What is _IO_2_1_? If 0 is a file descriptor for stdin, what is 0xfbad2088?
Furthermore, I take a look at the symbols with readelf and get the following line:
25: 0000000000004050 8 OBJECT GLOBAL DEFAULT 26 stdin@GLIBC_2.2.5
I thought libc is a bunch of functions. Why does a file/pointer stands in GOT?
At what time the file pointers stdin, stdout and stderr are loaded into memory and why do I cannot find any 0, 1 and 2 when debugging?