LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-31-2006, 02:35 AM   #1
ravi
LQ Newbie
 
Registered: Jan 2006
Location: CHENNAI
Distribution: RH9(2.4.20-8)
Posts: 13

Rep: Reputation: 0
getting the virtual address of the .data segment


hi,

i am trying to obtain the virtual address of the .data segment of a user program from my shared library, dynamically(i.e. after program load), using the program headers. i am trying to use the program headers as the section headers are dropped after resolving all the symbols and addresses during program load. but the problem is that many different sections of the file are mapped into one single segment (see below attached file displaying the output of readelf command). i need the exact segff of the .data segment(in general any segment). is there any way to extract this information "DYNAMICALLY"(may not be from program headers but any generic way). also the program headers use flags(PT_LOAD,PF_r,PF_W,PF_X,...) to indicate the type and nature of the segment. but when i tried to use this information in my code to identify the various segments it did not work. can anyone help? i got my reference from ELF ABI.


ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0x8048348
Start of program headers: 52 (bytes into file)
Start of section headers: 7908 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 6
Size of section headers: 40 (bytes)
Number of section headers: 35
Section header string table index: 32

Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 080480f4 0000f4 000013 00 A 0 0 1
[ 2] .note.ABI-tag NOTE 08048108 000108 000020 00 A 0 0 4
[ 3] .hash HASH 08048128 000128 000038 04 A 4 0 4
[ 4] .dynsym DYNSYM 08048160 000160 000090 10 A 5 1 4
[ 5] .dynstr STRTAB 080481f0 0001f0 000063 00 A 0 0 1
[ 6] .gnu.version VERSYM 08048254 000254 000012 02 A 4 0 2
[ 7] .gnu.version_r VERNEED 08048268 000268 000020 00 A 5 1 4
[ 8] .rel.dyn REL 08048288 000288 000008 08 A 4 0 4
[ 9] .rel.plt REL 08048290 000290 000030 08 A 4 11 4
[10] .init PROGBITS 080482c0 0002c0 000017 00 AX 0 0 4
[11] .plt PROGBITS 080482d8 0002d8 000070 04 AX 0 0 4
[12] .text PROGBITS 08048348 000348 0001d8 00 AX 0 0 4
[13] .fini PROGBITS 08048520 000520 00001b 00 AX 0 0 4
[14] .rodata PROGBITS 08048540 000540 000080 00 A 0 0 32
[15] .eh_frame PROGBITS 080485c0 0005c0 000004 00 A 0 0 4
[16] .ctors PROGBITS 080495c4 0005c4 000008 00 WA 0 0 4
[17] .dtors PROGBITS 080495cc 0005cc 000008 00 WA 0 0 4
[18] .jcr PROGBITS 080495d4 0005d4 000004 00 WA 0 0 4
[19] .dynamic DYNAMIC 080495d8 0005d8 0000c8 08 WA 5 0 4
[20] .got PROGBITS 080496a0 0006a0 000004 04 WA 0 0 4
[21] .got.plt PROGBITS 080496a4 0006a4 000024 04 WA 0 0 4
[22] .data PROGBITS 080496c8 0006c8 00000c 00 WA 0 0 4
[23] .bss NOBITS 080496d4 0006d4 000004 00 WA 0 0 4
[24] .comment PROGBITS 00000000 0006d4 000132 00 0 0 1
[25] .debug_aranges PROGBITS 00000000 000808 000078 00 0 0 8
[26] .debug_pubnames PROGBITS 00000000 000880 000025 00 0 0 1
[27] .debug_info PROGBITS 00000000 0008a5 000a84 00 0 0 1
[28] .debug_abbrev PROGBITS 00000000 001329 000138 00 0 0 1
[29] .debug_line PROGBITS 00000000 001461 00027c 00 0 0 1
[30] .debug_frame PROGBITS 00000000 0016e0 000014 00 0 0 4
[31] .debug_str PROGBITS 00000000 0016f4 0006ba 01 MS 0 0 1
[32] .shstrtab STRTAB 00000000 001dae 000134 00 0 0 1
[33] .symtab SYMTAB 00000000 00245c 000710 10 34 85 4
[34] .strtab STRTAB 00000000 002b6c 000432 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)

