This is the mail archive of the binutils@sources.redhat.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]

[patch] .comm & alignment bug



While I'm work on avr port (ELF) I founded strange thing:

I want to define common variable without alignment, so I wrote:

.comm var,23,1

Is this right ? (IMHO:yes)

After assembling and linking  I have a `var' rounded to 16 :-(

My port is a 8bit micro controller which not needed in rounding at all.

IMHO: bug in elflink.h:elf_link_add_object_symbols

      /* Set the alignment of a common symbol.  */
      if (sym.st_shndx == SHN_COMMON
	  && h->root.type == bfd_link_hash_common)
	{
	  unsigned int align;

>	  align = bfd_log2 (sym.st_value);
>	  if (align > old_alignment)
>	    h->root.u.c.p->alignment_power = align;

`h->root.u.c.p->alignment_power' setted by
`_bfd_generic_link_add_one_symbol' to default value for `var' size
`h->root.u.c.p->alignment_power' is 16
In my case `old_alignment' is 0 because I have only one declared `var'.
`sym.st_value' is 1 because `.comm var,23,1'.
`align' is 0 because 1 = 2**0.
So, `align' equal to `old_alignment' and we skip the body of `if'.

In output I have `var' aligned to 16 - it's wrong.

Denis.

Sun Aug 20 23:43:28 2000  Denis Chertykov  <denisc@overta.ru>

	* elflink.h (elf_link_add_object_symbols): .comm variables can be
	rounded to 1.



Index: elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.52
diff -c -3 -p -r1.52 elflink.h
*** elflink.h	2000/04/27 00:31:16	1.52
--- elflink.h	2000/08/20 19:49:37
*************** elf_link_add_object_symbols (abfd, info)
*** 1527,1533 ****
  	  unsigned int align;
  
  	  align = bfd_log2 (sym.st_value);
! 	  if (align > old_alignment)
  	    h->root.u.c.p->alignment_power = align;
  	}
  
--- 1527,1533 ----
  	  unsigned int align;
  
  	  align = bfd_log2 (sym.st_value);
! 	  if (align >= old_alignment)
  	    h->root.u.c.p->alignment_power = align;
  	}
  


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