{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/example-main-program-elf/",
  "atlas": "https://www.pystone.net/?node=example-main-program-elf#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/example-main-program-elf.md",
  "context": "https://www.pystone.net/notes/example-main-program-elf.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:example-main-program-elf",
  "slug": "example-main-program-elf",
  "title": "示例：main_program elf",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "示例：main program elf",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "652a041c75a50c0288a8a8eecaed12362183d8d1f5ebf795cd3a789f10e70a0d",
  "assets": [],
  "headings": [
    {
      "depth": 1,
      "text": "示例：mainprogram elf",
      "anchor": "示例mainprogram-elf",
      "citation": "https://www.pystone.net/notes/example-main-program-elf/#%E7%A4%BA%E4%BE%8Bmainprogram-elf"
    }
  ],
  "claims": [],
  "outgoing": [],
  "incoming": [
    {
      "id": "note:programming-languages-and-runtimes",
      "title": "编程语言与运行时",
      "url": "https://www.pystone.net/notes/programming-languages-and-runtimes/",
      "atlas": "https://www.pystone.net/?node=programming-languages-and-runtimes#knowledge-atlas",
      "label": "编程语言与运行时",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "示例：mainprogram elf",
      "citation": "https://www.pystone.net/notes/programming-languages-and-runtimes/#%E6%9C%AC%E5%B1%82"
    }
  ],
  "contentMarkdown": "# 示例：main_program elf\n\n﻿# 示例：main_program elf\n\n\n\n```c\n// main_program.c\n#include <stdio.h>\n\nextern int add(int, int);  // 声明外部函数\n\nint main() {\n    int result = add(3, 5);  // 调用共享库中的函数\n    printf(\"Result: %d\\n\", result);\n    return 0;\n}\n\n```\n\n```yaml\n\nreadelf -a main_program\nELF Header:\n  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00\n  Class:                             ELF64\n  Data:                              2's complement, little endian\n  Version:                           1 (current)\n  OS/ABI:                            UNIX - System V\n  ABI Version:                       0\n  Type:                              DYN (Shared object file)\n  Machine:                           Advanced Micro Devices X86-64\n  Version:                           0x1\n  Entry point address:               0x640\n  Start of program headers:          64 (bytes into file)\n  Start of section headers:          6480 (bytes into file)\n  Flags:                             0x0\n  Size of this header:               64 (bytes)\n  Size of program headers:           56 (bytes)\n  Number of program headers:         9\n  Size of section headers:           64 (bytes)\n  Number of section headers:         29\n  Section header string table index: 28\n\nSection Headers:\n  [Nr] Name              Type             Address           Offset\n       Size              EntSize          Flags  Link  Info  Align\n  [ 0]                   NULL             0000000000000000  00000000\n       0000000000000000  0000000000000000           0     0     0\n  [ 1] .interp           PROGBITS         0000000000000238  00000238\n       000000000000001c  0000000000000000   A       0     0     1\n  [ 2] .note.ABI-tag     NOTE             0000000000000254  00000254\n       0000000000000020  0000000000000000   A       0     0     4\n  [ 3] .note.gnu.build-i NOTE             0000000000000274  00000274\n       0000000000000024  0000000000000000   A       0     0     4\n  [ 4] .gnu.hash         GNU_HASH         0000000000000298  00000298\n       0000000000000038  0000000000000000   A       5     0     8\n  [ 5] .dynsym           DYNSYM           00000000000002d0  000002d0\n       0000000000000138  0000000000000018   A       6     1     8\n  [ 6] .dynstr           STRTAB           0000000000000408  00000408\n       00000000000000b6  0000000000000000   A       0     0     1\n  [ 7] .gnu.version      VERSYM           00000000000004be  000004be\n       000000000000001a  0000000000000002   A       5     0     2\n  [ 8] .gnu.version_r    VERNEED          00000000000004d8  000004d8\n       0000000000000020  0000000000000000   A       6     1     8\n  [ 9] .rela.dyn         RELA             00000000000004f8  000004f8\n       00000000000000c0  0000000000000018   A       5     0     8\n  [10] .rela.plt         RELA             00000000000005b8  000005b8\n       0000000000000030  0000000000000018  AI       5    22     8\n  [11] .init             PROGBITS         00000000000005e8  000005e8\n       0000000000000017  0000000000000000  AX       0     0     4\n  [12] .plt              PROGBITS         0000000000000600  00000600\n       0000000000000030  0000000000000010  AX       0     0     16\n  [13] .plt.got          PROGBITS         0000000000000630  00000630\n       0000000000000008  0000000000000008  AX       0     0     8\n  [14] .text             PROGBITS         0000000000000640  00000640\n       00000000000001c2  0000000000000000  AX       0     0     16\n  [15] .fini             PROGBITS         0000000000000804  00000804\n       0000000000000009  0000000000000000  AX       0     0     4\n  [16] .rodata           PROGBITS         0000000000000810  00000810\n       0000000000000010  0000000000000000   A       0     0     4\n  [17] .eh_frame_hdr     PROGBITS         0000000000000820  00000820\n       000000000000003c  0000000000000000   A       0     0     4\n  [18] .eh_frame         PROGBITS         0000000000000860  00000860\n       0000000000000108  0000000000000000   A       0     0     8\n  [19] .init_array       INIT_ARRAY       0000000000200da0  00000da0\n       0000000000000008  0000000000000008  WA       0     0     8\n  [20] .fini_array       FINI_ARRAY       0000000000200da8  00000da8\n       0000000000000008  0000000000000008  WA       0     0     8\n  [21] .dynamic          DYNAMIC          0000000000200db0  00000db0\n       0000000000000200  0000000000000010  WA       6     0     8\n  [22] .got              PROGBITS         0000000000200fb0  00000fb0\n       0000000000000050  0000000000000008  WA       0     0     8\n  [23] .data             PROGBITS         0000000000201000  00001000\n       0000000000000010  0000000000000000  WA       0     0     8\n  [24] .bss              NOBITS           0000000000201010  00001010\n       0000000000000008  0000000000000000  WA       0     0     1\n  [25] .comment          PROGBITS         0000000000000000  00001010\n       0000000000000029  0000000000000001  MS       0     0     1\n  [26] .symtab           SYMTAB           0000000000000000  00001040\n       0000000000000600  0000000000000018          27    43     8\n  [27] .strtab           STRTAB           0000000000000000  00001640\n       0000000000000210  0000000000000000           0     0     1\n  [28] .shstrtab         STRTAB           0000000000000000  00001850\n       00000000000000fe  0000000000000000           0     0     1\nKey to Flags:\n  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n  L (link order), O (extra OS processing required), G (group), T (TLS),\n  C (compressed), x (unknown), o (OS specific), E (exclude),\n  l (large), p (processor specific)\n\nThere are no section groups in this file.\n\nProgram Headers:\n  Type           Offset             VirtAddr           PhysAddr\n                 FileSiz            MemSiz              Flags  Align\n  PHDR           0x0000000000000040 0x0000000000000040 0x0000000000000040\n                 0x00000000000001f8 0x00000000000001f8  R      0x8\n  INTERP         0x0000000000000238 0x0000000000000238 0x0000000000000238\n                 0x000000000000001c 0x000000000000001c  R      0x1\n      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]\n  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000\n                 0x0000000000000968 0x0000000000000968  R E    0x200000\n  LOAD           0x0000000000000da0 0x0000000000200da0 0x0000000000200da0\n                 0x0000000000000270 0x0000000000000278  RW     0x200000\n  DYNAMIC        0x0000000000000db0 0x0000000000200db0 0x0000000000200db0\n                 0x0000000000000200 0x0000000000000200  RW     0x8\n  NOTE           0x0000000000000254 0x0000000000000254 0x0000000000000254\n                 0x0000000000000044 0x0000000000000044  R      0x4\n  GNU_EH_FRAME   0x0000000000000820 0x0000000000000820 0x0000000000000820\n                 0x000000000000003c 0x000000000000003c  R      0x4\n  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000\n                 0x0000000000000000 0x0000000000000000  RW     0x10\n  GNU_RELRO      0x0000000000000da0 0x0000000000200da0 0x0000000000200da0\n                 0x0000000000000260 0x0000000000000260  R      0x1\n\n Section to Segment mapping:\n  Segment Sections...\n   00\n   01     .interp\n   02     .interp .note.ABI-tag .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .plt.got .text .fini .rodata .eh_frame_hdr .eh_frame\n   03     .init_array .fini_array .dynamic .got .data .bss\n   04     .dynamic\n   05     .note.ABI-tag .note.gnu.build-id\n   06     .eh_frame_hdr\n   07\n   08     .init_array .fini_array .dynamic .got\n\nDynamic section at offset 0xdb0 contains 28 entries:\n  Tag        Type                         Name/Value\n 0x0000000000000001 (NEEDED)             Shared library: [libadd.so]\n 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]\n 0x000000000000000c (INIT)               0x5e8\n 0x000000000000000d (FINI)               0x804\n 0x0000000000000019 (INIT_ARRAY)         0x200da0\n 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)\n 0x000000000000001a (FINI_ARRAY)         0x200da8\n 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)\n 0x000000006ffffef5 (GNU_HASH)           0x298\n 0x0000000000000005 (STRTAB)             0x408\n 0x0000000000000006 (SYMTAB)             0x2d0\n 0x000000000000000a (STRSZ)              182 (bytes)\n 0x000000000000000b (SYMENT)             24 (bytes)\n 0x0000000000000015 (DEBUG)              0x0\n 0x0000000000000003 (PLTGOT)             0x200fb0\n 0x0000000000000002 (PLTRELSZ)           48 (bytes)\n 0x0000000000000014 (PLTREL)             RELA\n 0x0000000000000017 (JMPREL)             0x5b8\n 0x0000000000000007 (RELA)               0x4f8\n 0x0000000000000008 (RELASZ)             192 (bytes)\n 0x0000000000000009 (RELAENT)            24 (bytes)\n 0x000000000000001e (FLAGS)              BIND_NOW\n 0x000000006ffffffb (FLAGS_1)            Flags: NOW PIE\n 0x000000006ffffffe (VERNEED)            0x4d8\n 0x000000006fffffff (VERNEEDNUM)         1\n 0x000000006ffffff0 (VERSYM)             0x4be\n 0x000000006ffffff9 (RELACOUNT)          3\n 0x0000000000000000 (NULL)               0x0\n\nRelocation section '.rela.dyn' at offset 0x4f8 contains 8 entries:\n  Offset          Info           Type           Sym. Value    Sym. Name + Addend\n000000200da0  000000000008 R_X86_64_RELATIVE                    740\n000000200da8  000000000008 R_X86_64_RELATIVE                    700\n000000201008  000000000008 R_X86_64_RELATIVE                    201008\n000000200fd8  000100000006 R_X86_64_GLOB_DAT 0000000000000000 _ITM_deregisterTMClone + 0\n000000200fe0  000400000006 R_X86_64_GLOB_DAT 0000000000000000 __libc_start_main@GLIBC_2.2.5 + 0\n000000200fe8  000500000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0\n000000200ff0  000600000006 R_X86_64_GLOB_DAT 0000000000000000 _ITM_registerTMCloneTa + 0\n000000200ff8  000700000006 R_X86_64_GLOB_DAT 0000000000000000 __cxa_finalize@GLIBC_2.2.5 + 0\n\nRelocation section '.rela.plt' at offset 0x5b8 contains 2 entries:\n  Offset          Info           Type           Sym. Value    Sym. Name + Addend\n000000200fc8  000200000007 R_X86_64_JUMP_SLO 0000000000000000 add + 0\n000000200fd0  000300000007 R_X86_64_JUMP_SLO 0000000000000000 printf@GLIBC_2.2.5 + 0\n\nThe decoding of unwind sections for machine type Advanced Micro Devices X86-64 is not currently supported.\n\nSymbol table '.dynsym' contains 13 entries:\n   Num:    Value          Size Type    Bind   Vis      Ndx Name\n     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND\n     1: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterTMCloneTab\n     2: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND add\n     3: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND printf@GLIBC_2.2.5 (2)\n     4: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __libc_start_main@GLIBC_2.2.5 (2)\n     5: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__\n     6: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_registerTMCloneTable\n     7: 0000000000000000     0 FUNC    WEAK   DEFAULT  UND __cxa_finalize@GLIBC_2.2.5 (2)\n     8: 0000000000201010     0 NOTYPE  GLOBAL DEFAULT   23 _edata\n     9: 0000000000201018     0 NOTYPE  GLOBAL DEFAULT   24 _end\n    10: 0000000000201010     0 NOTYPE  GLOBAL DEFAULT   24 __bss_start\n    11: 00000000000005e8     0 FUNC    GLOBAL DEFAULT   11 _init\n    12: 0000000000000804     0 FUNC    GLOBAL DEFAULT   15 _fini\n\nSymbol table '.symtab' contains 64 entries:\n   Num:    Value          Size Type    Bind   Vis      Ndx Name\n     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND\n     1: 0000000000000238     0 SECTION LOCAL  DEFAULT    1\n     2: 0000000000000254     0 SECTION LOCAL  DEFAULT    2\n     3: 0000000000000274     0 SECTION LOCAL  DEFAULT    3\n     4: 0000000000000298     0 SECTION LOCAL  DEFAULT    4\n     5: 00000000000002d0     0 SECTION LOCAL  DEFAULT    5\n     6: 0000000000000408     0 SECTION LOCAL  DEFAULT    6\n     7: 00000000000004be     0 SECTION LOCAL  DEFAULT    7\n     8: 00000000000004d8     0 SECTION LOCAL  DEFAULT    8\n     9: 00000000000004f8     0 SECTION LOCAL  DEFAULT    9\n    10: 00000000000005b8     0 SECTION LOCAL  DEFAULT   10\n    11: 00000000000005e8     0 SECTION LOCAL  DEFAULT   11\n    12: 0000000000000600     0 SECTION LOCAL  DEFAULT   12\n    13: 0000000000000630     0 SECTION LOCAL  DEFAULT   13\n    14: 0000000000000640     0 SECTION LOCAL  DEFAULT   14\n    15: 0000000000000804     0 SECTION LOCAL  DEFAULT   15\n    16: 0000000000000810     0 SECTION LOCAL  DEFAULT   16\n    17: 0000000000000820     0 SECTION LOCAL  DEFAULT   17\n    18: 0000000000000860     0 SECTION LOCAL  DEFAULT   18\n    19: 0000000000200da0     0 SECTION LOCAL  DEFAULT   19\n    20: 0000000000200da8     0 SECTION LOCAL  DEFAULT   20\n    21: 0000000000200db0     0 SECTION LOCAL  DEFAULT   21\n    22: 0000000000200fb0     0 SECTION LOCAL  DEFAULT   22\n    23: 0000000000201000     0 SECTION LOCAL  DEFAULT   23\n    24: 0000000000201010     0 SECTION LOCAL  DEFAULT   24\n    25: 0000000000000000     0 SECTION LOCAL  DEFAULT   25\n    26: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c\n    27: 0000000000000670     0 FUNC    LOCAL  DEFAULT   14 deregister_tm_clones\n    28: 00000000000006b0     0 FUNC    LOCAL  DEFAULT   14 register_tm_clones\n    29: 0000000000000700     0 FUNC    LOCAL  DEFAULT   14 __do_global_dtors_aux\n    30: 0000000000201010     1 OBJECT  LOCAL  DEFAULT   24 completed.7698\n    31: 0000000000200da8     0 OBJECT  LOCAL  DEFAULT   20 __do_global_dtors_aux_fin\n    32: 0000000000000740     0 FUNC    LOCAL  DEFAULT   14 frame_dummy\n    33: 0000000000200da0     0 OBJECT  LOCAL  DEFAULT   19 __frame_dummy_init_array_\n    34: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS main_program.c\n    35: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c\n    36: 0000000000000964     0 OBJECT  LOCAL  DEFAULT   18 __FRAME_END__\n    37: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS\n    38: 0000000000200da8     0 NOTYPE  LOCAL  DEFAULT   19 __init_array_end\n    39: 0000000000200db0     0 OBJECT  LOCAL  DEFAULT   21 _DYNAMIC\n    40: 0000000000200da0     0 NOTYPE  LOCAL  DEFAULT   19 __init_array_start\n    41: 0000000000000820     0 NOTYPE  LOCAL  DEFAULT   17 __GNU_EH_FRAME_HDR\n    42: 0000000000200fb0     0 OBJECT  LOCAL  DEFAULT   22 _GLOBAL_OFFSET_TABLE_\n    43: 0000000000000800     2 FUNC    GLOBAL DEFAULT   14 __libc_csu_fini\n    44: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterTMCloneTab\n    45: 0000000000201000     0 NOTYPE  WEAK   DEFAULT   23 data_start\n    46: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND add\n    47: 0000000000201010     0 NOTYPE  GLOBAL DEFAULT   23 _edata\n    48: 0000000000000804     0 FUNC    GLOBAL DEFAULT   15 _fini\n    49: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND printf@@GLIBC_2.2.5\n    50: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __libc_start_main@@GLIBC_\n    51: 0000000000201000     0 NOTYPE  GLOBAL DEFAULT   23 __data_start\n    52: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__\n    53: 0000000000201008     0 OBJECT  GLOBAL HIDDEN    23 __dso_handle\n    54: 0000000000000810     4 OBJECT  GLOBAL DEFAULT   16 _IO_stdin_used\n    55: 0000000000000790   101 FUNC    GLOBAL DEFAULT   14 __libc_csu_init\n    56: 0000000000201018     0 NOTYPE  GLOBAL DEFAULT   24 _end\n    57: 0000000000000640    43 FUNC    GLOBAL DEFAULT   14 _start\n    58: 0000000000201010     0 NOTYPE  GLOBAL DEFAULT   24 __bss_start\n    59: 000000000000074a    55 FUNC    GLOBAL DEFAULT   14 main\n    60: 0000000000201010     0 OBJECT  GLOBAL HIDDEN    23 __TMC_END__\n    61: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_registerTMCloneTable\n    62: 0000000000000000     0 FUNC    WEAK   DEFAULT  UND __cxa_finalize@@GLIBC_2.2\n    63: 00000000000005e8     0 FUNC    GLOBAL DEFAULT   11 _init\n\nHistogram for .gnu.hash' bucket list length (total of 3 buckets):\n Length  Number     % of total  Coverage\n      0  0          (  0.0%)\n      1  1          ( 33.3%)     20.0%\n      2  2          ( 66.7%)    100.0%\n\nVersion symbols section '.gnu.version' contains 13 entries:\n Addr: 00000000000004be  Offset: 0x0004be  Link: 5 (.dynsym)\n  000:   0 (*local*)       0 (*local*)       0 (*local*)       2 (GLIBC_2.2.5)\n  004:   2 (GLIBC_2.2.5)   0 (*local*)       0 (*local*)       2 (GLIBC_2.2.5)\n  008:   1 (*global*)      1 (*global*)      1 (*global*)      1 (*global*)\n  00c:   1 (*global*)\n\nVersion needs section '.gnu.version_r' contains 1 entry:\n Addr: 0x00000000000004d8  Offset: 0x0004d8  Link: 6 (.dynstr)\n  000000: Version: 1  File: libc.so.6  Cnt: 1\n  0x0010:   Name: GLIBC_2.2.5  Flags: none  Version: 2\n\nDisplaying notes found in: .note.ABI-tag\n  Owner                 Data size       Description\n  GNU                  0x00000010       NT_GNU_ABI_TAG (ABI version tag)\n    OS: Linux, ABI: 3.2.0\n\nDisplaying notes found in: .note.gnu.build-id\n  Owner                 Data size       Description\n  GNU                  0x00000014       NT_GNU_BUILD_ID (unique build ID bitstring)\n    Build ID: 1a98050da8e372ee5ca3d1f359d6171357277bd4\n```\n"
}
