This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
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