/*
* gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)
*/
#include <stdio.h>
int main(void)
{
return printf("main=%p\n", main);
}
gcc main.c -o main
./main
main=0x55e780f1164a
./main
main=0x55cf8b90c64a
./main
main=0x56484d6e864a
各位路过的大神:
为什么main在不同的运行中 地址会不一样呢?
附:
[1]
----------------------------------------------------------------------
ld --verbose
GNU ld (GNU Binutils for Ubuntu) 2.30
......
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = SEGMENT_START("text-segment",
0x400000)); . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS;
[2] /* 这里表达 跟0x400000 无关?*/
-------------------------------------------------------------
readelf -h main
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: 0x540
Start of program headers: 64 (bytes into file)
Start of section headers: 6440 (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: 29
Section header string table index: 28
objdump -ds main
000000000000064a <main>:
64a: 55 push %rbp
64b: 48 89 e5 mov %rsp,%rbp
64e: 48 8d 35 f5 ff ff ff lea -0xb(%rip),%rsi # 64a <main>
655: 48 8d 3d 98 00 00 00 lea 0x98(%rip),%rdi # 6f4 <_IO_stdin_used+0x4>
65c: b8 00 00 00 00 mov $0x0,%eax
661: e8 ba fe ff ff callq 520 <printf@plt>
666: 5d pop %rbp
667: c3 retq
668: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1)
66f: 00
[3]
_________________________________________________
addr2line -e main 0x55e780f1164a -f
??
??:0
addr2line -e main
64a -f
main
??:?