This is the mail archive of the
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
>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
which in turn is called from
Hope that gives you the idea?
My current output is as follow:
For the code below
.comm _xxx, 4
If .bss and .common follows .data and data ends (say at 0x0008)
then the address allocated by linker are wrong(i guess)
Idx Name Size VMA LMA File off Algn Flags
0 .text 00000000 00000000 00000000 00000000 2**2 ALLOC, LOAD,
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.
From: Ian Lance Taylor [mailto:email@example.com]
Sent: Tuesday, February 10, 2004 8:15 PM
To: Vineet Sharma, Noida
Subject: Re: reloc against common symbols
"Vineet Sharma, Noida" <firstname.lastname@example.org> 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
> (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;
> relocation = symbol->value +
> symbol->section->output_section->vma +
> 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
> Now for the common symbol "symbol->value" does not contain the offset of
> symbol in the section, rather it contains the lenght of the common
> its say .comm _x,120) "symbol->value" contians 120(the lenght of the
> symbol).Thus i am not able to calculate the final address of the common
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
> The above method get_symbol_value() does not work for common symbols.Whats
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.