public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Bug (and fix) in gas: frags.c @ frag_align
@ 2000-07-21 16:58 Serge Nikulin
  2000-07-21 21:25 ` Alan Modra
  0 siblings, 1 reply; 2+ messages in thread
From: Serge Nikulin @ 2000-07-21 16:58 UTC (permalink / raw)
  To: Serge Nikulin; +Cc: binutils

Hi,

As I have reported already, I had a problem with alignment in absolute
section.
I found the bug in frags.c file in frag_align function.

Old code:
---------
      new_off = ((abs_section_offset + alignment - 1)
   &~ ((1 << alignment) - 1));
---------

When abs_section_offset == 1 and alignment == 1 then new_off should be == 2

In the above code new_off == 0

The proposed new code:
-------------------
if ((abs_section_offset & ((1 << alignment) - 1)) != 0)
    new_off = ((abs_section_offset  >> alignment) + 1) << alignment;
else
    new_off = abs_section_offset;    /* aligned already */
-------------------

Serge





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

* Re: Bug (and fix) in gas: frags.c @ frag_align
  2000-07-21 16:58 Bug (and fix) in gas: frags.c @ frag_align Serge Nikulin
@ 2000-07-21 21:25 ` Alan Modra
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2000-07-21 21:25 UTC (permalink / raw)
  To: Serge Nikulin; +Cc: Serge Nikulin, binutils

On Fri, 21 Jul 2000, Serge Nikulin wrote:

> I found the bug in frags.c file in frag_align function.
> 
>       new_off = ((abs_section_offset + alignment - 1)
>    &~ ((1 << alignment) - 1));

Yes, that's broken.  I'm checking in the following to fix it.

Thanks, Alan Modra
-- 
Linuxcare.  Support for the Revolution.


gas/ChangeLog
	* frags.c (frag_align): Correct absolute section alignment.

Index: frags.c
===================================================================
RCS file: /cvs/src/src/gas/frags.c,v
retrieving revision 1.5
diff -u -p -r1.5 frags.c
--- frags.c	2000/05/23 05:07:47	1.5
+++ frags.c	2000/07/22 04:11:36
@@ -303,9 +303,10 @@ frag_align (alignment, fill_character, m
   if (now_seg == absolute_section)
     {
       addressT new_off;
+      addressT mask;
 
-      new_off = ((abs_section_offset + alignment - 1)
-		 &~ ((1 << alignment) - 1));
+      mask = (~ (addressT) 0) << alignment;
+      new_off = (abs_section_offset + ~ mask) & mask;
       if (max == 0 || new_off - abs_section_offset <= (addressT) max)
 	abs_section_offset = new_off;
     }

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

end of thread, other threads:[~2000-07-21 21:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-21 16:58 Bug (and fix) in gas: frags.c @ frag_align Serge Nikulin
2000-07-21 21:25 ` Alan Modra

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