所以,我听说ld-linux.so progname
相当于直接运行progname
,假设您使用ld-linux.so
中记录的progname
,例如:
$ readelf -l ../pytorch-tmp-env/bin/python
Elf file type is DYN (Shared object file)
Entry point 0x1c774a
There are 9 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000000000040 0x0000000000000040
0x00000000000001f8 0x00000000000001f8 R E 8
INTERP 0x0000000000000238 0x0000000000000238 0x0000000000000238
0x000000000000001c 0x000000000000001c R 1
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
但是,我发现直接运行该程序有效,而这样做会导致它出现段错误:
$ ../pytorch-tmp-env/bin/python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ /lib64/ld-linux-x86-64.so.2 ../pytorch-tmp-env/bin/python
Segmentation fault (core dumped)
根据gdb,segfault看起来像这样:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff75171a0 in fileno_unlocked () from /lib64/libc.so.6
(gdb) disas
Dump of assembler code for function fileno_unlocked:
=> 0x00007ffff75171a0 <+0>: testl $0x2000,(%rdi)
0x00007ffff75171a6 <+6>: je 0x7ffff75171b8 <fileno_unlocked+24>
0x00007ffff75171a8 <+8>: mov 0x70(%rdi),%eax
0x00007ffff75171ab <+11>: test %eax,%eax
0x00007ffff75171ad <+13>: js 0x7ffff75171b8 <fileno_unlocked+24>
0x00007ffff75171af <+15>: repz retq
0x00007ffff75171b1 <+17>: nopl 0x0(%rax)
0x00007ffff75171b8 <+24>: mov 0x348ca9(%rip),%rax # 0x7ffff785fe68
0x00007ffff75171bf <+31>: movl $0x9,%fs:(%rax)
0x00007ffff75171c6 <+38>: mov $0xffffffff,%eax
0x00007ffff75171cb <+43>: retq
End of assembler dump.
(gdb) info registers
rax 0x0 0
rbx 0x1 1
rcx 0xffff8000083084c2 -140737350957886
rdx 0x0 0
rsi 0x0 0
rdi 0x0 0
rbp 0x0 0x0
rsp 0x7fffffffd6d8 0x7fffffffd6d8
r8 0x0 0
r9 0x1 1
r10 0x1 1
r11 0x1 1
r12 0x0 0
r13 0x0 0
r14 0x0 0
r15 0x0 0
rip 0x7ffff75171a0 0x7ffff75171a0 <fileno_unlocked>
eflags 0x10202 [ IF RF ]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
我可能做错了什么?