Blame binutils-delay-ld-script-constant-eval.patch

4b7c783
diff -rup binutils.orig/ld/emultempl/pe.em binutils-2.31.1/ld/emultempl/pe.em
4b7c783
--- binutils.orig/ld/emultempl/pe.em	2018-09-04 11:00:05.546667021 +0100
4b7c783
+++ binutils-2.31.1/ld/emultempl/pe.em	2018-09-04 11:00:58.427292612 +0100
4b7c783
@@ -2165,7 +2165,7 @@ gld_${EMULATION_NAME}_place_orphan (asec
4b7c783
 			       &add_child);
4b7c783
       if (bfd_link_relocatable (&link_info))
4b7c783
 	{
4b7c783
-	  os->section_alignment = s->alignment_power;
4b7c783
+	  os->section_alignment = exp_intop (1U << s->alignment_power);
4b7c783
 	  os->bfd_section->alignment_power = s->alignment_power;
4b7c783
 	}
4b7c783
     }
4b7c783
diff -rup binutils.orig/ld/emultempl/pep.em binutils-2.31.1/ld/emultempl/pep.em
4b7c783
--- binutils.orig/ld/emultempl/pep.em	2018-09-04 11:00:05.545667029 +0100
4b7c783
+++ binutils-2.31.1/ld/emultempl/pep.em	2018-09-04 11:01:29.340073740 +0100
4b7c783
@@ -1962,7 +1962,7 @@ gld_${EMULATION_NAME}_place_orphan (asec
4b7c783
 			       &add_child);
4b7c783
       if (bfd_link_relocatable (&link_info))
4b7c783
 	{
4b7c783
-	  os->section_alignment = s->alignment_power;
4b7c783
+	  os->section_alignment = exp_intop (1U << s->alignment_power);
4b7c783
 	  os->bfd_section->alignment_power = s->alignment_power;
4b7c783
 	}
4b7c783
     }
4b7c783
diff -rup binutils.orig/ld/ldexp.c binutils-2.31.1/ld/ldexp.c
4b7c783
--- binutils.orig/ld/ldexp.c	2018-09-04 11:00:05.535667100 +0100
4b7c783
+++ binutils-2.31.1/ld/ldexp.c	2018-09-04 11:03:29.179225246 +0100
4b7c783
@@ -1528,6 +1528,28 @@ exp_get_value_int (etree_type *tree, int
4b7c783
   return exp_get_vma (tree, def, name);
4b7c783
 }
4b7c783
 
4b7c783
+/* Return the smallest non-negative integer such that two raised to
4b7c783
+   that power is at least as large as the vma evaluated at TREE, if
4b7c783
+   TREE is a non-NULL expression that can be resolved.  If TREE is
4b7c783
+   NULL or cannot be resolved, return -1.  */
4b7c783
+
4b7c783
+signed int
4b7c783
+exp_get_power (etree_type *tree, char *name)
4b7c783
+{
4b7c783
+  bfd_vma x = exp_get_vma (tree, -1, name);
4b7c783
+  bfd_vma p2;
4b7c783
+  int n;
4b7c783
+
4b7c783
+  if (x == (bfd_vma) -1)
4b7c783
+    return -1;
4b7c783
+
4b7c783
+  for (n = 0, p2 = 1; p2 < x; ++n, p2 <<= 1)
4b7c783
+    if (p2 == 0)
4b7c783
+      break;
4b7c783
+
4b7c783
+  return n;
4b7c783
+}
4b7c783
+
4b7c783
 fill_type *
4b7c783
 exp_get_fill (etree_type *tree, fill_type *def, char *name)
4b7c783
 {
4b7c783
diff -rup binutils.orig/ld/ldexp.h binutils-2.31.1/ld/ldexp.h
4b7c783
--- binutils.orig/ld/ldexp.h	2018-09-04 11:00:05.536667092 +0100
4b7c783
+++ binutils-2.31.1/ld/ldexp.h	2018-09-04 11:04:12.937915422 +0100
4b7c783
@@ -231,6 +231,8 @@ bfd_vma exp_get_vma
4b7c783
   (etree_type *, bfd_vma, char *);
4b7c783
 int exp_get_value_int
4b7c783
   (etree_type *, int, char *);
4b7c783
+signed int exp_get_power
4b7c783
+  (etree_type *, char *);
4b7c783
 fill_type *exp_get_fill
4b7c783
   (etree_type *, fill_type *, char *);
4b7c783
 bfd_vma exp_get_abs_int
4b7c783
diff -rup binutils.orig/ld/ldlang.c binutils-2.31.1/ld/ldlang.c
4b7c783
--- binutils.orig/ld/ldlang.c	2018-09-04 11:00:05.536667092 +0100
4b7c783
+++ binutils-2.31.1/ld/ldlang.c	2018-09-04 11:07:42.249433438 +0100
4b7c783
@@ -1199,8 +1199,8 @@ output_section_statement_newfunc (struct
4b7c783
   ret = (struct out_section_hash_entry *) entry;
4b7c783
   memset (&ret->s, 0, sizeof (ret->s));
4b7c783
   ret->s.header.type = lang_output_section_statement_enum;
4b7c783
-  ret->s.output_section_statement.subsection_alignment = -1;
4b7c783
-  ret->s.output_section_statement.section_alignment = -1;
4b7c783
+  ret->s.output_section_statement.subsection_alignment = NULL;
4b7c783
+  ret->s.output_section_statement.section_alignment = NULL;
4b7c783
   ret->s.output_section_statement.block_value = 1;
4b7c783
   lang_list_init (&ret->s.output_section_statement.children);
4b7c783
   lang_statement_append (stat_ptr, &ret->s, &ret->s.header.next);
4b7c783
@@ -2193,8 +2193,9 @@ init_os (lang_output_section_statement_t
4b7c783
     exp_init_os (s->load_base);
4b7c783
 
4b7c783
   /* If supplied an alignment, set it.  */
4b7c783
-  if (s->section_alignment != -1)
4b7c783
-    s->bfd_section->alignment_power = s->section_alignment;
4b7c783
+  if (s->section_alignment != NULL)
4b7c783
+    s->bfd_section->alignment_power = exp_get_power (s->section_alignment,
4b7c783
+                                                    "section alignment");
4b7c783
 }
4b7c783
 
4b7c783
 /* Make sure that all output sections mentioned in an expression are
4b7c783
@@ -4706,8 +4707,10 @@ size_input_section
4b7c783
 	 is greater than any seen before, then record it too.  Perform
4b7c783
 	 the alignment by inserting a magic 'padding' statement.  */
4b7c783
 
4b7c783
-      if (output_section_statement->subsection_alignment != -1)
4b7c783
-	i->alignment_power = output_section_statement->subsection_alignment;
4b7c783
+      if (output_section_statement->subsection_alignment != NULL)
4b7c783
+	i->alignment_power
4b7c783
+	  = exp_get_power (output_section_statement->subsection_alignment,
4b7c783
+			   "subsection alignment");
4b7c783
 
4b7c783
       if (o->alignment_power < i->alignment_power)
4b7c783
 	o->alignment_power = i->alignment_power;
4b7c783
@@ -5147,7 +5150,8 @@ lang_size_sections_1
4b7c783
 		    section_alignment = os->bfd_section->alignment_power;
4b7c783
 		  }
4b7c783
 		else
4b7c783
-		  section_alignment = os->section_alignment;
4b7c783
+                 section_alignment = exp_get_power (os->section_alignment,
4b7c783
+                                                    "section alignment");
4b7c783
 
4b7c783
 		/* Align to what the section needs.  */
4b7c783
 		if (section_alignment > 0)
4b7c783
@@ -5225,7 +5229,8 @@ lang_size_sections_1
4b7c783
 		       only align according to the value in the output
4b7c783
 		       statement.  */
4b7c783
 		    if (os->lma_region != os->region)
4b7c783
-		      section_alignment = os->section_alignment;
4b7c783
+		      section_alignment = exp_get_power (os->section_alignment,
4b7c783
+							 "section alignment");
4b7c783
 		    if (section_alignment > 0)
4b7c783
 		      lma = align_power (lma, section_alignment);
4b7c783
 		  }
4b7c783
@@ -6673,25 +6678,6 @@ lang_add_output (const char *name, int f
4b7c783
     }
4b7c783
 }
4b7c783
 
4b7c783
-static int
4b7c783
-topower (int x)
4b7c783
-{
4b7c783
-  unsigned int i = 1;
4b7c783
-  int l;
4b7c783
-
4b7c783
-  if (x < 0)
4b7c783
-    return -1;
4b7c783
-
4b7c783
-  for (l = 0; l < 32; l++)
4b7c783
-    {
4b7c783
-      if (i >= (unsigned int) x)
4b7c783
-	return l;
4b7c783
-      i <<= 1;
4b7c783
-    }
4b7c783
-
4b7c783
-  return 0;
4b7c783
-}
4b7c783
-
4b7c783
 lang_output_section_statement_type *
4b7c783
 lang_enter_output_section_statement (const char *output_section_statement_name,
4b7c783
 				     etree_type *address_exp,
4b7c783
@@ -6727,10 +6713,8 @@ lang_enter_output_section_statement (con
4b7c783
     einfo (_("%F%P:%pS: error: align with input and explicit align specified\n"),
4b7c783
 	   NULL);
4b7c783
 
4b7c783
-  os->subsection_alignment =
4b7c783
-    topower (exp_get_value_int (subalign, -1, "subsection alignment"));
4b7c783
-  os->section_alignment =
4b7c783
-    topower (exp_get_value_int (align, -1, "section alignment"));
4b7c783
+  os->subsection_alignment = subalign;
4b7c783
+  os->section_alignment = align;
4b7c783
 
4b7c783
   os->load_base = ebase;
4b7c783
   return os;
4b7c783
@@ -7748,7 +7732,7 @@ lang_new_phdr (const char *name,
4b7c783
   n = (struct lang_phdr *) stat_alloc (sizeof (struct lang_phdr));
4b7c783
   n->next = NULL;
4b7c783
   n->name = name;
4b7c783
-  n->type = exp_get_value_int (type, 0, "program header type");
4b7c783
+  n->type = exp_get_vma (type, 0, "program header type");
4b7c783
   n->filehdr = filehdr;
4b7c783
   n->phdrs = phdrs;
4b7c783
   n->at = at;
4b7c783
diff -rup binutils.orig/ld/ldlang.h binutils-2.31.1/ld/ldlang.h
4b7c783
--- binutils.orig/ld/ldlang.h	2018-09-04 11:00:05.533667114 +0100
4b7c783
+++ binutils-2.31.1/ld/ldlang.h	2018-09-04 11:08:29.224100845 +0100
4b7c783
@@ -143,6 +143,8 @@ typedef struct lang_output_section_state
4b7c783
   fill_type *fill;
4b7c783
   union etree_union *addr_tree;
4b7c783
   union etree_union *load_base;
4b7c783
+  union etree_union *section_alignment;
4b7c783
+  union etree_union *subsection_alignment;
4b7c783
 
4b7c783
   /* If non-null, an expression to evaluate after setting the section's
4b7c783
      size.  The expression is evaluated inside REGION (above) with '.'
4b7c783
@@ -153,8 +155,6 @@ typedef struct lang_output_section_state
4b7c783
   lang_output_section_phdr_list *phdrs;
4b7c783
 
4b7c783
   unsigned int block_value;
4b7c783
-  int subsection_alignment;	/* Alignment of components.  */
4b7c783
-  int section_alignment;	/* Alignment of start of section.  */
4b7c783
   int constraint;
4b7c783
   flagword flags;
4b7c783
   enum section_type sectype;