0
下面代碼示例中的兩個奇怪的外觀沒有任何意義。我想知道linux內存對齊和佈局
- 爲什麼
foo
和argv[0]
之間的距離總是有什麼不同? - 爲什麼不與4對齊?雖然預期結果是4的倍數,並且不是
我想知道奇怪外觀的詳細原因。
,我知道它不與ASLR
[[email protected] ~]# cat /etc/fedora-release
Fedora release 14 (Laughlin)
[[email protected] ~]# cat poc.c
#include <stdio.h>
int main(int argc, char *argv[]){
int foo;
printf("%d\n", (int)argv[0] - (int)&foo);
}
[[email protected] ~]# ./poc
5345
[[email protected] ~]# ./poc
8465
[[email protected] ~]# ./poc
4641
[[email protected] ~]# ./poc
1201
[[email protected] ~]# ./poc
2881
[[email protected] ~]# ./poc
7073
[[email protected] ~]# ./poc
5905
[[email protected] ~]# ./poc
2225
[[email protected] ~]# ./poc
2465
[[email protected] ~]# ./poc
6017
[[email protected] ~]# ./poc
8657
[[email protected] ~]# ./poc
8401
[[email protected] ~]# ./poc
5073
[[email protected] ~]# ./poc
5505
[[email protected] ~]# ./poc
1761
[[email protected] ~]# ./poc
8609
[[email protected] ~]# ./poc
3665
[[email protected] ~]# ./poc
3633
[[email protected] ~]# ./poc
6257
[[email protected] ~]# ./poc
3441
[[email protected] ~]# ./poc
4961
[[email protected] ~]# ./poc
5233
[[email protected] ~]# ./poc
561
[[email protected] ~]# ./poc
3441
[[email protected] ~]# ./poc
2097
[[email protected] ~]# ./poc
1729
[[email protected] ~]# ./poc
1841
[[email protected] ~]# ./poc
2241
[[email protected] ~]# ./poc
2145
[[email protected] ~]# ./poc
6593
[[email protected] ~]# ./poc
5681
[[email protected] ~]# ./poc
737
[[email protected] ~]# ./poc
8353
[[email protected] ~]# ./poc
1937
[[email protected] ~]# ./poc
3937
[[email protected] ~]# ./poc
4769
[[email protected] ~]# ./poc
3441
[[email protected] ~]# ./poc
6097
[[email protected] ~]# ./poc
6673
[[email protected] ~]# ./poc
1857
[[email protected] ~]# ./poc
5617
[[email protected] ~]# ./poc
5473
[[email protected] ~]# ./poc
7313
[[email protected] ~]# ./poc
3921
[[email protected] ~]# ./poc
2369
[[email protected] ~]# ./poc
4609
[[email protected] ~]# ./poc
5569
[[email protected] ~]# ./poc
6209
[[email protected] ~]# ./poc
3457
[[email protected] ~]# ./poc
3665
[[email protected] ~]# ./poc
3297
[[email protected] ~]# ./poc
4465
[[email protected] ~]# ./poc
5281
[[email protected] ~]# ./poc
6017
[[email protected] ~]# ./poc
2705
[[email protected] ~]# ./poc
1601
[[email protected] ~]# ./poc
7457
[[email protected] ~]# ./poc
4145
[[email protected] ~]# ./poc
2353
[[email protected] ~]# ./poc
5537
[[email protected] ~]# ./poc
7873
[[email protected] ~]# ./poc
6449
[[email protected] ~]# ./poc
3297