This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: some question about output section
hi:
2011/4/28 Alan Modra <amodra@gmail.com>:
> On Wed, Apr 27, 2011 at 11:29:13PM +0800, loody wrote:
>> Dear all:
>> I have some questions as below:
>> 1. Is it possible to put whole .text of a static library to one output section?
>> 2. Is it possible to put whole sections of a static library to one
>> output section?
>> 3. is it possible for some file B to get address of some function in
>> A, while linking?
>> 4. usually the address of a static lib is not determined until link
>> stage. Is it possible we can pre-defined the address of each function
>> in a static lib?
>
> Yes, yes, yes and yes. ?As to how you can do this, see ld info doc
> node "Input Section Basics" for the answer to (1) and (2). ?For (3)
> and (4) you're going to need to compile with -ffunction-sections then
> write scripts to put the functions where you want them. ?An
> alternative to (4) is to build a jump table at a fixed address then
> define the function entry points on the jump table entries.
>
after studying the ld info, I make a link script as below:
OUTPUT_ARCH(mips)
ENTRY(entry)
SECTIONS
{
.begin 0xbfb00000 :
{
*(.begin)
. = ALIGN(8);
_end_begin = ABSOLUTE(.);
}
.onlyText 0x80000000 : AT(_end_begin)
{
lib1.a ( *.text )
}
.wholelib 0x81000000 :
{
lib2.a (*)
}
.text : { *(EXCLUDE_FILE (*.a ) .text)}
.data : { *(EXCLUDE_FILE (*.a ) .data) }
}
and I link the files by following command.
mipsel-linux-gnu-ld -T ./link.xn -o TEST_LINK.elf -Map TEST_LINK.map
--oformat elf32-tradlittlemips lib1.a lib2.a main.o ut.o
But I cannot see the section I used to link lib1.a and lib2.a
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: MIPS R3000
Version: 0x1
Entry point address: 0xbfb00000
Start of program headers: 52 (bytes into file)
Start of section headers: 2936 (bytes into file)
Flags: 0x70001001, noreorder, o32, mips32r2
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 1
Size of section headers: 40 (bytes)
Number of section headers: 20
Section header string table index: 17
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .begin PROGBITS bfb00000 000054 000058 00 AX 0 0 4
[ 2] .text PROGBITS bfb00058 0000ac 0002bc 00 AX 0 0 4
[ 3] .rodata.str1.4 PROGBITS bfb00314 000368 000014 01 AMS 0 0 4
[ 4] .data PROGBITS bfb00328 00037c 000014 00 WA 0 0 4
[ 5] .bss NOBITS bfb0033c 000390 000004 00 WA 0 0 4
[ 6] .reginfo MIPS_REGINFO 00000000 000390 000018 18 0 0 4
[ 7] .pdr PROGBITS 00000000 0003a8 0000a0 00 0 0 4
[ 8] .mdebug.abi32 PROGBITS 00000000 000448 000000 00 0 0 1
[ 9] .debug_abbrev MIPS_DWARF 00000000 000448 0000fa 00 0 0 1
[10] .debug_info MIPS_DWARF 00000000 000542 0001b8 00 0 0 1
[11] .debug_line MIPS_DWARF 00000000 0006fa 0000bf 00 0 0 1
[12] .debug_frame MIPS_DWARF 00000000 0007bc 000080 00 0 0 4
[13] .debug_pubnames MIPS_DWARF 00000000 00083c 000083 00 0 0 1
[14] .debug_aranges MIPS_DWARF 00000000 0008bf 000048 00 0 0 1
[15] .debug_str MIPS_DWARF 00000000 000907 000154 01 MS 0 0 1
[16] .comment PROGBITS 00000000 000a5b 000056 00 0 0 1
[17] .shstrtab STRTAB 00000000 000ab1 0000c4 00 0 0 1
[18] .symtab SYMTAB 00000000 000e98 0001e0 10 19 24 4
[19] .strtab STRTAB 00000000 001078 00007a 00 0 0 1
Did I miss anything?
--
Regards,
miloody