| « November 2009 |
| Mon | Tue | Wed | Thu | Fri | Sat | Sun |
|---|
| | | | | | | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | | | | | | |
| Today |
Blog::Navigation
Site notes
Technorati

Monday June 11, 2007
using mapfiles to lay program segments out.
If you were writing an application from scratch and wanted to make sure
your program segments were aligned for large pages you could compile it
with a mapfile like this..
cc -M
mapfile -o test1 test1.c
where map file looks like ..
data = A0x400000;
text = A0x400000;
bss = A0x400000;
and test1 looks like
#include
<sys/types.h>
#include <stdio.h>
#include <unistd.h>
const char *foo[1024] = {"hello"};
int
main( int argc, char *argv[]) {
pause();
}
so how can we check what went where..
./test1 &
[1] 98
pmap -xs 98
98: ./test1
Address
Kbytes
RSS Anon Locked Pgsz
Mode Mapped File
00400000
8
8
-
- 8K r-x-- test1
00800000
16
16
8
- 8K rwx-- test1
00C00000
8
8
8
- 8K rwx-- [ heap ]
C4080000
224
224
-
- 8K r-x-- libc.so.1
....
so
we have
read only text and readonly data in a segment at 00400000
and the read/write data at 00800000 and the bss segment starting
at 00c00000 just as we wanted.
the const char * declation for foo ensures that the storage for "hello"
is in the read only section with the text and the pointer is in the
read/write data segment.
or
nm -fx test1 |
egrep "bss|text|data"
[38] |0x00c00000|0x00000000|OBJT |LOCL
|0
|18 |Bbss.bss
[34] |0x00c00000|0x00000000|NOTY |LOCL
|0
|18 |Bbss.bss
[39] |0x008010b8|0x00000000|OBJT |LOCL
|0
|17 |Ddata.data
[35] |0x00801088|0x00000000|NOTY |LOCL
|0
|17 |Ddata.data
[40] |0x00400ed4|0x00000000|OBJT |LOCL
|0
|13 |Drodata.rodata
[36] |0x00400ed4|0x00000000|NOTY |LOCL
|0
|13 |Drodata.rodata
[55] |0x00c00000|0x00000000|OBJT |GLOB
|0
|17 |_edata
[63] |0x00400ede|0x00000000|OBJT |GLOB
|0
|14 |_etext
so we can see the text and read only rodata in first segment, data in
the next and bss in the next.
so now if I run test1 under ppgsize thus
1299 ppgsz -o heap=4m,anon=4m,stack=4m ./test1
1300
./test1
enoexec ksh: pmap -xs 1300
1300: ./test1
Address
Kbytes
RSS Anon Locked Pgsz
Mode Mapped File
00400000
8
8
-
- 8K r-x-- test1
00800000
16
16
8
- 8K rwx-- test1
00C00000
4096 4096
4096
- 4M rwx-- [ heap ]
C4080000
224
224
-
- 8K r-x-- libc.so.1
C40B8000
32
32
-
- - r-x-- libc.so.1
a 4m heap for all of the heap, now we just need to get the text and
data into 4m pages or try and get the rodata section into its
own segment.