一、什么是Map文件

map文件就是通过编译器编译之后,生成的程序、数据及IO空间信息的一种映射文件,里面包含函数大小,入口地址等一些重要信息。从map文件我们可以了解到:

  • 程序各区段的寻址是否正确
  • 程序各区段的size,即目前存储器的使用量
  • 程序中各个symbol的地址
  • 各个symbol在存储器中的顺序关系(这在调试时很有用)
  • 各个程序文件的存储用量

二、实例说明

1.简单的C 程序,生成map 文件

main.c
#include <stdio.h>
#include "add.h"
char* Hello="HelloWorld!";
char array[4]={0,1,2,3};
char array0[6];
int g_gloableInt;
double doubletest = 10;
char* testP = NULL;
int* pInt;
#define READ_SIZE (0x7A0)
void main(void)
{
	int a = 5,b = 6,sum=0;
	static int staticInt = 0;
	char data[READ_SIZE]={0};
	int ret = 0;
	FILE* fp = fopen("abuf_apu_nbsm_o1_1_00720.mpg","r");
	//FILE* fp_out = fopen("abuf_apu_nbsm_o1_1_00720_out.mpg","w+");
	FILE* fp_out = fopen("abuf_apu_nbsm_o1_1_00720_out.mpg","w+");
	if(!fp || !fp_out)
	{
		printf("NULL data file!");
		return;
	}
	
	sum=math(a,b);
	printf("sum is %d\n",sum);
	staticInt += sum;
	g_gloableInt =0;
	printf("main=%016llx,math=%016llx,add=%016llx,sub=%016llx\ng_gloableInt=%016llx staticInt=%016llx Hello=%016llx\n",(long long)main,(long long)math,(long long)add,(long long)sub,(long long)&g_gloableInt,(long long)&staticInt,(long long)Hello);
	printf("sizeof(doubletest)=%ld sizeof(testP)=%ld sizeof(array0)=%ld \n",sizeof(doubletest),sizeof(testP),sizeof(array0));
	printf("&doubletest=%016llx,testP=%016llx array0=%016llx\n",(long long)&doubletest,(long long)testP,(long long)array0);
	fseek(fp, 0, SEEK_SET);
	fseek(fp_out, 0, SEEK_SET);
	do
	{
		ret=fread(data,1,READ_SIZE,fp);
		//printf("read %d byte data\n",ret);
		fwrite((data+32),(ret-32),1,fp_out);
	}while(ret==READ_SIZE);
	fclose(fp);
	fclose(fp_out);
	return;
}
---------------------------------------------------------------------------------------
add.c
#include "add.h"
int Min = 10;
int sub(int* v)
{
	*v = (*v >Min)? (*v - Min):*v ;
	return 0;
}
int add(int a, int b)
{
	int sum = a+b;
	sub(&sum);
	return sum;
}
int math(int a,int b)
{
	return add(a,b);
}

---------------------------------------------------------------------------------------
#ifndef __ADD_H__
#define __ADD_H__
int math(int a, int b);
int add(int a, int b);
int sub(int* a);
#endif

--------------------------------------------------------------------------------------
dummy.c
#include "dummy.h"

int dummy_ver0(int dummmy)
{
	return 0;
}
--------------------------------------------------------------------------------------
#ifndef __DUMMY_H__
#define __DUMMY_H__
int dummy_ver0(int dummmy);
#endif

编译命令

gcc main.c add.c -Wl,-Map,add.map -o main   

生成的map 文件为:

Archive member included to satisfy reference by file (symbol) ==>included archive

/usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS)
                              /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o (__libc_csu_init)

As-needed library included to satisfy reference by file (symbol)  ==>link 的lib

libc.so.6                     /tmp/ccYQAtfU.o (fopen@@GLIBC_2.2.5)

Allocating common symbols
Common symbol       size              file

pInt                0x8               /tmp/ccYQAtfU.o
g_gloableInt        0x4               /tmp/ccYQAtfU.o
array0              0x6               /tmp/ccYQAtfU.o

Discarded input sections

 .note.GNU-stack
                0x0000000000000000        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 .note.GNU-stack
                0x0000000000000000        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o
 .note.GNU-stack
                0x0000000000000000        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
 .note.GNU-stack
                0x0000000000000000        0x0 /tmp/ccYQAtfU.o ==>实际是main.o
 .note.GNU-stack
                0x0000000000000000        0x0 /tmp/ccetcq5K.o ==>实际是add.o
 .note.GNU-stack
                0x0000000000000000        0x0 /tmp/ccYNVa0B.o ==>实际是dummy.o
 .note.GNU-stack
                0x0000000000000000        0x0 /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS)
 .note.GNU-stack
                0x0000000000000000        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o
 .note.GNU-stack
                0x0000000000000000        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o

Memory Configuration

Name             Origin             Length             Attributes
*default*        0x0000000000000000 0xffffffffffffffff

Linker script and memory map

