This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

Re: ALIGN directive showing different behavior than documented


On Tue, Jul 07, 2015 at 02:41:59PM +0100, Andre Vieira wrote:
> After some digging I found that the unary operator uses the expression
> 'expld.dot' whereas the binary operator uses 'lhs.value'. The first gives an
> absolute value, whereas the second seems to hold a relative value to the
> section start.

Right, lhs.value is evaluated from fold_name case NAME here:
      else if (tree->name.name[0] == '.' && tree->name.name[1] == 0)
	new_rel_from_abs (expld.dot);

So the difference is that the unary operator is missing a conversion
from absolute to relative.  I think that is a bug since we say the
value of dot inside a section is relative to the start of the section.

I wonder how many scripts rely on the old behaviour?  If I don't hear
any objections to this change, I'll install the following in a day or
two.

	* ldexp.c (align_dot_val): New function.
	(fold_unary <ALIGN_K, NEXT>): Use it.

diff --git a/ld/ldexp.c b/ld/ldexp.c
index a5192b1..2c0fe5a 100644
--- a/ld/ldexp.c
+++ b/ld/ldexp.c
@@ -257,6 +257,14 @@ new_rel_from_abs (bfd_vma value)
   expld.result.section = s;
 }
 
+static void
+align_dot_val (bfd_vma align)
+{
+  bfd_vma base = expld.section->vma;
+
+  new_rel_from_abs (base + align_n (expld.dot - base, align));
+}
+
 /* New-function for the definedness hash table.  */
 
 static struct bfd_hash_entry *
@@ -335,7 +343,7 @@ fold_unary (etree_type *tree)
 	{
 	case ALIGN_K:
 	  if (expld.phase != lang_first_phase_enum)
-	    new_rel_from_abs (align_n (expld.dot, expld.result.value));
+	    align_dot_val (expld.result.value);
 	  else
 	    expld.result.valid_p = FALSE;
 	  break;
@@ -365,7 +373,7 @@ fold_unary (etree_type *tree)
 	  if (expld.phase != lang_first_phase_enum)
 	    {
 	      make_abs ();
-	      expld.result.value = align_n (expld.dot, expld.result.value);
+	      align_dot_val (expld.result.value);
 	    }
 	  else
 	    expld.result.valid_p = FALSE;

-- 
Alan Modra
Australia Development Lab, IBM


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