test2.c
#include <stdio.h>
int main(int arg, char *argv[]){
        printf("hello\n");
}
--#include is not a C grammar, but a preprocessor instruction
--There are many standard function definitions in stdio.h
--#include only expands the contents of stdio.h
--There are two main types in the header file.
--What is installed by default on the system
- #include <>
--Standard header files are located in a directory called / usr / include
--Looking at stdio.h, it says "the GNU C Library" and there is code in glibc (probably)
--Searching for stdio.h from the glibc source gets 3 stuck
--Some of / usr / include are provided by other than glibc (Linux kernel and other libraries, etc.)
――It seems to be less than
--/usr/include/.h: Standard C library
--/usr/include/sys/.h: Provided by OS kernel
--/usr/include/net/*.h: Network related
--It seems that the substance of glibc is → (Ubuntu 16.04) / usr / lib / x86_64-linux-gnu /
--If you check with readelf, there is printf.o
--If you look for printf.c, there are various things like that under the stdio-common directory under the glibc source.
--If you look in printf.c, you can see that it calls vfprintf. (End here)
--Local things defined in the program
- #include ""
--Header file location
--There is stdio.h in glibc
command
ubuntu# ls /usr/include | grep stdio
stdio.h
stdio_ext.h
/usr/include/stdio.h
/* Define ISO C stdio on top of C++ iostreams.
   Copyright (C) 1991-2016 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.
   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.
   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */
command
ubuntu# find . -name "stdio.h"
./include/stdio.h
./libio/stdio.h
./libio/bits/stdio.h
commmand
ubuntu# readelf -a /usr/lib/x86_64-linux-gnu/libc.a | grep printf | grep -v "[a-z_]printf"
     9: 0000000000000480  9125 FUNC    LOCAL  DEFAULT    1 printf_positional
File: libc.a(printf_fp.o)
File: libc.a(reg-printf.o)
File: libc.a(printf-prs.o)
File: libc.a(printf_fphex.o)
File: libc.a(printf_size.o)
    28: 0000000000000000  2223 FUNC    GLOBAL DEFAULT    1 printf_size
    29: 00000000000008b0    31 FUNC    GLOBAL DEFAULT    1 printf_size_info
File: libc.a(printf.o)
    11: 0000000000000000   158 FUNC    GLOBAL DEFAULT    1 printf
    10: 0000000000000370 10733 FUNC    LOCAL  DEFAULT    1 printf_positional
File: libc.a(printf-parsemb.o)
File: libc.a(printf-parsewc.o)
File: libc.a(printf_chk.o)
command
# find . -name "*printf.c" | grep comm
./stdio-common/fprintf.c
./stdio-common/asprintf.c
./stdio-common/printf.c
./stdio-common/reg-printf.c
./stdio-common/tst-obprintf.c
./stdio-common/tst-swprintf.c
./stdio-common/tst-wc-printf.c
./stdio-common/fxprintf.c
./stdio-common/vprintf.c
./stdio-common/vfwprintf.c
./stdio-common/dprintf.c
./stdio-common/vfprintf.c
./stdio-common/test-vfprintf.c
./stdio-common/sprintf.c
./stdio-common/tst-printf.c
./stdio-common/tst-sprintf.c
./stdio-common/snprintf.c
stdio-common/printf.c(Excerpt)
/* Write formatted output to stdout from the format string FORMAT.  */
/* VARARGS1 */
int
__printf (const char *format, ...)
{
  va_list arg;
  int done;
  va_start (arg, format);
  done = vfprintf (stdout, format, arg);
  va_end (arg);
  return done;
}