This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
RE: reloc against common symbols
- From: "Vineet Sharma, Noida" <vineets at noida dot hcltech dot com>
- To: Ian Lance Taylor <ian at wasabisystems dot com>
- Cc: binutils at sources dot redhat dot com
- Date: Wed, 11 Feb 2004 17:37:38 +0530
- Subject: RE: reloc against common symbols
Hi,
>It's hard to say without more information. What is the backtrace when
>coff_XXX_reloc() is called? There are several possible paths to that
>point, and I'm not sure which you are using.
It is called from
bfd_perform_relocation()
which in turn is called from
bfd_generic_get_relocated_section_contents()
Hope that gives you the idea?
My current output is as follow:
For the code below
_y:
.short _x+0
.short _xx+0
.short _xxx+0
.global _z
.align 1
_z:
.short 1
.comm _xxx, 4
.comm _xx,5
.comm _x,6
If .bss and .common follows .data and data ends (say at 0x0008)
then the address allocated by linker are wrong(i guess)
Sections:
Idx Name Size VMA LMA File off Algn Flags
0 .text 00000000 00000000 00000000 00000000 2**2 ALLOC, LOAD,
CODE
1 .data 00000008 00000000 00000000 000000a8 2**2 CONTENTS,
ALLOC, LOAD, DATA
2 .bss 00000011 00000008 00000008 00000000 2**2 ALLOC
So the address allocated for
_x is 0x000c
_xx is 0x0014
_xxx is 0x0008
Dont you thinks some thing wrong in this _xx being declared first(before _x)
should start at lower address
than that of (_x).
The allocated symbols should have been set by the generic linker code to
hold the allocated address.
So i guess my code is not interfering with the genric part.
Regards
Vineet
-----Original Message-----
From: Ian Lance Taylor [mailto:ian@wasabisystems.com]
Sent: Tuesday, February 10, 2004 8:15 PM
To: Vineet Sharma, Noida
Cc: binutils@sources.redhat.com
Subject: Re: reloc against common symbols
"Vineet Sharma, Noida" <vineets@noida.hcltech.com> writes:
> Actually i have ported binutils to new target (a 16 bit proceessor).
> The problem is with
> linker(although same holds true for assembler) .Lets talk about linker
> particularly coff_XXX_reloc()
>
> Now when i need to fix a relocation against a common symbol(in function
> coff_XXX_reloc())
> (Refer example below ".short _x+28" _x is common symbol)
> I use the follwing method to calculate the value of the final symbol
> value/address in coff_XXX_reloc()
>
> static long
> get_symbol_value (symbol)
> asymbol *symbol;
> {
> long relocation = 0;
>
>
> if (bfd_is_com_section (symbol->section))
> relocation = 0;
> else
> relocation = symbol->value +
> symbol->section->output_section->vma +
> symbol->section->output_offset;
>
>
> return relocation;
> }
> Now for a normal symbol(non-common symbol) "symbol->value" contains the
> offset of the symbol in the section.
> Every thing works fine.And the function returns the final address of the
> symbol.Good..
>
>
> Now for the common symbol "symbol->value" does not contain the offset of
the
> symbol in the section, rather it contains the lenght of the common
symbol(if
> its say .comm _x,120) "symbol->value" contians 120(the lenght of the
common
> symbol).Thus i am not able to calculate the final address of the common
> symbol.
When the linker calls coff_XXX_reloc(), presumably via
bfd_generic_get_relocated_section_contents(), there should be no
symbol for which bfd_is_com_section (symbol->section) is true. All
the symbols should have been allocated into real sections by
lang_common(). The allocated symbols should have been set by the
generic linker code to hold the allocated address.
> >What is the actual problem?
>
> How to calculate the final address of the common symbol in
coff_XXX_reloc()?
>
> The above method get_symbol_value() does not work for common symbols.Whats
> wrong?
It's hard to say without more information. What is the backtrace when
coff_XXX_reloc() is called? There are several possible paths to that
point, and I'm not sure which you are using.
Ian