LOAD /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
LOAD /tmp/ccYQAtfU.o
LOAD /tmp/ccetcq5K.o
LOAD /tmp/ccYNVa0B.o
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/libgcc.a
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/libgcc_s.so
START GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/libgcc_s.so.1
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/libgcc.a
END GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.so
START GROUP
LOAD /lib/x86_64-linux-gnu/libc.so.6
LOAD /usr/lib/x86_64-linux-gnu/libc_nonshared.a
LOAD /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
END GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/libgcc.a
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/libgcc_s.so
START GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/libgcc_s.so.1
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/libgcc.a
END GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o
                [!provide]                        PROVIDE (__executable_start = SEGMENT_START ("text-segment", 0x0))
                0x0000000000000238                . = (SEGMENT_START ("text-segment", 0x0) + SIZEOF_HEADERS)

.interp         0x0000000000000238       0x1c
 *(.interp)
 .interp        0x0000000000000238       0x1c /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o

.note.ABI-tag   0x0000000000000254       0x20
 .note.ABI-tag  0x0000000000000254       0x20 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o

.note.gnu.build-id
                0x0000000000000274       0x24
 *(.note.gnu.build-id)
 .note.gnu.build-id
                0x0000000000000274       0x24 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o

.hash
 *(.hash)

.gnu.hash       0x0000000000000298       0x1c
 *(.gnu.hash)
 .gnu.hash      0x0000000000000298       0x1c /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o

.dynsym         0x00000000000002b8      0x138
 *(.dynsym)
 .dynsym        0x00000000000002b8      0x138 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o

.dynstr         0x00000000000003f0       0xbf
 *(.dynstr)
 .dynstr        0x00000000000003f0       0xbf /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o

.gnu.version    0x00000000000004b0       0x1a
 *(.gnu.version)
 .gnu.version   0x00000000000004b0       0x1a /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o

.gnu.version_d  0x00000000000004d0        0x0
 *(.gnu.version_d)
 .gnu.version_d
                0x00000000000004d0        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o

.gnu.version_r  0x00000000000004d0       0x30
 *(.gnu.version_r)
 .gnu.version_r
                0x00000000000004d0       0x30 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o

.rela.dyn       0x0000000000000500       0xd8
 *(.rela.init)
 *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
 .rela.text     0x0000000000000500        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 *(.rela.fini)
 *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
 *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
 .rela.data.rel.ro
                0x0000000000000500        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 .rela.data.rel.local
                0x0000000000000500       0x30 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
 *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
 *(.rela.ctors)
 *(.rela.dtors)
 *(.rela.got)
 .rela.got      0x0000000000000530       0x78 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
 .rela.bss      0x00000000000005a8        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 *(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*)
 *(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*)
 *(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*)
 *(.rela.ifunc)
 .rela.ifunc    0x00000000000005a8        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 .rela.fini_array
                0x00000000000005a8       0x18 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 .rela.init_array
                0x00000000000005c0       0x18 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o

.rela.plt       0x00000000000005d8       0xa8
 *(.rela.plt)
 .rela.plt      0x00000000000005d8       0xa8 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
                [!provide]                        PROVIDE (__rela_iplt_start = .)
 *(.rela.iplt)
                [!provide]                        PROVIDE (__rela_iplt_end = .)

.init           0x0000000000000680       0x17
 *(SORT_NONE(.init))
 .init          0x0000000000000680       0x12 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o
                0x0000000000000680                _init
 .init          0x0000000000000692        0x5 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o

.plt            0x00000000000006a0       0x80
 *(.plt)
 .plt           0x00000000000006a0       0x80 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 *(.iplt)

.plt.got        0x0000000000000720        0x8
 *(.plt.got)
 .plt.got       0x0000000000000720        0x8 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o

.plt.sec
 *(.plt.sec)

.text           0x0000000000000730      0x4c2
 *(.text.unlikely .text.*_unlikely .text.unlikely.*)
 *(.text.exit .text.exit.*)
 *(.text.startup .text.startup.*)
 *(.text.hot .text.hot.*)
 *(.text .stub .text.* .gnu.linkonce.t.*)
 .text          0x0000000000000730       0x2b /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
                0x0000000000000730                _start
 .text          0x000000000000075b        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o
 *fill*         0x000000000000075b        0x5 
 .text          0x0000000000000760       0xda /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
 .text          0x000000000000083a      0x289 /tmp/ccYQAtfU.o
                0x000000000000083a                main
 .text          0x0000000000000ac3       0xa9 /tmp/ccetcq5K.o
                0x0000000000000ac3                sub
                0x0000000000000b00                add
                0x0000000000000b4d                math
 .text          0x0000000000000b6c        0xe /tmp/ccYNVa0B.o
                0x0000000000000b6c                dummy_ver0
 *fill*         0x0000000000000b7a        0x6 
 .text          0x0000000000000b80       0x72 /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS)
                0x0000000000000b80                __libc_csu_init
                0x0000000000000bf0                __libc_csu_fini
 .text          0x0000000000000bf2        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o
 .text          0x0000000000000bf2        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o
 *(.gnu.warning)

.fini           0x0000000000000bf4        0x9
 *(SORT_NONE(.fini))
 .fini          0x0000000000000bf4        0x4 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o
                0x0000000000000bf4                _fini
 .fini          0x0000000000000bf8        0x5 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o
                [!provide]                        PROVIDE (__etext = .)
                [!provide]                        PROVIDE (_etext = .)
                [!provide]                        PROVIDE (etext = .)

.rodata         0x0000000000000c00      0x152
 *(.rodata .rodata.* .gnu.linkonce.r.*)
 .rodata.cst4   0x0000000000000c00        0x4 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
                0x0000000000000c00                _IO_stdin_used
 *fill*         0x0000000000000c04        0x4 
 .rodata        0x0000000000000c08      0x14a /tmp/ccYQAtfU.o

