public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* relaxing vs section merging
@ 2004-04-26 19:54 DJ Delorie
  2004-04-27  2:35 ` Alan Modra
  0 siblings, 1 reply; 6+ messages in thread
From: DJ Delorie @ 2004-04-26 19:54 UTC (permalink / raw)
  To: binutils


target = mn10300-elf
host = linux

Consider linking these two files with "ld --relax":

-------------------- dj1.s
	.section .text
	.global _start
	.type	_start,@function
_start:
	mov	.LC1a,d1
	nop

	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1a:
	.string	"\n"
-------------------- dj2.s
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2a:
	.rept	32768
	.byte	'a'
	.endr
	.byte	0
.LC2b:
	.string	"abc\n"
--------------------

What I'm seeing is that the relaxation code uses the pre-merge value
of LC1a, but the relocation uses the post-merge value and thus fails
(reloc overflow).  I've verified that merging happens before relaxing.

Why this happens is uncertain.  Various things I've seen:

* The section for LC1a is set to *ABS* by ldlang.c, because the merge
  code decided it was to be discarded.

* If I try to map LC1a through _bfd_elf_rela_local_sym, at first it
  doesn't because only STT_SECTION symbols are allowed to be mapped.

* If I override the STT_SECTION check, it complains that the symbol is
  outside the merged section (*ABS*, remember?)

* If I try to keep the section from being discarded (so it's not
  *ABS*), it still complains as above.

So far, the only "solution" I've found is to just not relax relocs to
symbols in mergable sections, but this obviously isn't ideal.  Am I
missing something obvious?  Is there some fundamental bug that needs
to be fix here, and if so, where?  Or should we just skip mergable
symbols?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: relaxing vs section merging
  2004-04-26 19:54 relaxing vs section merging DJ Delorie
@ 2004-04-27  2:35 ` Alan Modra
  2004-04-27  2:47   ` DJ Delorie
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Modra @ 2004-04-27  2:35 UTC (permalink / raw)
  To: DJ Delorie; +Cc: binutils

On Mon, Apr 26, 2004 at 03:45:19PM -0400, DJ Delorie wrote:
> What I'm seeing is that the relaxation code uses the pre-merge value
> of LC1a, but the relocation uses the post-merge value and thus fails
> (reloc overflow).  I've verified that merging happens before relaxing.

I would guess that the mn10300 symbol reading code needs to look like
that in elflink.c:elf_link_input_bfd.  I don't see
_bfd_merged_section_offset being called anywhere in elf-m10300.c.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: relaxing vs section merging
  2004-04-27  2:35 ` Alan Modra
@ 2004-04-27  2:47   ` DJ Delorie
  2004-04-27  3:39     ` Alan Modra
  0 siblings, 1 reply; 6+ messages in thread
From: DJ Delorie @ 2004-04-27  2:47 UTC (permalink / raw)
  To: amodra; +Cc: binutils


> I would guess that the mn10300 symbol reading code needs to look like
> that in elflink.c:elf_link_input_bfd.  I don't see
> _bfd_merged_section_offset being called anywhere in elf-m10300.c.

Yeah, I added calls to _bfd_merged_section_offset (the mn10300
relocation code calls it indirectly).  That's when all the other
problems started happening; I think I mentioned that in my original
email.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: relaxing vs section merging
  2004-04-27  2:47   ` DJ Delorie
@ 2004-04-27  3:39     ` Alan Modra
  2004-04-27 18:03       ` DJ Delorie
  2004-04-27 21:39       ` Dave Korn
  0 siblings, 2 replies; 6+ messages in thread
From: Alan Modra @ 2004-04-27  3:39 UTC (permalink / raw)
  To: DJ Delorie; +Cc: binutils

On Mon, Apr 26, 2004 at 10:47:14PM -0400, DJ Delorie wrote:
> 
> > I would guess that the mn10300 symbol reading code needs to look like
> > that in elflink.c:elf_link_input_bfd.  I don't see
> > _bfd_merged_section_offset being called anywhere in elf-m10300.c.
> 
> Yeah, I added calls to _bfd_merged_section_offset (the mn10300
> relocation code calls it indirectly).  That's when all the other
> problems started happening; I think I mentioned that in my original
> email.

