public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Oddity in the linker code on AIX
@ 2005-04-19 21:29 Eric Botcazou
  2005-04-20  3:35 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Botcazou @ 2005-04-19 21:29 UTC (permalink / raw)
  To: binutils

Hi,

We're toying a bit with Binutils on AIX and I stumbled on the following 
construct in coff_compute_section_file_positions:

#ifdef ALIGN_SECTIONS_IN_FILE
      if ((abfd->flags & EXEC_P) != 0)
	{
	  /* Make sure this section is aligned on the right boundary - by
	     padding the previous section up if necessary.  */

	  old_sofar = sofar;
#ifdef RS6000COFF_C
	  /* AIX loader checks the text section alignment of (vma - filepos)
	     So even though the filepos may be aligned wrt the o_algntext, for
	     AIX executables, this check fails. This shows up when a native
	     AIX executable is stripped with gnu strip because the default vma
	     of native is 0x10000150 but default for gnu is 0x10000140.  Gnu
	     stripped gnu excutable passes this check because the filepos is
	     0x0140.  This problem also show up with 64 bit shared objects. The
	     data section must also be aligned.  */
	  if (!strcmp (current->name, _TEXT)
	      || !strcmp (current->name, _DATA))
	    {
	      bfd_vma pad;
	      bfd_vma align;

	      sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);

	      align = 1 << current->alignment_power;
	      pad = abs (current->vma - sofar) % align;

	      if (pad)
		{
		  pad = align - pad;
		  sofar += pad;
		}
	    }
	  else
#else
	    {
	      sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
	    }
#endif
	  if (previous != (asection *) NULL)
	    previous->size += sofar - old_sofar;
	}

#endif


Note the mix between preprocessor conditional and C conditional constructs.  
As a result, the code eventually compiled on AIX is:

      if ((abfd->flags & EXEC_P) != 0)
	{
	  /* Make sure this section is aligned on the right boundary - by
	     padding the previous section up if necessary.  */

	  old_sofar = sofar;

	  /* AIX loader checks the text section alignment of (vma - filepos)
	     So even though the filepos may be aligned wrt the o_algntext, for
	     AIX executables, this check fails. This shows up when a native
	     AIX executable is stripped with gnu strip because the default vma
	     of native is 0x10000150 but default for gnu is 0x10000140.  Gnu
	     stripped gnu excutable passes this check because the filepos is
	     0x0140.  This problem also show up with 64 bit shared objects. The
	     data section must also be aligned.  */
	  if (!strcmp (current->name, _TEXT)
	      || !strcmp (current->name, _DATA))
	    {
	      bfd_vma pad;
	      bfd_vma align;

	      sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);

	      align = 1 << current->alignment_power;
	      pad = abs (current->vma - sofar) % align;

	      if (pad)
		{
		  pad = align - pad;
		  sofar += pad;
		}
	    }
	  else

	  if (previous != (asection *) NULL)
	    previous->size += sofar - old_sofar;
	}

which looks a little suspicious to me.


Am I right in thinking that the author got a bit confused here?

Thanks in advance.

-- 
Eric Botcazou

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

* Re: Oddity in the linker code on AIX
  2005-04-19 21:29 Oddity in the linker code on AIX Eric Botcazou
@ 2005-04-20  3:35 ` Ian Lance Taylor
  2005-04-20 10:00   ` Eric Botcazou
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2005-04-20  3:35 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: binutils

Eric Botcazou <ebotcazou@adacore.com> writes:

> #ifdef ALIGN_SECTIONS_IN_FILE
>       if ((abfd->flags & EXEC_P) != 0)
> 	{
> 	  /* Make sure this section is aligned on the right boundary - by
> 	     padding the previous section up if necessary.  */
> 
> 	  old_sofar = sofar;
> #ifdef RS6000COFF_C
> 	  /* AIX loader checks the text section alignment of (vma - filepos)
> 	     So even though the filepos may be aligned wrt the o_algntext, for
> 	     AIX executables, this check fails. This shows up when a native
> 	     AIX executable is stripped with gnu strip because the default vma
> 	     of native is 0x10000150 but default for gnu is 0x10000140.  Gnu
> 	     stripped gnu excutable passes this check because the filepos is
> 	     0x0140.  This problem also show up with 64 bit shared objects. The
> 	     data section must also be aligned.  */
> 	  if (!strcmp (current->name, _TEXT)
> 	      || !strcmp (current->name, _DATA))
> 	    {
> 	      bfd_vma pad;
> 	      bfd_vma align;
> 
> 	      sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
> 
> 	      align = 1 << current->alignment_power;
> 	      pad = abs (current->vma - sofar) % align;
> 
> 	      if (pad)
> 		{
> 		  pad = align - pad;
> 		  sofar += pad;
> 		}
> 	    }
> 	  else
> #else
> 	    {
> 	      sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
> 	    }
> #endif

It's pretty clear from looking at the original patch introducing this
code:

2001-12-20  Tom Rix  <trix@redhat.com>

	* coffcode.h (coff_compute_section_file_positions): Add special AIX
	loader alignment of text section.

that the #else above should be a #endif, and the #endif should be
removed.

Ian

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

* Re: Oddity in the linker code on AIX
  2005-04-20  3:35 ` Ian Lance Taylor
@ 2005-04-20 10:00   ` Eric Botcazou
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Botcazou @ 2005-04-20 10:00 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: binutils

> It's pretty clear from looking at the original patch introducing this
> code:
>
> 2001-12-20  Tom Rix  <trix@redhat.com>
>
> 	* coffcode.h (coff_compute_section_file_positions): Add special AIX
> 	loader alignment of text section.
>
> that the #else above should be a #endif, and the #endif should be
> removed.

OK, thank you for confirming.  I'm not sure mainline builds on AIX for the 
time being so I may need a little time to post a patch.

-- 
Eric Botcazou

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

end of thread, other threads:[~2005-04-20 10:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-19 21:29 Oddity in the linker code on AIX Eric Botcazou
2005-04-20  3:35 ` Ian Lance Taylor
2005-04-20 10:00   ` Eric Botcazou

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).