.rodata1
 *(.rodata1)

.eh_frame_hdr   0x0000000000000d54       0x5c
 *(.eh_frame_hdr)
 .eh_frame_hdr  0x0000000000000d54       0x5c /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
                0x0000000000000d54                __GNU_EH_FRAME_HDR
 *(.eh_frame_entry .eh_frame_entry.*)

.eh_frame       0x0000000000000db0      0x188
 *(.eh_frame)
 .eh_frame      0x0000000000000db0       0x30 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
                                         0x2c (size before relaxing)
 *fill*         0x0000000000000de0        0x0 
 .eh_frame      0x0000000000000de0       0x40 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 .eh_frame      0x0000000000000e20       0x18 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
                                         0x30 (size before relaxing)
 .eh_frame      0x0000000000000e38       0x20 /tmp/ccYQAtfU.o
                                         0x38 (size before relaxing)
 .eh_frame      0x0000000000000e58       0x60 /tmp/ccetcq5K.o
                                         0x78 (size before relaxing)
 .eh_frame      0x0000000000000eb8       0x20 /tmp/ccYNVa0B.o
                                         0x38 (size before relaxing)
 .eh_frame      0x0000000000000ed8       0x5c /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS)
                                         0x78 (size before relaxing)
 .eh_frame      0x0000000000000f34        0x4 /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o
 *(.eh_frame.*)

.gcc_except_table
 *(.gcc_except_table .gcc_except_table.*)

.gnu_extab
 *(.gnu_extab*)

.exception_ranges
 *(.exception_ranges .exception_ranges*)
                0x0000000000201d88                . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE))

.eh_frame
 *(.eh_frame)
 *(.eh_frame.*)

.gnu_extab
 *(.gnu_extab)

.gcc_except_table
 *(.gcc_except_table .gcc_except_table.*)

.exception_ranges
 *(.exception_ranges .exception_ranges*)

.tdata
 *(.tdata .tdata.* .gnu.linkonce.td.*)

.tbss
 *(.tbss .tbss.* .gnu.linkonce.tb.*)
 *(.tcommon)

.preinit_array  0x0000000000201d88        0x0
                [!provide]                        PROVIDE (__preinit_array_start = .)
 *(.preinit_array)
                [!provide]                        PROVIDE (__preinit_array_end = .)

.init_array     0x0000000000201d88        0x8
                0x0000000000201d88                PROVIDE (__init_array_start = .)
 *(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))
 *(.init_array EXCLUDE_FILE(*crtend?.o *crtend.o *crtbegin?.o *crtbegin.o) .ctors)
 .init_array    0x0000000000201d88        0x8 /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
                0x0000000000201d90                PROVIDE (__init_array_end = .)

.fini_array     0x0000000000201d90        0x8
                [!provide]                        PROVIDE (__fini_array_start = .)
 *(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))
 *(.fini_array EXCLUDE_FILE(*crtend?.o *crtend.o *crtbegin?.o *crtbegin.o) .dtors)
 .fini_array    0x0000000000201d90        0x8 /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
                [!provide]                        PROVIDE (__fini_array_end = .)

.ctors
 *crtbegin.o(.ctors)
 *crtbegin?.o(.ctors)
 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
 *(SORT_BY_NAME(.ctors.*))
 *(.ctors)

.dtors
 *crtbegin.o(.dtors)
 *crtbegin?.o(.dtors)
 *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
 *(SORT_BY_NAME(.dtors.*))
 *(.dtors)

.jcr
 *(.jcr)

.data.rel.ro    0x0000000000201d98        0x0
 *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*)
 *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*)
 .data.rel.ro   0x0000000000201d98        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o

.dynamic        0x0000000000201d98      0x1f0
 *(.dynamic)
 .dynamic       0x0000000000201d98      0x1f0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
                0x0000000000201d98                _DYNAMIC

.got            0x0000000000201f88       0x78
 *(.got.plt)
 .got.plt       0x0000000000201f88       0x50 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
                0x0000000000201f88                _GLOBAL_OFFSET_TABLE_
 *(.igot.plt)
 *(.got)
 .got           0x0000000000201fd8       0x28 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 *(.igot)
                0x0000000000202000                . = DATA_SEGMENT_RELRO_END (., 0x0)

.data           0x0000000000202000       0x2c
 *(.data .data.* .gnu.linkonce.d.*)
 .data          0x0000000000202000        0x4 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
                0x0000000000202000                data_start
                0x0000000000202000                __data_start
 .data          0x0000000000202004        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o
 .data          0x0000000000202004        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
 *fill*         0x0000000000202004        0x4 
 .data.rel.local
                0x0000000000202008        0x8 /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
                0x0000000000202008                __dso_handle
 .data          0x0000000000202010       0x10 /tmp/ccYQAtfU.o
                0x0000000000202010                array
                0x0000000000202018                doubletest
 .data.rel.local
                0x0000000000202020        0x8 /tmp/ccYQAtfU.o
                0x0000000000202020                Hello
 .data          0x0000000000202028        0x4 /tmp/ccetcq5K.o
                0x0000000000202028                Min
 .data          0x000000000020202c        0x0 /tmp/ccYNVa0B.o
 .data          0x000000000020202c        0x0 /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS)
 .data          0x000000000020202c        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o
 .data          0x000000000020202c        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o

