linux - addr2line 在 Ubuntu 16.10 上不工作?

标签 linux ubuntu

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

另存为foo.c 并用gcc -g foo.c编译

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

我发现地址不是从0x400000开始的,于是转储小 Sprite :

$ 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

入口点不是从 0x400000 开始。为什么?但是 Ubuntu 16.04 没问题。

注意:我发现了一个类似的问题:Ubuntu 16.10 randomizes function addresses at runtime

最佳答案

他们更改了 GCC 的默认设置以发出与位置无关的可执行文件。如果您想要旧的行为,请使用 -fno-pie 进行编译。

关于linux - addr2line 在 Ubuntu 16.10 上不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41890103/

相关文章:

regex - 在 VI 编辑器中将每个出现的正则表达式匹配替换为特定的正则表达式?

python - 无法启动 gunicorn.service : Unit gunicorn. 找不到服务。 Ubuntu 18.04

ubuntu - 解决 IBus 问题 - 1.5.11 之前的 IBus 可能会导致输入问题

linux - Android Studio 2.3 使用来自控制台的模拟器,root 用户为 "/dev/kvm device: permission denied"

ruby - RVM - 无法在 Ubuntu 11.10 上安装 gem thrift

linux - 如何使用 sed 在一行中切换注释

linux - Bash:从文件中读取标准输入并将标准输出写入文件

linux - 在最近的 Linux 上执行进程堆栈中的代码

linux - 禁用特定的USB设备

regex - 用 sed 用另一个转义字符串替换转义字符串