为什么在没有使用 malloc 时存在堆部分 [英] Why is the heap section present when there are no malloc used

查看:154
本文介绍了为什么在没有使用 malloc 时存在堆部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们不调用 malloc,我试图找出进程的地址空间中是否存在堆.

I am trying to find out whether heap exists in the address space of the process, if we don't call malloc.

#include <stdio.h>
int main()
{
    getchar();
    return 0;
}

即使我不调用 malloc,映射中也存在堆部分

Heap section is present in the maps even if i dont call malloc

cat /proc/73268/maps
55d0b405c000-55d0b4160000 r-xp 00000000 08:01 5505031                    /bin/bash
55d0b435f000-55d0b4363000 r--p 00103000 08:01 5505031                    /bin/bash
55d0b4363000-55d0b436c000 rw-p 00107000 08:01 5505031                    /bin/bash
55d0b436c000-55d0b4376000 rw-p 00000000 00:00 0 
55d0b567e000-55d0b5815000 rw-p 00000000 00:00 0                          [heap]
7f57533fd000-7f5753408000 r-xp 00000000 08:01 2102129                    /lib/x86_64-linux-gnu/libnss_files-2.27.so
7f5753408000-7f5753607000 ---p 0000b000 08:01 2102129                    /lib/x86_64-linux-gnu/libnss_files-2.27.so
7f5753607000-7f5753608000 r--p 0000a000 08:01 2102129                    /lib/x86_64-linux-gnu/libnss_files-2.27.so
7f5753608000-7f5753609000 rw-p 0000b000 08:01 2102129                    /lib/x86_64-linux-gnu/libnss_files-2.27.so
7f5753609000-7f575360f000 rw-p 00000000 00:00 0 
7f575360f000-7f5753626000 r-xp 00000000 08:01 2102123                    /lib/x86_64-linux-gnu/libnsl-2.27.so
7f5753626000-7f5753825000 ---p 00017000 08:01 2102123                    /lib/x86_64-linux-gnu/libnsl-2.27.so
7f5753825000-7f5753826000 r--p 00016000 08:01 2102123                    /lib/x86_64-linux-gnu/libnsl-2.27.so
7f5753826000-7f5753827000 rw-p 00017000 08:01 2102123                    /lib/x86_64-linux-gnu/libnsl-2.27.so
7f5753827000-7f5753829000 rw-p 00000000 00:00 0 
7f5753829000-7f5753834000 r-xp 00000000 08:01 2102140                    /lib/x86_64-linux-gnu/libnss_nis-2.27.so
7f5753834000-7f5753a33000 ---p 0000b000 08:01 2102140                    /lib/x86_64-linux-gnu/libnss_nis-2.27.so
7f5753a33000-7f5753a34000 r--p 0000a000 08:01 2102140                    /lib/x86_64-linux-gnu/libnss_nis-2.27.so
7f5753a34000-7f5753a35000 rw-p 0000b000 08:01 2102140                    /lib/x86_64-linux-gnu/libnss_nis-2.27.so
7f5753a35000-7f5753a3d000 r-xp 00000000 08:01 2102125                    /lib/x86_64-linux-gnu/libnss_compat-2.27.so
7f5753a3d000-7f5753c3d000 ---p 00008000 08:01 2102125                    /lib/x86_64-linux-gnu/libnss_compat-2.27.so
7f5753c3d000-7f5753c3e000 r--p 00008000 08:01 2102125                    /lib/x86_64-linux-gnu/libnss_compat-2.27.so
7f5753c3e000-7f5753c3f000 rw-p 00009000 08:01 2102125                    /lib/x86_64-linux-gnu/libnss_compat-2.27.so
7f5753c3f000-7f575460e000 r--p 00000000 08:01 793285                     /usr/lib/locale/locale-archive
7f575460e000-7f57547f5000 r-xp 00000000 08:01 2102039                    /lib/x86_64-linux-gnu/libc-2.27.so
7f57547f5000-7f57549f5000 ---p 001e7000 08:01 2102039                    /lib/x86_64-linux-gnu/libc-2.27.so
7f57549f5000-7f57549f9000 r--p 001e7000 08:01 2102039                    /lib/x86_64-linux-gnu/libc-2.27.so
7f57549f9000-7f57549fb000 rw-p 001eb000 08:01 2102039                    /lib/x86_64-linux-gnu/libc-2.27.so
7f57549fb000-7f57549ff000 rw-p 00000000 00:00 0 
7f57549ff000-7f5754a02000 r-xp 00000000 08:01 2102062                    /lib/x86_64-linux-gnu/libdl-2.27.so
7f5754a02000-7f5754c01000 ---p 00003000 08:01 2102062                    /lib/x86_64-linux-gnu/libdl-2.27.so
7f5754c01000-7f5754c02000 r--p 00002000 08:01 2102062                    /lib/x86_64-linux-gnu/libdl-2.27.so
7f5754c02000-7f5754c03000 rw-p 00003000 08:01 2102062                    /lib/x86_64-linux-gnu/libdl-2.27.so
7f5754c03000-7f5754c28000 r-xp 00000000 08:01 2102197                    /lib/x86_64-linux-gnu/libtinfo.so.5.9
7f5754c28000-7f5754e28000 ---p 00025000 08:01 2102197                    /lib/x86_64-linux-gnu/libtinfo.so.5.9
7f5754e28000-7f5754e2c000 r--p 00025000 08:01 2102197                    /lib/x86_64-linux-gnu/libtinfo.so.5.9
7f5754e2c000-7f5754e2d000 rw-p 00029000 08:01 2102197                    /lib/x86_64-linux-gnu/libtinfo.so.5.9
7f5754e2d000-7f5754e54000 r-xp 00000000 08:01 2102011                    /lib/x86_64-linux-gnu/ld-2.27.so
7f5754fb6000-7f575503c000 rw-p 00000000 00:00 0 
7f575504d000-7f5755054000 r--s 00000000 08:01 1050910                    /usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache
7f5755054000-7f5755055000 r--p 00027000 08:01 2102011                    /lib/x86_64-linux-gnu/ld-2.27.so
7f5755055000-7f5755056000 rw-p 00028000 08:01 2102011                    /lib/x86_64-linux-gnu/ld-2.27.so
7f5755056000-7f5755057000 rw-p 00000000 00:00 0 
7ffd41cc9000-7ffd41cea000 rw-p 00000000 00:00 0                          [stack]
7ffd41db7000-7ffd41dba000 r--p 00000000 00:00 0                          [vvar]
7ffd41dba000-7ffd41dbc000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

我在 Ubuntu 18.04 上试过这个,gcc 版本是 7.4.0,你们能帮我理解为什么即使我们没有任何 malloc 也会创建堆部分.

I tried this on Ubuntu 18.04 and gcc version is 7.4.0, can you guys help me understand why is the heap section created even if we dont have any malloc.

推荐答案

试试这个

int main()
{
        for(;;);
}

并用 gcc test.c -nodefaultlibs -Wl,-e,main -o test -nostdlib -static

这篇关于为什么在没有使用 malloc 时存在堆部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