There are no section groups in this file.

Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000034 0x08048034 0x08048034 0x000c0 0x000c0 R E 0x4
INTERP 0x0000f4 0x080480f4 0x080480f4 0x00013 0x00013 R 0x1
[Requesting program interpreter: /lib/ld-linux.so.2]
LOAD 0x000000 0x08048000 0x08048000 0x005c4 0x005c4 R E 0x1000
LOAD 0x0005c4 0x080495c4 0x080495c4 0x00110 0x00114 RW 0x1000
DYNAMIC 0x0005d8 0x080495d8 0x080495d8 0x000c8 0x000c8 RW 0x4
NOTE 0x000108 0x08048108 0x08048108 0x00020 0x00020 R 0x4

Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .note.ABI-tag .hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame
03 .ctors .dtors .jcr .dynamic .got .got.plt .data .bss
04 .dynamic
05 .note.ABI-tag

Dynamic section at offset 0x5d8 contains 20 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libc.so.6]
0x0000000c (INIT) 0x80482c0
0x0000000d (FINI) 0x8048520
0x00000004 (HASH) 0x8048128
0x00000005 (STRTAB) 0x80481f0
0x00000006 (SYMTAB) 0x8048160
0x0000000a (STRSZ) 99 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000015 (DEBUG) 0x0
0x00000003 (PLTGOT) 0x80496a4
0x00000002 (PLTRELSZ) 48 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x8048290
0x00000011 (REL) 0x8048288
0x00000012 (RELSZ) 8 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x6ffffffe (VERNEED) 0x8048268
0x6fffffff (VERNEEDNUM) 1
0x6ffffff0 (VERSYM) 0x8048254
0x00000000 (NULL) 0x0

Relocation section '.rel.dyn' at offset 0x288 contains 1 entries:
Offset Info Type Sym.Value Sym. Name
080496a0 00000806 R_386_GLOB_DAT 00000000 __gmon_start__

Relocation section '.rel.plt' at offset 0x290 contains 6 entries:
Offset Info Type Sym.Value Sym. Name
080496b0 00000107 R_386_JUMP_SLOT 00000000 fork
080496b4 00000207 R_386_JUMP_SLOT 00000000 execlp
080496b8 00000307 R_386_JUMP_SLOT 00000000 sleep
080496bc 00000407 R_386_JUMP_SLOT 00000000 __libc_start_main
080496c0 00000507 R_386_JUMP_SLOT 00000000 printf
080496c4 00000607 R_386_JUMP_SLOT 00000000 exit

There are no unwind sections in this file.

Symbol table '.dynsym' contains 9 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 90 FUNC GLOBAL DEFAULT UND fork@GLIBC_2.0 (2)
2: 00000000 287 FUNC GLOBAL DEFAULT UND execlp@GLIBC_2.0 (2)
3: 00000000 513 FUNC GLOBAL DEFAULT UND sleep@GLIBC_2.0 (2)
4: 00000000 251 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 (2)
5: 00000000 57 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.0 (2)
6: 00000000 217 FUNC GLOBAL DEFAULT UND exit@GLIBC_2.0 (2)
7: 08048544 4 OBJECT GLOBAL DEFAULT 14 _IO_stdin_used
8: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__

