This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
RE: Resolving External References
- From: "Savithri Venkatachalapathy, Noida" <savithriv at noida dot hcltech dot com>
- To: Nick Clifton <nickc at redhat dot com>
- Cc: binutils at sources dot redhat dot com, "Rishabh Gupta, Noida" <rishabhg at noida dot hcltech dot com>, binutils at sourceware dot cygnus dot com, "Naveen Sharma, Noida" <naveens at noida dot hcltech dot com>
- Date: Thu, 27 Mar 2003 11:46:26 +0530
- Subject: RE: Resolving External References
Hello Nick,
These are the details.
* What host are you running on ?
I am running on sparc machine.
* What version of binutils are you using ? What target are the binutils
targeted at, (if it is different from
your host) ?
I am using Algor MIPS cross-compler, release 4.0c ( SDE-MIPS )
* What command line did you use in order to link together a.o and
b.o ?
Source files:
-------------
fun1.c
int myfunc()
{
int x = foo();
}
fun2.c
int x = 15;
int foo()
{
return x;
}
int main()
{
foo();
exit(0);
}
Commands:
---------
gcc -c -EL -fpic -o a.o fun1.c
gcc -c -EL -fpic -o b.o fun2.c
ld -verbose -i -EL -fpic -o mytest.elf -defsym __start=0xbfc00000
-Tmyapp_lnk a.o b.o
Linker script(myapp_lnk):
-------------------------
OUTPUT_FORMAT("elf32-littlemips")
SECTIONS
{
.BOOT 0xbfc00000 : {
a.o
}
.RUN 0x80002000 : {
b.o
}
}
* What address does object show for the reference to foo() from a.o
? What address should it be ?
Executable file:
----------------
mytest.elf: file format elf32-littlemips
Disassembly of section .BOOT:
bfc00000 <myfunc>:
bfc00000: 27bdffe0 addiu $sp,$sp,-32
bfc00004: afbf001c sw $ra,28($sp)
bfc00008: afbe0018 sw $s8,24($sp)
bfc0000c: 0c000000 jal b0000000 <x+0x2fffdfa4>
bfc00010: 03a0f025 move $s8,$sp
bfc00014: afc20010 sw $v0,16($s8)
bfc00018: 03c0e825 move $sp,$s8
bfc0001c: 8fbf001c lw $ra,28($sp)
bfc00020: 8fbe0018 lw $s8,24($sp)
bfc00024: 03e00008 jr $ra
bfc00028: 27bd0020 addiu $sp,$sp,32
bfc0002c: e0000004 swc0 $0,4($zero)
...
Disassembly of section .RUN:
80002000 <foo>:
80002000: 27bdfff8 addiu $sp,$sp,-8
80002004: afbe0000 sw $s8,0($sp)
80002008: 03a0f025 move $s8,$sp
8000200c: 8f83806d lw $v1,-32659($gp)
80002010: 00000000 nop
80002014: 10000001 b 8000201c <foo+0x1c>
80002018: 00601025 move $v0,$v1
8000201c: 03c0e825 move $sp,$s8
80002020: 8fbe0000 lw $s8,0($sp)
80002024: 03e00008 jr $ra
80002028: 27bd0008 addiu $sp,$sp,8
8000202c <main>:
8000202c: 27bdffe8 addiu $sp,$sp,-24
80002030: afbf0014 sw $ra,20($sp)
80002034: afbe0010 sw $s8,16($sp)
80002038: 0c000000 jal 80000000 <foo-0x2000>
8000203c: 03a0f025 move $s8,$sp
80002040: 0c000000 jal 80000000 <foo-0x2000>
80002044: 00002025 move $a0,$zero
80002048: 03c0e825 move $sp,$s8
8000204c: 8fbf0014 lw $ra,20($sp)
80002050: 8fbe0010 lw $s8,16($sp)
80002054: 03e00008 jr $ra
80002058: 27bd0018 addiu $sp,$sp,24
8000205c <x>:
8000205c: 0000000f 0xf
The function foo() has been relocated to address 80002000 in the executable
mytest.elf
Hence the reference to foo() from a.o should show the address 80002000.
But it is showing the address b0000000 <x+0x2fffdfa4>.
'x' is a global constant set to 0x0f in the object file b.o and
is relocated in the executable mytest.elf to 8000205c
* Does the linked program work, despite the apparent discrepancy in
addresses ?
No, foo() never gets executed..
* Do you have a *small* example that reproduces the problem ?
Given above :)
Thanks,
savi
-----Original Message-----
From: Nick Clifton [mailto:nickc at redhat dot com]
Sent: Wednesday, March 26, 2003 6:09 PM
To: Savithri Venkatachalapathy, Noida
Cc: binutils at sources dot redhat dot com; Rishabh Gupta, Noida;
binutils at sourceware dot cygnus dot com
Subject: Re: Resolving External References
Hi Savithri,
> I am using "ld" command to link 2 object files a.o and b.o
> a.o has an external reference to function foo() defined in b.o
>
> When I look at the objdump, it has resolved the external reference to
> different address rather than that of foo().
Please could you provide more information about your problem. In
particular:
* What version of binutils are you using ?
* What host are you running on ?
* What target are the binutils targeted at, (if it is different from
your host) ?
* What command line did you use in order to link together a.o and
b.o ?
* What address does object show for the reference to foo() from a.o
? What address should it be ?
* Does the linked program work, despite the apparent discrepancy in
addresses ?
* Do you have a *small* example that reproduces the problem ?
Cheers
Nick