This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
the problem : assign the section's order in shared library based on mipsplatform
- From: eagle_zhou at ali dot com dot tw
- To: binutils at sources dot redhat dot com
- Date: Thu, 11 Nov 2004 12:11:36 +0800
- Subject: the problem : assign the section's order in shared library based on mipsplatform
I want to take out the continuous part i care(only include
.text/.data/.bss/..) from the shared library,
and discard the those part i don't care ( dynsym/dynstr/dynamic/hash/...).
So i use the -T [ldscriptfile] option to assign the order of shared
library:
$ mips-elf-gcc -g -EL -fPIC -mabicalls -c demo.c
$ mips-t2-elf-ld -shared -T test.ld -o demo.so demo.o
$ readelf -a demo.so >demo.elf
$ mips-elf-objdump -D demo.so >demo.dis
the content of file demo.c is:
void demo_main()
{
external_func();
}
the content of file test.ld is:
OUTPUT_FORMAT("elf32-littlemips")
SECTIONS{
.text : {*(.text) *(.text.*) *(.rodata)}
. = ALIGN(4);
.sdata : {*(.sdata) *(.sdata.*)}
. = ALIGN(4);
.data : {*(.data) *(.data.*) *(.rodata) }
. = ALIGN(4);
.sbss : {*(.sbss) *(.scommon)}
. = ALIGN(4);
.bss : { *(.bss) *(COMMON)}
. = ALIGN(4);
.rodata : {*(.rodata) *(.rodata.*)}
. = ALIGN(4);
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
}
the content file demo.elf is:
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: DYN (Shared object file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0x0
Start of program headers: 52 (bytes into file)
Start of section headers: 11388 (bytes into file)
Flags: 0x3, noreorder, pic, mips1
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 4
Size of section headers: 40 (bytes)
Number of section headers: 17
Section header string table index: 14
Section Headers:
[Nr] Name Type Addr Off Size ES Flg
Lk Inf Al
[ 0] NULL 00000000 000000 000000 00
0 0 0
[ 1] .text PROGBITS 00000000 001000 000050 00 AX
0 0 4
[ 2] .stub PROGBITS 00000050 001050 000020 00 AX
0 0 4
[ 3] .data PROGBITS 00000070 001070 000000 00 WA
0 0 1
[ 4] .got PROGBITS 00000070 001070 000020 04 WAp
0 0 16
[ 5] .bss NOBITS 00000090 002090 000000 00 WA
0 0 1
[ 6] .dynsym DYNSYM 00000090 001090 000150 10 A
7 14 16
[ 7] .dynstr STRTAB 000001e0 0021e0 000080 00 A
0 0 16
[ 8] .dynamic DYNAMIC 00000260 002260 0000b0 00 A
7 0 16
[ 9] .hash HASH 00000310 002310 0000a0 00 A
6 0 16
[10] .reginfo MIPS_REGINFO 00000000 0023b0 000018 18
0 0 16
[11] .mdebug MIPS_DEBUG 00000000 0023c8 000774 00
0 0 4
[12] .compact_rel PROGBITS 00000000 002b3c 000018 00
0 0 4
[13] .rtproc PROGBITS 00000000 002b60 0000a0 00
0 0 16
[14] .shstrtab STRTAB 00000000 002c00 00007c 00
0 0 1
[15] .symtab SYMTAB 00000000 002f24 000190 10
16 17 4
[16] .strtab STRTAB 00000000 0030b4 000080 00
0 0 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
above, this is the order what i wished.
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)
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg
Align
LOAD 0x001000 0x00000000 0x00000000 0x001e0 0x01090 RWE
0x1000
LOAD 0x0021e0 0x000001e0 0x000001e0 0x001d0 0x001d0 R
0x1000
DYNAMIC 0x001090 0x00000090 0x00000090 0x00320 0x00320 R
0x10
RTPROC 0x000000 0x00000000 0x00000000 0x00000 0x000a0 R
0x10
Section to Segment mapping:
Segment Sections...
00 .text .stub .got .dynsym .dynstr .dynamic .hash
01 .dynstr .dynamic .hash
02 .dynsym .dynstr .dynamic .hash
03 .text .stub .got
Dynamic section at offset 0x2260 contains 17 entries:
Tag Type Name/Value
0x00000004 (HASH) 0x310
0x00000005 (STRTAB) 0x1e0
0x00000006 (SYMTAB) 0x90
0x0000000a (STRSZ) 128 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000003 (PLTGOT) 0x70
0x7000000b (MIPS_CONFLICTNO) 0
0x70000010 (MIPS_LIBLISTNO) 0
0x70000001 (MIPS_RLD_VERSION) 1
0x70000005 (MIPS_FLAGS) NOTPOT
0x70000006 (MIPS_BASE_ADDRESS) 0
0x7000000a (MIPS_LOCAL_GOTNO) 7
0x70000011 (MIPS_SYMTABNO) 21
0x70000012 (MIPS_UNREFEXTNO) 14
0x70000013 (MIPS_GOTSYM) 0x14
0x70000014 (MIPS_HIPAGENO) 5
0x00000000 (NULL) 0x0
There are no relocations in this file.
There are no unwind sections in this file.
Symbol table '.dynsym' contains 21 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 SECTION LOCAL DEFAULT 13
1: 00000000 0 SECTION LOCAL DEFAULT 1
2: 00000050 0 SECTION LOCAL DEFAULT 2
3: 00000070 0 SECTION LOCAL DEFAULT 3
4: 00000070 0 SECTION LOCAL DEFAULT 4
5: 00000090 0 SECTION LOCAL DEFAULT 5
6: 00000090 0 SECTION LOCAL DEFAULT 6
7: 000001e0 0 SECTION LOCAL DEFAULT 7
8: 00000260 0 SECTION LOCAL DEFAULT 8
9: 00000310 0 SECTION LOCAL DEFAULT 9
10: 00000000 0 SECTION LOCAL DEFAULT 10
11: 00000000 0 SECTION LOCAL DEFAULT 11
12: 00000000 0 SECTION LOCAL DEFAULT 12
13: 00000000 0 SECTION GLOBAL DEFAULT ABS _gp_disp
14: 00000260 0 OBJECT GLOBAL DEFAULT ABS _DYNAMIC
15: 00000003 0 SECTION GLOBAL PROTECTED ABS
_procedure_table_size
16: 00000000 0 SECTION GLOBAL PROTECTED PRC[0xff02]
_procedure_string_table
17: 00000000 80 FUNC GLOBAL DEFAULT PRC[0xff01] demo_main
18: 00000070 0 OBJECT GLOBAL DEFAULT ABS
_GLOBAL_OFFSET_TABLE_
19: 00000000 0 SECTION GLOBAL PROTECTED PRC[0xff02]
_procedure_table
20: 00000050 0 FUNC GLOBAL DEFAULT UND external_func
~~~~~~~~~ ~~~~~~~~~~~~~~
Symbol table '.symtab' contains 25 entries:
...
Histogram for bucket list length (total of 17 buckets):
...
No version information found in this file.
the content file demo.dis is:
demo.so: file format elf32-littlemips
Disassembly of section .text:
00000000 <.text>:
0: 3c1c0000 lui gp,0x0
4: 279c0000 addiu gp,gp,0
8: 0399e021 addu gp,gp,t9
c: 27bdffd8 addiu sp,sp,-40
10: afbc0010 sw gp,16(sp)
14: afbf0020 sw ra,32(sp)
18: afbe001c sw s8,28(sp)
1c: afbc0018 sw gp,24(sp)
20: 03a0f021 move s8,sp
24: 8f99008c lw t9,140(gp)
~~~~~~~~~~
28: 00000000 nop
2c: 0320f809 jalr t9
30: 00000000 nop
34: 8fdc0010 lw gp,16(s8)
38: 03c0e821 move sp,s8
3c: 8fbf0020 lw ra,32(sp)
40: 8fbe001c lw s8,28(sp)
44: 27bd0028 addiu sp,sp,40
48: 03e00008 jr ra
4c: 00000000 nop
Disassembly of section .stub:
00000050 <.stub>:
50: 8f998010 lw t9,-32752(gp)
~~~~~~~~~~~~~
54: 03e07825 move t7,ra
58: 0320f809 jalr t9
5c: 34180014 li t8,0x14
...
Disassembly of section .data:
Disassembly of section .got:
00000070 <.got>:
70: 00000000 nop
74: 80000000 lb zero,0(zero)
...
8c: 00000050 0x50
~~~~~~~~~~~~~~~~~~~~~~~~~~
Disassembly of section .dynsym:
...
...
==========================================================================================
my question is:
i think the correct flow of demo_main() calling external_func() is:
calling external_func()--> got[7] --> stub --> got[0] -->
_dl_runtime_resolve --> modify got[7]
but the execute flow is:
(i) 24: 8f99008c lw t9,140(gp)
<==> lw t9, 0(0x8C) // t9=got[7]
(ii) got[7]==0x50, so jal to 0x50 // jmp to stub
(iii) 50: 8f998010 lw t9,-32752(gp) // t9=got[0]
where it point to ??
the address of got[0] is 0x70 , not -32752 ?
(1) Is there some error in my "test.ld" file ? or is this a small bug ?
if i do not use -T option, it will work ok.
(2) I think the shared library is too big.
My aim is only to take out my interested part(.text and .data) from
shared library.
and i must put these part into the continuous space.
how can i do it ?
welcome everybody's suggestion !