.tm_clone_table
                0x0000000000202030        0x0
 .tm_clone_table
                0x0000000000202030        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
 .tm_clone_table
                0x0000000000202030        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o

.data1
 *(.data1)
                0x0000000000202030                _edata = .
                [!provide]                        PROVIDE (edata = .)
                0x0000000000202030                . = .
                0x0000000000202030                __bss_start = .

.bss            0x0000000000202030       0x30
 *(.dynbss)
 .dynbss        0x0000000000202030        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 *(.bss .bss.* .gnu.linkonce.b.*)
 .bss           0x0000000000202030        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 .bss           0x0000000000202030        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o
 .bss           0x0000000000202030        0x1 /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
 *fill*         0x0000000000202031        0x7 
 .bss           0x0000000000202038        0xc /tmp/ccYQAtfU.o
                0x0000000000202038                testP
 .bss           0x0000000000202044        0x0 /tmp/ccetcq5K.o
 .bss           0x0000000000202044        0x0 /tmp/ccYNVa0B.o
 .bss           0x0000000000202044        0x0 /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS)
 .bss           0x0000000000202044        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o
 .bss           0x0000000000202044        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o
 *(COMMON)
 *fill*         0x0000000000202044        0x4 
 COMMON         0x0000000000202048       0x12 /tmp/ccYQAtfU.o
                0x0000000000202048                pInt
                0x0000000000202050                g_gloableInt
                0x0000000000202054                array0
                0x0000000000202060                . = ALIGN ((. != 0x0)?0x8:0x1)
 *fill*         0x000000000020205a        0x6 

.lbss
 *(.dynlbss)
 *(.lbss .lbss.* .gnu.linkonce.lb.*)
 *(LARGE_COMMON)
                0x0000000000202060                . = ALIGN (0x8)
                0x0000000000202060                . = SEGMENT_START ("ldata-segment", .)

.lrodata
 *(.lrodata .lrodata.* .gnu.linkonce.lr.*)

.ldata          0x0000000000602060        0x0
 *(.ldata .ldata.* .gnu.linkonce.l.*)
                0x0000000000602060                . = ALIGN ((. != 0x0)?0x8:0x1)
                0x0000000000602060                . = ALIGN (0x8)
                0x0000000000602060                _end = .
                [!provide]                        PROVIDE (end = .)
                0x0000000000602060                . = DATA_SEGMENT_END (.)

.stab
 *(.stab)

.stabstr
 *(.stabstr)

.stab.excl
 *(.stab.excl)

.stab.exclstr
 *(.stab.exclstr)

.stab.index
 *(.stab.index)

.stab.indexstr
 *(.stab.indexstr)

.comment        0x0000000000000000       0x29
 *(.comment)
 .comment       0x0000000000000000       0x29 /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
                                         0x2a (size before relaxing)
 .comment       0x0000000000000029       0x2a /tmp/ccYQAtfU.o
 .comment       0x0000000000000029       0x2a /tmp/ccetcq5K.o
 .comment       0x0000000000000029       0x2a /tmp/ccYNVa0B.o
 .comment       0x0000000000000029       0x2a /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o

.debug
 *(.debug)

.line
 *(.line)

.debug_srcinfo
 *(.debug_srcinfo)

.debug_sfnames
 *(.debug_sfnames)

.debug_aranges
 *(.debug_aranges)

.debug_pubnames
 *(.debug_pubnames)

.debug_info
 *(.debug_info .gnu.linkonce.wi.*)

.debug_abbrev
 *(.debug_abbrev)

.debug_line
 *(.debug_line .debug_line.* .debug_line_end)

.debug_frame
 *(.debug_frame)

.debug_str
 *(.debug_str)

.debug_loc
 *(.debug_loc)

.debug_macinfo
 *(.debug_macinfo)

.debug_weaknames
 *(.debug_weaknames)

.debug_funcnames
 *(.debug_funcnames)

.debug_typenames
 *(.debug_typenames)

.debug_varnames
 *(.debug_varnames)

.debug_pubtypes
 *(.debug_pubtypes)

.debug_ranges
 *(.debug_ranges)

.debug_macro
 *(.debug_macro)

.debug_addr
 *(.debug_addr)

.gnu.attributes
 *(.gnu.attributes)

/DISCARD/
 *(.note.GNU-stack)
 *(.gnu_debuglink)
 *(.gnu.lto_*)
OUTPUT(main elf64-x86-64)

2.对比C 程序,读map 文件

tmp/testC$ ./main
sum is 1
main=000055854636e83a,math=000055854636eb4d,add=000055854636eb00,sub=000055854636eac3
g_gloableInt=0000558546570050 staticInt=0000558546570040 Hello=000055854636ec08
sizeof(doubletest)=8 sizeof(testP)=8 sizeof(array0)=6 
&doubletest=0000558546570018,testP=0000000000000000 array0=0000558546570054

1)首先是included archive file

Archive member included to satisfy reference by file (symbol) ==>included archive

/usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS)
                              /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o (__libc_csu_init)

解析:

> Scrt1.o 这个目标文件会调用到__libc_csu_init 这个函数

