当使用mcmodel = medium编译时,C程序会因分段错误而崩溃 . 我们在堆栈上使用了一些非常大的数组,我们需要启用中型mcmodel . 我正在使用g 5.4,当我对应用程序进行扫描时,它会打印出错误 . 请告知如何调试 .
strace ./app
execve("./app", ["./app"], [/* 65 vars */]) = -1 ENOMEM (Cannot allocate memory)
--- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
+++ killed by SIGSEGV +++
Segmentation fault (core dumped)
粘贴可执行readelf -l app的readelf输出
Elf file type is EXEC (Executable file)
Entry point 0x6e4f60
There are 9 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000000400040 0x0000000000400040
0x00000000000001f8 0x00000000000001f8 R E 8
INTERP 0x0000000000000238 0x0000000000400238 0x0000000000400238
0x000000000000001c 0x000000000000001c R 1
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000
0x000000000074d0b8 0x000000000074d0b8 R E 200000
LOAD 0x000000000074dc50 0x0000000000d4dc50 0x0000000000d4dc50
0x00000000000aafe0 0x00000041bf407a08 RW 200000
DYNAMIC 0x000000000074dda8 0x0000000000d4dda8 0x0000000000d4dda8
0x0000000000000250 0x0000000000000250 RW 8
NOTE 0x0000000000000254 0x0000000000400254 0x0000000000400254
0x0000000000000044 0x0000000000000044 R 4
GNU_EH_FRAME 0x00000000006b2c18 0x0000000000ab2c18 0x0000000000ab2c18
0x000000000000ef14 0x000000000000ef14 R 4
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RW 10
GNU_RELRO 0x000000000074dc50 0x0000000000d4dc50 0x0000000000d4dc50
0x00000000000003b0 0x00000000000003b0 R 1
Section to Segment mapping:
Segment Sections...
00
01 .interp
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 .gcc_except_table
03 .init_array .fini_array .jcr .dynamic .got .got.plt .data .bss .lbss
04 .dynamic
05 .note.ABI-tag .note.gnu.build-id
06 .eh_frame_hdr
07
08 .init_array .fini_array .jcr .dynamic .got
内核版本:Linux rk-VirtualBox 4.4.0-64-lowlatency#85-Ubuntu SMP PREEMPT星期二2月20日12:39:25 UTC 2017 x86_64 x86_64 x86_64 GNU / Linux
1 回答
您显示的
strace
输出表明内核拒绝启动您的程序(不执行程序的单个指令) .内核简单地说:“这个可执行文件的构建方式使我无法运行” .
输出
readelf -l ./app
和确切的内核版本可以帮助进一步诊断 .Update:
第二个
LOAD
段:要求内核分配(
mmap
)0x41bf407a08
个字节 . 那个's almost 263GiB. Either your machine doesn't有那么多内存,或者你的ulimit -v
和ulimit -d
设置得太低,或两者兼而有之 .