Well, you mentioned _bfd_elf_rela_local_sym, but that's not what I
meant.   I'm talking about code in elf-m10300.c that does

	  isym = isymbuf + ELF32_R_SYM (irel->r_info);
	  if (isym->st_shndx == SHN_UNDEF)
	    sym_sec = bfd_und_section_ptr;
	  else if (isym->st_shndx == SHN_ABS)
	    sym_sec = bfd_abs_section_ptr;
	  else if (isym->st_shndx == SHN_COMMON)
	    sym_sec = bfd_com_section_ptr;
	  else
	    sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);

	  symval = (isym->st_value
		    + sym_sec->output_section->vma
		    + sym_sec->output_offset);

then uses symval.


-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: relaxing vs section merging
  2004-04-27  3:39     ` Alan Modra
@ 2004-04-27 18:03       ` DJ Delorie
  2004-04-27 21:39       ` Dave Korn
  1 sibling, 0 replies; 6+ messages in thread
From: DJ Delorie @ 2004-04-27 18:03 UTC (permalink / raw)
  To: amodra; +Cc: binutils


> Well, you mentioned _bfd_elf_rela_local_sym, but that's not what I
> meant.   I'm talking about code in elf-m10300.c that does

That was one of the places I added a hook to look up the merged
section info.  It didn't work, for the reasons I outlined previously.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: relaxing vs section merging
  2004-04-27  3:39     ` Alan Modra
  2004-04-27 18:03       ` DJ Delorie
@ 2004-04-27 21:39       ` Dave Korn
  1 sibling, 0 replies; 6+ messages in thread
From: Dave Korn @ 2004-04-27 21:39 UTC (permalink / raw)
  To: binutils

> -----Original Message-----
> From: binutils-owner On Behalf Of Alan Modra
> Sent: 27 April 2004 04:28
> To: DJ Delorie

> On Mon, Apr 26, 2004 at 10:47:14PM -0400, DJ Delorie wrote:
> > 
> > Yeah, I added calls to _bfd_merged_section_offset (the mn10300
> > relocation code calls it indirectly).  That's when all the other
> > problems started happening; I think I mentioned that in my original
> > email.
> 
> Well, you mentioned _bfd_elf_rela_local_sym, but that's not what I
> meant.   I'm talking about code in elf-m10300.c that does
> 
> 	  isym = isymbuf + ELF32_R_SYM (irel->r_info);
> 	  if (isym->st_shndx == SHN_UNDEF)
> 	    sym_sec = bfd_und_section_ptr;
> 	  else if (isym->st_shndx == SHN_ABS)
> 	    sym_sec = bfd_abs_section_ptr;
> 	  else if (isym->st_shndx == SHN_COMMON)
> 	    sym_sec = bfd_com_section_ptr;
> 	  else
> 	    sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
> 
> 	  symval = (isym->st_value
> 		    + sym_sec->output_section->vma
> 		    + sym_sec->output_offset);
> 
> then uses symval.

  Hmmm.  Aren't you about to run into the discrepancy I stumbled across a
while ago in this clause:

> 	  if (isym->st_shndx == SHN_UNDEF)
> 	    sym_sec = bfd_und_section_ptr;

because SHN_UNDEF = 0, but also absolute relocs in ELF are indicated by
relocs against the absolute symbol, which has a st_shndx value of zero ?

[  See http://sources.redhat.com/ml/binutils/2004-03/msg00107.html and
preceding thread refs for more.  ]



    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-04-27 18:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-26 19:54 relaxing vs section merging DJ Delorie
2004-04-27  2:35 ` Alan Modra
2004-04-27  2:47   ` DJ Delorie
2004-04-27  3:39     ` Alan Modra
2004-04-27 18:03       ` DJ Delorie
2004-04-27 21:39       ` Dave Korn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).