If you want to learn some fantastic and advance technique about Security, You have to command some fundamental knowledge……
Today i will show you how to compile a glibc manually.
Refer from the
It’s the implementation of Standard C library described in C standards plus some extra useful stuffs which are not strictly standard but used frequently.
Its main contents are :
1) C library described in ANSI,c99,c11 standards. It includes macros, symbols, function implementations etc.(printf(),malloc() etc)
2) POSIX standard library. The “userland” glue of system calls. (open(),read() etc. Actually glibc does not “implement” system calls. kernel does it. But glibc provides the user land interface to the services provided by kernel so that user application can use a system call just like a ordinary function.
3) Also some nonstandard but useful stuff.
“use the force, read the source “
$git clone git://sourceware.org/git/glibc.git
ld.so : Dynamic linker of system…Used for Executed-file like a.out
ld-linux.so: Dynamic linker of linux…Used for ELF format Executed-file.
✘ ⚡ root@xiaoyifeng ~/glibc_source/glibc2.23_build # file ./elf/ld-linux-x86-64.so.2 ./elf/ld-linux-x86-64.so.2: symbolic link to ld.so
libc.so : Glibc binary is called libc.so.6
Actually libc.so.6 is a symbolic link to libc.so……
⚡ root@xiaoyifeng ~/glibc_source/glibc2.23_build # file libc.so.6 libc.so.6: symbolic link to libc.so
Before compile it，you should download the special glibc source code and uncompressed it……Then you should mkdir two another directory called for build and compiling file……like this:
It’s important to add
Maybe you would encounter this bad problem. :
can't be versioned to common symbol 'loc1'
Just find the solution in this page : https://www.e-learn.cn/content/qita/664508
--- a/misc/regexp.c +++ b/misc/regexp.c @@ -29,14 +29,15 @@ #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_23) -/* Define the variables used for the interface. */ -char *loc1; -char *loc2; +/* Define the variables used for the interface. Avoid .symver on common + symbol, which just creates a new common symbol, not an alias. */ +char *loc1 __attribute__ ((nocommon)); +char *loc2 __attribute__ ((nocommon)); compat_symbol (libc, loc1, loc1, GLIBC_2_0); compat_symbol (libc, loc2, loc2, GLIBC_2_0); /* Although we do not support the use we define this variable as well. */ -char *locs; +char *locs __attribute__ ((nocommon)); compat_symbol (libc, locs, locs, GLIBC_2_0);
__attribute__ ((nocommon)) behind the
*loc，then you can solve this error;
make install, you can find the libc.so compiled by yourself in build directory, and ld.so is in elf directory.
Although the same version of libc may also have diffrent offset because of the diffrent args in compiling time.
gcc -g -fno-stack-protector -z execstack size_over.c -o size_over -Wl,--rpath=/root/glibc_source/glibc2.23_build/ -Wl,--dynamic-linker=/root/glibc_source/glibc2.23_build/elf/ld-linux-x86-64.so.2
Use gdb to debug in underlying source level：
So cool it is😄!