c++ - 带有自定义* .o文件的“ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000”

标签 c++ elf entry-point readelf

我已经编译了一个简单的目标文件文件,并尝试与ld链接,但是它给出了警告。但是,该文件具有_start符号,这是对象的readelf

ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x40
  Start of program headers:          0 (bytes into file)
  Start of section headers:          59392 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         0
  Size of section headers:           64 (bytes)
  Number of section headers:         6
  Section header string table index: 5
(...)
Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .text             PROGBITS         0000000000000000  00000040
       000000000000005c  0000000000000000  AX       0     0     1
  [ 2] .data             PROGBITS         0000000000000000  00001040
       0000000000001000  0000000000000000  WA       0     0     8
  [ 3] .symtab           SYMTAB           0000000000000000  00003400
       0000000000000030  0000000000000018           4     2     8
  [ 4] .strtab           STRTAB           0000000000000000  00003800
       0000000000000400  0000000000000000           0     0     1
  [ 5] .shstrtab         STRTAB           0000000000000000  00003000
       0000000000000400  0000000000000000           0     0     1
(...)
Symbol table '.symtab' contains 2 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000    87 FUNC    GLOBAL DEFAULT    1 _start

这可能是什么问题

最佳答案

因此,我发现了问题。符号节头的info必须是符号表中_start函数的索引。但是由于某种原因,链接器后来改变了,但是效果很好!!

关于c++ - 带有自定义* .o文件的“ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61239336/

相关文章:

linux - 我可以在MacOS的_start处通过代码执行 `ret`指令吗? Linux的?

c++ - 在 C++11 中, protected 意味着公共(public)?

c++ - "detail"和 "impl"文件夹有什么用?

c++ - 为 C++11 移动语义编辑 Google 的 C++ DISALLOW_COPY_AND_ASSIGN 预处理器宏

c - 实现跟踪 C 内存错误的工具,找到从哪里调用我覆盖的 malloc 等

c++ - 为什么动态链接的二进制文件显示硬编码的 SO 名称?

c++ - .bss 部分零初始化变量是否占用 elf 文件中的空间?

c++ - void main() 有什么问题?

c++ - 具有可变参数模板的递归继承和继承参数问题

python - setuptools 入口点。将可执行文件安装到/usr/sbin