Symbol table '.symtab' contains 113 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 080480f4 0 SECTION LOCAL DEFAULT 1
2: 08048108 0 SECTION LOCAL DEFAULT 2
3: 08048128 0 SECTION LOCAL DEFAULT 3
4: 08048160 0 SECTION LOCAL DEFAULT 4
5: 080481f0 0 SECTION LOCAL DEFAULT 5
6: 08048254 0 SECTION LOCAL DEFAULT 6
7: 08048268 0 SECTION LOCAL DEFAULT 7
8: 08048288 0 SECTION LOCAL DEFAULT 8
9: 08048290 0 SECTION LOCAL DEFAULT 9
10: 080482c0 0 SECTION LOCAL DEFAULT 10
11: 080482d8 0 SECTION LOCAL DEFAULT 11
12: 08048348 0 SECTION LOCAL DEFAULT 12
13: 08048520 0 SECTION LOCAL DEFAULT 13
14: 08048540 0 SECTION LOCAL DEFAULT 14
15: 080485c0 0 SECTION LOCAL DEFAULT 15
16: 080495c4 0 SECTION LOCAL DEFAULT 16
17: 080495cc 0 SECTION LOCAL DEFAULT 17
18: 080495d4 0 SECTION LOCAL DEFAULT 18
19: 080495d8 0 SECTION LOCAL DEFAULT 19
20: 080496a0 0 SECTION LOCAL DEFAULT 20
21: 080496a4 0 SECTION LOCAL DEFAULT 21
22: 080496c8 0 SECTION LOCAL DEFAULT 22
23: 080496d4 0 SECTION LOCAL DEFAULT 23
24: 00000000 0 SECTION LOCAL DEFAULT 24
25: 00000000 0 SECTION LOCAL DEFAULT 25
26: 00000000 0 SECTION LOCAL DEFAULT 26
27: 00000000 0 SECTION LOCAL DEFAULT 27
28: 00000000 0 SECTION LOCAL DEFAULT 28
29: 00000000 0 SECTION LOCAL DEFAULT 29
30: 00000000 0 SECTION LOCAL DEFAULT 30
31: 00000000 0 SECTION LOCAL DEFAULT 31
32: 00000000 0 SECTION LOCAL DEFAULT 32
33: 00000000 0 SECTION LOCAL DEFAULT 33
34: 00000000 0 SECTION LOCAL DEFAULT 34
35: 00000000 0 FILE LOCAL DEFAULT ABS <command line>
36: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/build/231499-i38
37: 00000000 0 FILE LOCAL DEFAULT ABS <command line>
38: 00000000 0 FILE LOCAL DEFAULT ABS <built-in>
39: 00000000 0 FILE LOCAL DEFAULT ABS abi-note.S
40: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/build/231499-i38
41: 00000000 0 FILE LOCAL DEFAULT ABS abi-note.S
42: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/build/231499-i38
43: 00000000 0 FILE LOCAL DEFAULT ABS abi-note.S
44: 00000000 0 FILE LOCAL DEFAULT ABS <command line>
45: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/build/231499-i38
46: 00000000 0 FILE LOCAL DEFAULT ABS <command line>
47: 00000000 0 FILE LOCAL DEFAULT ABS <built-in>
48: 00000000 0 FILE LOCAL DEFAULT ABS abi-note.S
49: 00000000 0 FILE LOCAL DEFAULT ABS init.c
50: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/build/231499-i38
51: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/build/231499-i38
52: 00000000 0 FILE LOCAL DEFAULT ABS initfini.c
53: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/build/231499-i38
54: 00000000 0 FILE LOCAL DEFAULT ABS <command line>
55: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/build/231499-i38
56: 00000000 0 FILE LOCAL DEFAULT ABS <command line>
57: 00000000 0 FILE LOCAL DEFAULT ABS <built-in>
58: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/build/231499-i38
59: 0804836c 0 FUNC LOCAL DEFAULT 12 call_gmon_start
60: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
61: 080495c4 0 OBJECT LOCAL DEFAULT 16 __CTOR_LIST__
62: 080495cc 0 OBJECT LOCAL DEFAULT 17 __DTOR_LIST__
63: 080485c0 0 OBJECT LOCAL DEFAULT 15 __EH_FRAME_BEGIN__
64: 080495d4 0 OBJECT LOCAL DEFAULT 18 __JCR_LIST__
65: 080496d0 0 OBJECT LOCAL DEFAULT 22 p.0
66: 080496d4 1 OBJECT LOCAL DEFAULT 23 completed.1
67: 08048390 0 FUNC LOCAL DEFAULT 12 __do_global_dtors_aux
68: 080483cc 0 FUNC LOCAL DEFAULT 12 frame_dummy
69: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
70: 080495c8 0 OBJECT LOCAL DEFAULT 16 __CTOR_END__
71: 080495d0 0 OBJECT LOCAL DEFAULT 17 __DTOR_END__
72: 080485c0 0 OBJECT LOCAL DEFAULT 15 __FRAME_END__
73: 080495d4 0 OBJECT LOCAL DEFAULT 18 __JCR_END__
74: 080484fc 0 FUNC LOCAL DEFAULT 12 __do_global_ctors_aux
75: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/build/231499-i38
76: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/build/231499-i38
77: 00000000 0 FILE LOCAL DEFAULT ABS initfini.c
78: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/build/231499-i38
79: 00000000 0 FILE LOCAL DEFAULT ABS <command line>
80: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/build/231499-i38
81: 00000000 0 FILE LOCAL DEFAULT ABS <command line>
82: 00000000 0 FILE LOCAL DEFAULT ABS <built-in>
83: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/build/231499-i38
84: 00000000 0 FILE LOCAL DEFAULT ABS aa.c
85: 080495d8 0 OBJECT GLOBAL DEFAULT 19 _DYNAMIC
86: 08048540 4 OBJECT GLOBAL DEFAULT 14 _fp_hw
87: 00000000 90 FUNC GLOBAL DEFAULT UND fork@@GLIBC_2.0
88: 080495c4 0 NOTYPE GLOBAL DEFAULT ABS __fini_array_end
89: 080496cc 0 OBJECT GLOBAL HIDDEN 22 __dso_handle
90: 080484c8 52 FUNC GLOBAL DEFAULT 12 __libc_csu_fini
91: 080482c0 0 FUNC GLOBAL DEFAULT 10 _init
92: 08048348 0 FUNC GLOBAL DEFAULT 12 _start
93: 00000000 287 FUNC GLOBAL DEFAULT UND execlp@@GLIBC_2.0
94: 00000000 513 FUNC GLOBAL DEFAULT UND sleep@@GLIBC_2.0
95: 080495c4 0 NOTYPE GLOBAL DEFAULT ABS __fini_array_start
96: 08048498 48 FUNC GLOBAL DEFAULT 12 __libc_csu_init
97: 080496d4 0 NOTYPE GLOBAL DEFAULT ABS __bss_start
98: 080483f8 159 FUNC GLOBAL DEFAULT 12 main
99: 00000000 251 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_
100: 080495c4 0 NOTYPE GLOBAL DEFAULT ABS __init_array_end
101: 080496c8 0 NOTYPE WEAK DEFAULT 22 data_start
102: 00000000 57 FUNC GLOBAL DEFAULT UND printf@@GLIBC_2.0
103: 08048520 0 FUNC GLOBAL DEFAULT 13 _fini
104: 00000000 217 FUNC GLOBAL DEFAULT UND exit@@GLIBC_2.0
105: 080496d4 0 NOTYPE GLOBAL DEFAULT ABS _edata
106: 080496a4 0 OBJECT GLOBAL HIDDEN 21 _GLOBAL_OFFSET_TABLE_
107: 080496d8 0 NOTYPE GLOBAL DEFAULT ABS _end
108: 080495c4 0 NOTYPE GLOBAL DEFAULT ABS __init_array_start
109: 08048544 4 OBJECT GLOBAL DEFAULT 14 _IO_stdin_used
110: 080496c8 0 NOTYPE GLOBAL DEFAULT 22 __data_start
111: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses
112: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__

