This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bug(?) in ppc relocations


Hi,

Look at the following code from elf32-ppc.c

	/* relocate against _SDA_BASE_ */
	case (int)R_PPC_SDAREL16:
	  {
	    const char *name;

	    BFD_ASSERT (sec != (asection *)0);
	    name = bfd_get_section_name (abfd, sec->output_section);
	    if (strcmp (name, ".sdata") != 0
		&& strcmp (name, ".sbss") != 0)
	      {
		(*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in
the wrong output section (%s)"),
				       bfd_get_filename (input_bfd),
				       sym_name,
				       ppc_elf_howto_table[ (int)r_type ]->name,
				       name);
	      }
	    addend -= (sdata->sym_hash->root.u.def.value
		       + sdata->sym_hash->root.u.def.section->output_section->vma
		       + sdata->sym_hash->root.u.def.section->output_offset);
                      
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	  }                                   |
	  break;                              |
                              This looks somewhat suspicious.
sdata->sym_hash is the _SDA_BASE_ symbol and its value,
as far as I can understand, should not be affected by output_offset,
right ?
Consider the following scenario:
 1. The linker creates a linker section .sdata and _SDA_BASE_ with
offset 32768
 2. The linker outputs to the output .sdata some input .sdata
 3. The linker appends the linker .sdata to output .sdata
Now data items in the first .sdata are at offset < -32768 relative to 
_SDA_BASE_ and the linker exits with relocation overflow error.

If the above analisys is correct one can think of (at least) two
options:
  (a) make sure the linker section is output first, or
  (b) remove the underlined line above.

Tell me, guys, what do you think and I'll submit a patch.

Regards,
-velco

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]