> __libc_csu_init 这个函数在elf-init.oS 目标文件中

> elf-init.oS 目标文件 被打包在libc_nonshared.a 这个archive file

2)然后是library included

As-needed library included to satisfy reference by file (symbol)  ==>link 的lib

libc.so.6                     /tmp/ccYQAtfU.o (fopen@@GLIBC_2.2.5)

解析:

> /tmp/ccYQAtfU.o(实际是main.0) 这个目标文件会调用到fopen 这个函数

> fopen这个函数在libc.so.6 这个lib 中

3)然后是common symbols

Allocating common symbols
Common symbol       size              file

pInt                0x8               /tmp/ccYQAtfU.o
g_gloableInt        0x4               /tmp/ccYQAtfU.o
array0              0x6               /tmp/ccYQAtfU.o

解析:

> /tmp/ccYQAtfU.o(实际是main.0)

> 上述3个变量都是main.c 文件中定义的全局变量,并且没有初始化

> 上述3个全局变量,可以被任何module 访问到,使用并且改变

> 实际写程序中,可以通过common symbols 列出的变量,来检查是否有必要写全局变量,如没有必要,则改成static.

4)Discarded input sections

Discarded input sections

 .note.GNU-stack
                0x0000000000000000        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 .note.GNU-stack
                0x0000000000000000        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o
 .note.GNU-stack
                0x0000000000000000        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
 .note.GNU-stack
                0x0000000000000000        0x0 /tmp/ccYQAtfU.o ==>实际是main.o
 .note.GNU-stack
                0x0000000000000000        0x0 /tmp/ccetcq5K.o ==>实际是add.o
 .note.GNU-stack
                0x0000000000000000        0x0 /tmp/ccYNVa0B.o ==>实际是dummy.o
 .note.GNU-stack
                0x0000000000000000        0x0 /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS)
 .note.GNU-stack
                0x0000000000000000        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o
 .note.GNU-stack
                0x0000000000000000        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o

解析:

> 原本以为测试程序dummy.c 这个文件中的function 没有被引用,只会把dummy.o 放在discarded input sections

> 实际测试结果,add.o (所有function和变量都被引用)也被放在了这里,有些不理解

5)Memory Configuration

Memory Configuration

Name             Origin             Length             Attributes
*default*        0x0000000000000000 0xffffffffffffffff

解析:

> 因为我是在linux pc 上编译,因此这部分没有特殊的memory 限制

6)Linker script and memory map

LOAD /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
LOAD /tmp/ccYQAtfU.o
LOAD /tmp/ccetcq5K.o
LOAD /tmp/ccYNVa0B.o
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/libgcc.a
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/libgcc_s.so
START GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/libgcc_s.so.1
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/libgcc.a
END GROUP

......

(.text start address is 0x0000000000000730, total size is x4c2)

.text           0x0000000000000730      0x4c2
 *(.text.unlikely .text.*_unlikely .text.unlikely.*)
 *(.text.exit .text.exit.*)
 *(.text.startup .text.startup.*)
 *(.text.hot .text.hot.*)
 *(.text .stub .text.* .gnu.linkonce.t.*)
 .text          0x0000000000000730       0x2b /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
                0x0000000000000730                _start
 .text          0x000000000000075b        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o
 *fill*         0x000000000000075b        0x5 
 .text          0x0000000000000760       0xda /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o

(这里根据函数的调用关系,依次排列函数在memory 中的位置,先执行的先占memory)
 .text          0x000000000000083a      0x289 /tmp/ccYQAtfU.o(main.o)
                0x000000000000083a                main
 .text          0x0000000000000ac3       0xa9 /tmp/ccetcq5K.o(add.o)
                0x0000000000000ac3                sub(0xb00-0xac3=0x3D 表示sub函数占用的memory,不包含函数的data)
                0x0000000000000b00                add
                0x0000000000000b4d                math
 .text          0x0000000000000b6c        0xe /tmp/ccYNVa0B.o(dummy.o)
                0x0000000000000b6c                dummy_ver0
 *fill*         0x0000000000000b7a        0x6 
 .text          0x0000000000000b80       0x72 /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS)
                0x0000000000000b80                __libc_csu_init
                0x0000000000000bf0                __libc_csu_fini
 .text          0x0000000000000bf2        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o
 .text          0x0000000000000bf2        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o
 *(.gnu.warning)

.fini           0x0000000000000bf4        0x9
 *(SORT_NONE(.fini))
 .fini          0x0000000000000bf4        0x4 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o
                0x0000000000000bf4                _fini
 .fini          0x0000000000000bf8        0x5 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o
                [!provide]                        PROVIDE (__etext = .)
                [!provide]                        PROVIDE (_etext = .)
                [!provide]                        PROVIDE (etext = .)

(这里是read only data 区域,比如程序中的“helloWorld”就放在这里)

(这块区域start address 是0x0000000000000c00,total size is 0x152 )

.rodata         0x0000000000000c00      0x152
 *(.rodata .rodata.* .gnu.linkonce.r.*)
 .rodata.cst4   0x0000000000000c00        0x4 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
                0x0000000000000c00                _IO_stdin_used
 *fill*         0x0000000000000c04        0x4 
 .rodata        0x0000000000000c08      0x14a /tmp/ccYQAtfU.o("helloWorld"?)

.rodata1
 *(.rodata1)

.eh_frame_hdr   0x0000000000000d54       0x5c
 *(.eh_frame_hdr)
 .eh_frame_hdr  0x0000000000000d54       0x5c /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
                0x0000000000000d54                __GNU_EH_FRAME_HDR
 *(.eh_frame_entry .eh_frame_entry.*)

.eh_frame       0x0000000000000db0      0x188
 *(.eh_frame)
 .eh_frame      0x0000000000000db0       0x30 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
                                         0x2c (size before relaxing)
 *fill*         0x0000000000000de0        0x0 
 .eh_frame      0x0000000000000de0       0x40 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 .eh_frame      0x0000000000000e20       0x18 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
                                         0x30 (size before relaxing)
 .eh_frame      0x0000000000000e38       0x20 /tmp/ccYQAtfU.o
                                         0x38 (size before relaxing)
 .eh_frame      0x0000000000000e58       0x60 /tmp/ccetcq5K.o
                                         0x78 (size before relaxing)
 .eh_frame      0x0000000000000eb8       0x20 /tmp/ccYNVa0B.o
                                         0x38 (size before relaxing)
 .eh_frame      0x0000000000000ed8       0x5c /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS)
                                         0x78 (size before relaxing)
 .eh_frame      0x0000000000000f34        0x4 /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o
 *(.eh_frame.*)
 

6).data 区域

(start address is 0x0000000000202000,total size is 0x2c)

.data           0x0000000000202000       0x2c
 *(.data .data.* .gnu.linkonce.d.*)
 .data          0x0000000000202000        0x4 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
                0x0000000000202000                data_start
                0x0000000000202000                __data_start
 .data          0x0000000000202004        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o
 .data          0x0000000000202004        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
 *fill*         0x0000000000202004        0x4 
 .data.rel.local
                0x0000000000202008        0x8 /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
                0x0000000000202008                __dso_handle
 .data          0x0000000000202010       0x10 /tmp/ccYQAtfU.o
                0x0000000000202010                array(array 占用8byte,说明pointer 占用8byte,64bit 系统)
                0x0000000000202018                doubletest(double 类型占用8byte)
 .data.rel.local
                0x0000000000202020        0x8 /tmp/ccYQAtfU.o(Hello 字符指针占用8byte)
                0x0000000000202020                Hello
 .data          0x0000000000202028        0x4 /tmp/ccetcq5K.o(int 类型占用4byte)
                0x0000000000202028                Min
 .data          0x000000000020202c        0x0 /tmp/ccYNVa0B.o(没有全局变量,因此size 是0)
 .data          0x000000000020202c        0x0 /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS)
 .data          0x000000000020202c        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o
 .data          0x000000000020202c        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o


解析:

> 初始化的全局变量,会放在这里

> 未初始化的全局变量,不会放在这里

> 如全局变量初始化为0,有的编译器会优化到.bss 。

6).bss 区域

(start address is 0x0000000000202030,total size is 0x30)

.bss            0x0000000000202030       0x30
 *(.dynbss)
 .dynbss        0x0000000000202030        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 *(.bss .bss.* .gnu.linkonce.b.*)
 .bss           0x0000000000202030        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o
 .bss           0x0000000000202030        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o
 .bss           0x0000000000202030        0x1 /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
 *fill*         0x0000000000202031        0x7 
 .bss           0x0000000000202038        0xc /tmp/ccYQAtfU.o(bss 中指针占12byte?No)
                0x0000000000202038                testP
 .bss           0x0000000000202044        0x0 /tmp/ccetcq5K.o
 .bss           0x0000000000202044        0x0 /tmp/ccYNVa0B.o
 .bss           0x0000000000202044        0x0 /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS)
 .bss           0x0000000000202044        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o
 .bss           0x0000000000202044        0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o
 *(COMMON)
 *fill*         0x0000000000202044        0x4 
 COMMON         0x0000000000202048       0x12 /tmp/ccYQAtfU.o
                0x0000000000202048                pInt(此处指针占8byte)
                0x0000000000202050                g_gloableInt(int 占4byte)
                0x0000000000202054                array0(占6byte=0x12-0x8-0x4)(正好对应其定义:char array0[6];)
                0x0000000000202060                . = ALIGN ((. != 0x0)?0x8:0x1)
 *fill*         0x000000000020205a        0x6 

.lbss
 *(.dynlbss)
 *(.lbss .lbss.* .gnu.linkonce.lb.*)
 *(LARGE_COMMON)
                0x0000000000202060                . = ALIGN (0x8)
                0x0000000000202060                . = SEGMENT_START ("ldata-segment", .)

.lrodata
 *(.lrodata .lrodata.* .gnu.linkonce.lr.*)

.ldata          0x0000000000602060        0x0
 *(.ldata .ldata.* .gnu.linkonce.l.*)
                0x0000000000602060                . = ALIGN ((. != 0x0)?0x8:0x1)
                0x0000000000602060                . = ALIGN (0x8)
                0x0000000000602060                _end = .
                [!provide]                        PROVIDE (end = .)
                0x0000000000602060                . = DATA_SEGMENT_END (.)

解析:

> 定义的未初始化全局变量放在bss 区域

6)_end

_end 可以体现main 可执行程序最终占用的memory 是 0x 2060 byte?

7)程序执行期间打印地址,以确认上述解读是否正确

$ ./main
sum is 1
main=000055854636e83a,math=000055854636eb4d,add=000055854636eb00,sub=000055854636eac3
g_gloableInt=0000558546570050 staticInt=0000558546570040 Hello=000055854636ec08
sizeof(doubletest)=8 sizeof(testP)=8 sizeof(array0)=6 
&doubletest=0000558546570018,testP=0000000000000000 array0=0000558546570054

解析:

> 程序执行期间打印的是虚拟地址

> 全局函数address 与map 文件一致(低12bit 相同)

> 未初始化全局变量 address 与map 文件一致(低8byte 相同)

> 初始化全局变量 address 与map 文件一致(低8byte 相同)

> Hello 指向的是存放“HelloWorld”的address 0x000055854636ec08,对应到map 文件的这里

 .rodata        0x0000000000000c08      0x14a /tmp/ccYQAtfU.o

基于以上分析,map 文件可以很准确反应程序的memory 使用情况。

8).comment

它存放的是编译器版本等信息。

9)总结

程序放在.text

常量字符串放在.rodata

全局初始化变量放在.data

全局未初始化变量放在.bss

static 函数,不体现在map 文件

static 全局变量(初始化/不初始化)都不体现在map 文件,located in .data

malloc 分配的memory 不在map 文件体现,实际在heap


可执行程序由.text / .data /.bss 3部分组成。

.text 和 .data 都存在可执行文件中,由系统从可执行文件中加载,.bss 不在可执行文件中,由系统初始化。

10).data 与.bss 的区别

初始化全局变量,放在data 区 char array[1024*1024]={0,1,2,3};

 .data          0x0000000000202020   0x100008 /tmp/ccuT7WjH.o
                0x0000000000202020                array

编译后的exe size 为

testC$ ls -al main -rwxrwxr-x 1 xa00000 xa00000 1061920 May 11 16:57 main


未初始化全局变量,放在bss 区 char array[1024*1024];

.bss            0x0000000000202040   0x100050

......
 *(COMMON)
 *fill*         0x0000000000202058        0x8 
 COMMON         0x0000000000202060   0x10002a /tmp/ccKlvAPJ.o
                0x0000000000202060                malloc_ptr
                0x0000000000202068                pInt
                0x0000000000202080                array
                0x0000000000302080                g_gloableInt
                0x0000000000302084                array0

testC$ ls -al main -rwxrwxr-x 1 xa00000 xa00000 13328 May 11 17:02 main

1061920 - 13328=1048592 byte

结论:.bss size 不占用文件空间,只占用运行时的内存空间。

11)static 变量