Histogram for bucket list length (total of 3 buckets):
Length Number % of total Coverage
0 0 ( 0.0%)
1 0 ( 0.0%) 0.0%
2 2 ( 66.7%) 50.0%
3 0 ( 0.0%) 50.0%
4 1 ( 33.3%) 100.0%

Version symbols section '.gnu.version' contains 9 entries:
Addr: 0000000008048254 Offset: 0x000254 Link: 4 (.dynsym)
000: 0 (*local*) 2 (GLIBC_2.0) 2 (GLIBC_2.0) 2 (GLIBC_2.0)
004: 2 (GLIBC_2.0) 2 (GLIBC_2.0) 2 (GLIBC_2.0) 1 (*global*)
008: 0 (*local*)

Version needs section '.gnu.version_r' contains 1 entries:
Addr: 0x0000000008048268 Offset: 0x000268 Link to section: 5 (.dynstr)
000000: Version: 1 File: libc.so.6 Cnt: 1
0x0010: Name: GLIBC_2.0 Flags: none Version: 2

Notes at offset 0x00000108 with length 0x00000020:
Owner Data size Description
GNU 0x00000010 NT_VERSION (version)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
API for mapping Physical Address to Virtual Address Lakshman_smt Linux - Software 2 10-15-2006 10:08 PM
virtual IP address? gruessle Linux - Software 0 12-14-2005 01:13 AM
Increasing virtual address space mhl Linux - Newbie 1 09-07-2005 11:29 AM
Virtual network address silver2003 Linux - Networking 2 05-31-2004 02:39 PM
Network Browsing and Virtual IP address jarmstrong Linux - Networking 5 02-17-2003 09:09 AM


All times are GMT -5. The time now is 08:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration