reloc against common symbols

Vineet Sharma, Noida vineets@noida.hcltech.com
Tue Feb 10 11:56:00 GMT 2004


>What program are we talking about here?  The assembler or the linker?
>What target?  How precisely are you invoking the tool? 

	First of all i am not reporting a bug. It's just a problem which i
am not able to resolve yet.

	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.

>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 is not a bug for the assembler to call a coff_XXX_reloc() routine
>with a common symbol.  That will happen when the coff_XXX_reloc()
>routine appears as a special_function in a howto structure, and is
>called by bfd_install_relocation().

Yes this problem may not be a bug.
Yes i have defined my own special_function in howto structure for handling
the relocations. 
And i am relying on the parameters passed to my function coff_XXX_reloc()
for calculating
the symbol address.


With Regards
Vineet






-----Original Message-----
From: Ian Lance Taylor [mailto:ian@wasabisystems.com]
Sent: Monday, February 09, 2004 6:41 PM
To: Vineet Sharma, Noida
Cc: binutils@sources.redhat.com
Subject: Re: reloc against common symbols


"Vineet Sharma, Noida" <vineets@noida.hcltech.com> writes:

>      Let me put my question in another way.
> 	
> 	Consider
>  
>  	 __y:		 .short  _x+28 //Reloc generated here
>        		 .global _z
>        		 .align  1
> 	_z:
>        		 .short  1
>         		.comm _x,120  //Symbol in Question
> 
>      Now when the coff_XXX_reloc() is called in coff-XXX.c, there the
> "struct symbol" passed as an argument does not
>      contain the address of the symbol(in this case _x) in the "value"
> attribute of struct symbol.It contains the length(ie 	120) in this case.
> 		   While it is supposed to contain the address of the _x
> symbol.

What program are we talking about here?  The assembler or the linker?
What target?  How precisely are you invoking the tool?  What is the
actual problem?

The linker will normally not pass common symbols to the relocation
functions, because they will normally have been allocated and
defined.

It is not a bug for the assembler to call a coff_XXX_reloc() routine
with a common symbol.  That will happen when the coff_XXX_reloc()
routine appears as a special_function in a howto structure, and is
called by bfd_install_relocation().  Relocation handling in BFD is a
mess; see bfd/doc/bfdint.texi for more information.

Ian



More information about the Binutils mailing list