main.c static int tmpdata = 100; static int tmpdata_uni = 100; static void test_fun() { printf("test!"); } void main(void) { int a = 5,b = 6,sum=0; static int staticInt = 0; char data[READ_SIZE]={0}; int ret = 0; FILE* fp = fopen("abuf_apu_nbsm_o1_1_00720.mpg","r"); //FILE* fp_out = fopen("abuf_apu_nbsm_o1_1_00720_out.mpg","w+"); FILE* fp_out = fopen("abuf_apu_nbsm_o1_1_00720_out.mpg","w+"); static int tmpdata_2= 10; static int tmpdata_2_uni= 10; ...... }

testC$ objdump -t main main: file format elf64-x86-64 SYMBOL TABLE: 0000000000000238 l d .interp 0000000000000000 .interp 0000000000000254 l d .note.ABI-tag 0000000000000000 .note.ABI-tag 0000000000000274 l d .note.gnu.build-id 0000000000000000 .note.gnu.build-id 0000000000000298 l d .gnu.hash 0000000000000000 .gnu.hash 00000000000002b8 l d .dynsym 0000000000000000 .dynsym 0000000000000420 l d .dynstr 0000000000000000 .dynstr 00000000000004ec l d .gnu.version 0000000000000000 .gnu.version 0000000000000510 l d .gnu.version_r 0000000000000000 .gnu.version_r 0000000000000540 l d .rela.dyn 0000000000000000 .rela.dyn 0000000000000618 l d .rela.plt 0000000000000000 .rela.plt 00000000000006f0 l d .init 0000000000000000 .init 0000000000000710 l d .plt 0000000000000000 .plt 00000000000007b0 l d .plt.got 0000000000000000 .plt.got 00000000000007c0 l d .text 0000000000000000 .text 0000000000000d04 l d .fini 0000000000000000 .fini 0000000000000d10 l d .rodata 0000000000000000 .rodata 0000000000000e84 l d .eh_frame_hdr 0000000000000000 .eh_frame_hdr 0000000000000ee8 l d .eh_frame 0000000000000000 .eh_frame 0000000000201d78 l d .init_array 0000000000000000 .init_array 0000000000201d80 l d .fini_array 0000000000000000 .fini_array 0000000000201d88 l d .dynamic 0000000000000000 .dynamic 0000000000201f78 l d .got 0000000000000000 .got 0000000000202000 l d .data 0000000000000000 .data 0000000000202040 l d .bss 0000000000000000 .bss 0000000000000000 l d .comment 0000000000000000 .comment 0000000000000000 l df *ABS* 0000000000000000 crtstuff.c 00000000000007f0 l F .text 0000000000000000 deregister_tm_clones 0000000000000830 l F .text 0000000000000000 register_tm_clones 0000000000000880 l F .text 0000000000000000 __do_global_dtors_aux 0000000000202040 l O .bss 0000000000000001 completed.7698 0000000000201d80 l O .fini_array 0000000000000000 __do_global_dtors_aux_fini_array_entry 00000000000008c0 l F .text 0000000000000000 frame_dummy 0000000000201d78 l O .init_array 0000000000000000 __frame_dummy_init_array_entry 0000000000000000 l df *ABS* 0000000000000000 main.c 0000000000202018 l O .data 0000000000000004 tmpdata 000000000020201c l O .data 0000000000000004 tmpdata_uni 00000000000008ca l F .text 0000000000000018 test_fun 0000000000202050 l O .bss 0000000000000004 staticInt.2347 0000000000202020 l O .data 0000000000000004 tmpdata_2_uni.2353 0000000000202024 l O .data 0000000000000004 tmpdata_2.2352 0000000000000000 l df *ABS* 0000000000000000 add.c 0000000000000000 l df *ABS* 0000000000000000 dummy.c 0000000000000000 l df *ABS* 0000000000000000 crtstuff.c 000000000000108c l O .eh_frame 0000000000000000 __FRAME_END__ 0000000000000000 l df *ABS* 0000000000000000 0000000000201d80 l .init_array 0000000000000000 __init_array_end 0000000000201d88 l O .dynamic 0000000000000000 _DYNAMIC 0000000000201d78 l .init_array 0000000000000000 __init_array_start 0000000000000e84 l .eh_frame_hdr 0000000000000000 __GNU_EH_FRAME_HDR 0000000000201f78 l O .got 0000000000000000 _GLOBAL_OFFSET_TABLE_ 0000000000000d00 g F .text 0000000000000002 __libc_csu_fini 0000000000000000 F *UND* 0000000000000000 free@@GLIBC_2.2.5 0000000000202060 g O .bss 0000000000000008 malloc_ptr 0000000000202068 g O .bss 0000000000000008 pInt 0000000000000000 w *UND* 0000000000000000 _ITM_deregisterTMCloneTable 0000000000202000 w .data 0000000000000000 data_start 0000000000000c10 g F .text 000000000000004d add 0000000000000000 F *UND* 0000000000000000 fread@@GLIBC_2.2.5 0000000000202080 g O .bss 0000000000100000 array 0000000000302080 g O .bss 0000000000000004 g_gloableInt 0000000000202034 g .data 0000000000000000 _edata 0000000000202030 g O .data 0000000000000004 Min 0000000000000000 F *UND* 0000000000000000 fclose@@GLIBC_2.2.5 0000000000000d04 g F .fini 0000000000000000 _fini 0000000000000000 F *UND* 0000000000000000 __stack_chk_fail@@GLIBC_2.4 0000000000000000 F *UND* 0000000000000000 printf@@GLIBC_2.2.5 0000000000000c7c g F .text 000000000000000e dummy_ver0 0000000000000000 F *UND* 0000000000000000 __libc_start_main@@GLIBC_2.2.5 0000000000202000 g .data 0000000000000000 __data_start 0000000000000000 w *UND* 0000000000000000 __gmon_start__ 0000000000202008 g O .data 0000000000000000 .hidden __dso_handle 0000000000000d10 g O .rodata 0000000000000004 _IO_stdin_used 0000000000202028 g O .data 0000000000000008 Hello 0000000000000c90 g F .text 0000000000000065 __libc_csu_init 0000000000000000 F *UND* 0000000000000000 malloc@@GLIBC_2.2.5 0000000000302084 g O .bss 0000000000000006 array0 0000000000302090 g .bss 0000000000000000 _end 00000000000007c0 g F .text 000000000000002b _start 0000000000000000 F *UND* 0000000000000000 fseek@@GLIBC_2.2.5 0000000000202034 g .bss 0000000000000000 __bss_start 00000000000008e2 g F .text 00000000000002f1 main 0000000000000000 F *UND* 0000000000000000 fopen@@GLIBC_2.2.5 0000000000202010 g O .data 0000000000000008 doubletest 0000000000000c5d g F .text 000000000000001f math 0000000000202048 g O .bss 0000000000000008 testP 0000000000000000 F *UND* 0000000000000000 fwrite@@GLIBC_2.2.5 0000000000202038 g O .data 0000000000000000 .hidden __TMC_END__ 0000000000000000 w *UND* 0000000000000000 _ITM_registerTMCloneTable 0000000000000bd3 g F .text 000000000000003d sub 0000000000000000 w F *UND* 0000000000000000 __cxa_finalize@@GLIBC_2.2.5 00000000000006f0 g F .init 0000000000000000 _init

 objdump -t main


0000000000202018 l     O .data  0000000000000004              tmpdata
000000000020201c l     O .data  0000000000000004              tmpdata_uni
00000000000008ca l     F .text  0000000000000018              test_fun
0000000000202050 l     O .bss   0000000000000004              staticInt.2347
0000000000202020 l     O .data  0000000000000004              tmpdata_2_uni.2353
0000000000202024 l     O .data  0000000000000004              tmpdata_2.2352

conclusion:

static gloable (initialed or not-initialed) vars are located in .data

static non-gloable (initialed or not-initialed) vars are located in .data