简体   繁体   English

addr2line无法在Ubuntu 16.10上唤醒吗?

[英]addr2line not woking on Ubuntu 16.10?

#include <stdio.h>
void foo() {}
int main(int argc, char **argv)
{
    printf("%p\n", foo);
    return 0;
}

save as foo.c and compile with gcc -g foo.c 另存为foo.c并使用gcc -g foo.c编译

$ ./a.out
0x564e523896a0
$ addr2line 0x564e523896a0 -f -e a.out
??
??:0

I found the address doesn't start at 0x400000 , and dumped the elf: 我发现地址不是从0x400000开始,然后转储了elf:

$ readelf -h a.out
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:                              DYN (Shared object file)
Machine:                           Advanced Micro Devices X86-64
Version:                           0x1
Entry point address:               0x570
Start of program headers:          64 (bytes into file)
Start of section headers:          8808 (bytes into file)
Flags:                             0x0
Size of this header:               64 (bytes)
Size of program headers:           56 (bytes)
Number of program headers:         9
Size of section headers:           64 (bytes)
Number of section headers:         34
Section header string table index: 31

The entry point doesn't start at 0x400000 . 入口点不是从0x400000开始。 Why? 为什么? But Ubuntu 16.04 is fine. 但是Ubuntu 16.04很好。

NOTE : I've found a similar question: Ubuntu 16.10 randomizes function addresses at runtime 注意 :我发现了一个类似的问题: Ubuntu 16.10在运行时随机分配函数地址

They changed the default of GCC to emit Position Independent Executables. 他们将GCC的默认值更改为发出与位置无关的可执行文件。 If you want the old behavior, compile with -fno-pie . 如果您想要旧的行为,请使用-fno-pie编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM