#include<stdio.h>
volatile int data __attribute__((section(".interface")) = 5;
int* dataPtr = (int *) (0x12345678);
int main(void){
printf("%p\n",&dataPtr);
printf("%p\n",dataPtr);
printf("%d\n",*(int *)dataPtr);
printf("%p\n",&data);
return 0;
}
Line printf("%d\n",*(int *)dataPtr);
gives segmentation fault. Pasting relevant snippets from the objdump -x of the application:
snippet of the memory map
architecture: i386:x86-64, flags 0x00000150:
HAS_SYMS, DYNAMIC, D_PAGED
start address 0x0000000000001060
.
.
22 .dynamic 000001f0 0000000000003dc8 0000000000003dc8 00002dc8 2**3
CONTENTS, ALLOC, LOAD, DATA
23 .got 00000048 0000000000003fb8 0000000000003fb8 00002fb8 2**3
CONTENTS, ALLOC, LOAD, DATA
24 .data 00000018 0000000000004000 0000000000004000 00003000 2**3
CONTENTS, ALLOC, LOAD, DATA
25 .bss 00000008 0000000000004018 0000000000004018 00003018 2**0
ALLOC
26 .comment 0000002a 0000000000000000 0000000000000000 0000367c 2**0
CONTENTS, READONLY
27 .ipl1_interface 00000004 0000000012345678 0000000012345678 00003678 2**2
CONTENTS, ALLOC, LOAD, DATA
.
.
SYMBOL TABLE:
.
.
0000000000004010 g O .data 0000000000000008 dataPtr
0000000000001238 g F .fini 0000000000000000 .hidden _fini
0000000000000000 F *UND* 0000000000000000 printf@@GLIBC_2.2.5
0000000000000000 F *UND* 0000000000000000 __libc_start_main@@GLIBC_2.2.5
0000000000004000 g .data 0000000000000000 __data_start
0000000000000000 w *UND* 0000000000000000 __gmon_start__
0000000000004008 g O .data 0000000000000000 .hidden __dso_handle
0000000000002000 g O .rodata 0000000000000004 _IO_stdin_used
0000000012345678 g O .ipl1_interface 0000000000000004 data
In GDB this works fine:p *(int *)dataPtr;
. The data
symbol is in the symbol table and its address is 0x12345678. Can you provide an insight into what might be going on?