[2/4] LD: Support fixed-size sections some psABIs may require

Message ID alpine.DEB.2.00.1801312116210.4191@tp.orcam.me.uk
State New
Headers show
Series
  • LD: Support fixed-size sections some psABIs may require
Related show

Commit Message

Maciej W. Rozycki Jan. 31, 2018, 10:57 p.m.
Define a SEC_FIXED_SIZE section flag for target backends to use for 
output sections whose size has been fixed in the psABI.  The size of 
such sections will not be changed anyhow by the generic linker and it is 
up to the target backend to get their size right.

	bfd/
	* section.c (SEC_FIXED_SIZE): New macro.
	* bfd-in2.h: Regenerate.

        ld/
        * ldlang.c (insert_pad): Do not change output section's size if
	SEC_FIXED_SIZE is set in the flags.
	(size_input_section): Likewise.
	(lang_size_sections_1): Likewise.
	(lang_reset_memory_regions): Likewise.
---
Hi,

 No regressions across my usual targets.  OK to apply?

  Maciej
---
 bfd/bfd-in2.h |    5 +++++
 bfd/section.c |    5 +++++
 ld/ldlang.c   |   30 ++++++++++++++++++++----------
 3 files changed, 30 insertions(+), 10 deletions(-)

binutils-section-fixed-size.diff

Comments

Nick Clifton Feb. 1, 2018, 12:11 p.m. | #1
Hi Maciej,

> Define a SEC_FIXED_SIZE section flag for target backends to use for 

> output sections whose size has been fixed in the psABI.  The size of 

> such sections will not be changed anyhow by the generic linker and it is 

> up to the target backend to get their size right.


One thing that worries me is - should the linker issue a warning/error
message if the user does attempt to change the size of a fixed-size section ?
Or maybe only issue the message if the size change would make the section
bigger than is allowed ?

Hmm, actually, going one step further - do we need to support a FIXED_SIZE(<vale>)
section attribute for linker scripts, so that these sections can be defined 
there too ?

Cheers
  Nick
Maciej W. Rozycki Feb. 5, 2018, 3:01 p.m. | #2
Hi Nick,

> > Define a SEC_FIXED_SIZE section flag for target backends to use for 

> > output sections whose size has been fixed in the psABI.  The size of 

> > such sections will not be changed anyhow by the generic linker and it is 

> > up to the target backend to get their size right.

> 

> One thing that worries me is - should the linker issue a warning/error

> message if the user does attempt to change the size of a fixed-size section ?

> Or maybe only issue the message if the size change would make the section

> bigger than is allowed ?


 An error would defeat the purpose of this change, as what the change does 
is to ensure the size is fixed, by truncating or padding out the section 
concerned as required.  We currently abort, with an error, in the MIPS 
backend if one of the fixed-size sections turns out not to have the right 
size, and this patch changes it.

 A warning might make sense, although given how linker processing is done 
it would require keeping track of section size update attempts and only 
issue the warning if the final one ends up with a size mismatch.  I'll see 
if I can look into it, but given my other commitments right now I may not 
be able to do anything about it.

> Hmm, actually, going one step further - do we need to support a FIXED_SIZE(<vale>)

> section attribute for linker scripts, so that these sections can be defined 

> there too ?


 I don't know, I would have to think about a use case.  Maybe someone else 
can chime in.

  Maciej
Nick Clifton Feb. 5, 2018, 5:27 p.m. | #3
Hi Maciej,

>  A warning might make sense, although given how linker processing is done 

> it would require keeping track of section size update attempts and only 

> issue the warning if the final one ends up with a size mismatch.  I'll see 

> if I can look into it, but given my other commitments right now I may not 

> be able to do anything about it.


No worries - I do not see this as being a critical requirement.

>> Hmm, actually, going one step further - do we need to support a FIXED_SIZE(<vale>)

>> section attribute for linker scripts, so that these sections can be defined 

>> there too ?

> 

>  I don't know, I would have to think about a use case.  Maybe someone else 

> can chime in.


If someone does then I am willing to investigate implementing the enhancement.
But I suspect that no-one will be really bothered about this, so it can remain
on the wish list for that day when I have run out of other things to do.

Cheers
  Nick
Maciej W. Rozycki Feb. 13, 2018, 3:14 p.m. | #4
Hi Nick,

> >  A warning might make sense, although given how linker processing is done 

> > it would require keeping track of section size update attempts and only 

> > issue the warning if the final one ends up with a size mismatch.  I'll see 

> > if I can look into it, but given my other commitments right now I may not 

> > be able to do anything about it.

> 

> No worries - I do not see this as being a critical requirement.


 Given that nobody else has spoken shall I take it as your approval for 
this change as it stands?

  Maciej
Nick Clifton Feb. 13, 2018, 4:59 p.m. | #5
Hi Maciej,

>> No worries - I do not see this as being a critical requirement.

> 

>  Given that nobody else has spoken shall I take it as your approval for 

> this change as it stands?


Yes, please do. :-)

Cheers
  Nick
Maciej W. Rozycki Feb. 19, 2018, 6:42 p.m. | #6
Hi Nick,

> >> No worries - I do not see this as being a critical requirement.

> > 

> >  Given that nobody else has spoken shall I take it as your approval for 

> > this change as it stands?

> 

> Yes, please do. :-)


 Thank you for your review.  I have now applied this change, as well as 
the remaining ones in this series.

  Maciej

Patch

Index: binutils/bfd/bfd-in2.h
===================================================================
--- binutils.orig/bfd/bfd-in2.h	2018-01-31 20:38:09.548999454 +0000
+++ binutils/bfd/bfd-in2.h	2018-01-31 20:38:59.522971771 +0000
@@ -1324,6 +1324,11 @@  typedef struct bfd_section
   /* The section contains thread local data.  */
 #define SEC_THREAD_LOCAL                0x400
 
+  /* The section's size is fixed.  Generic linker code will not
+     recalculate it and it is up to whoever has set this flag to
+     get the size right.  */
+#define SEC_FIXED_SIZE                  0x800
+
   /* The section contains common symbols (symbols may be defined
      multiple times, the value of a symbol is the amount of
      space it requires, and the largest symbol value is the one
Index: binutils/bfd/section.c
===================================================================
--- binutils.orig/bfd/section.c	2018-01-31 20:38:09.573532846 +0000
+++ binutils/bfd/section.c	2018-01-31 20:38:59.572911226 +0000
@@ -221,6 +221,11 @@  CODE_FRAGMENT
 .  {* The section contains thread local data.  *}
 .#define SEC_THREAD_LOCAL                0x400
 .
+.  {* The section's size is fixed.  Generic linker code will not
+.     recalculate it and it is up to whoever has set this flag to
+.     get the size right.  *}
+.#define SEC_FIXED_SIZE                  0x800
+.
 .  {* The section contains common symbols (symbols may be defined
 .     multiple times, the value of a symbol is the amount of
 .     space it requires, and the largest symbol value is the one
Index: binutils/ld/ldlang.c
===================================================================
--- binutils.orig/ld/ldlang.c	2018-01-31 20:38:09.584743216 +0000
+++ binutils/ld/ldlang.c	2018-01-31 20:38:59.629693927 +0000
@@ -4675,8 +4675,9 @@  insert_pad (lang_statement_union_type **
     }
   pad->padding_statement.output_offset = dot - output_section->vma;
   pad->padding_statement.size = alignment_needed;
-  output_section->size = TO_SIZE (dot + TO_ADDR (alignment_needed)
-				  - output_section->vma);
+  if (!(output_section->flags & SEC_FIXED_SIZE))
+    output_section->size = TO_SIZE (dot + TO_ADDR (alignment_needed)
+				    - output_section->vma);
 }
 
 /* Work out how much this section will move the dot point.  */
@@ -4725,7 +4726,8 @@  size_input_section
 
       /* Mark how big the output section must be to contain this now.  */
       dot += TO_ADDR (i->size);
-      o->size = TO_SIZE (dot - o->vma);
+      if (!(o->flags & SEC_FIXED_SIZE))
+	o->size = TO_SIZE (dot - o->vma);
     }
 
   return dot;
@@ -5079,7 +5081,8 @@  lang_size_sections_1
 		bfd_set_section_vma (os->bfd_section->owner,
 				     os->bfd_section,
 				     bfd_section_vma (input->owner, input));
-		os->bfd_section->size = input->size;
+		if (!(os->bfd_section->flags & SEC_FIXED_SIZE))
+		  os->bfd_section->size = input->size;
 		break;
 	      }
 
@@ -5194,7 +5197,9 @@  lang_size_sections_1
 			  + os->block_value - 1)
 			 & - (bfd_vma) os->block_value);
 
-		os->bfd_section->size = TO_SIZE (after - os->bfd_section->vma);
+		if (!(os->bfd_section->flags & SEC_FIXED_SIZE))
+		  os->bfd_section->size = TO_SIZE (after
+						   - os->bfd_section->vma);
 	      }
 
 	    /* Set section lma.  */
@@ -5379,8 +5384,10 @@  lang_size_sections_1
 	    if (size < TO_SIZE ((unsigned) 1))
 	      size = TO_SIZE ((unsigned) 1);
 	    dot += TO_ADDR (size);
-	    output_section_statement->bfd_section->size
-	      = TO_SIZE (dot - output_section_statement->bfd_section->vma);
+	    if (!(output_section_statement->bfd_section->flags
+		  & SEC_FIXED_SIZE))
+	      output_section_statement->bfd_section->size
+		= TO_SIZE (dot - output_section_statement->bfd_section->vma);
 
 	  }
 	  break;
@@ -5395,8 +5402,10 @@  lang_size_sections_1
 	      output_section_statement->bfd_section;
 	    size = bfd_get_reloc_size (s->reloc_statement.howto);
 	    dot += TO_ADDR (size);
-	    output_section_statement->bfd_section->size
-	      = TO_SIZE (dot - output_section_statement->bfd_section->vma);
+	    if (!(output_section_statement->bfd_section->flags
+		  & SEC_FIXED_SIZE))
+	      output_section_statement->bfd_section->size
+		= TO_SIZE (dot - output_section_statement->bfd_section->vma);
 	  }
 	  break;
 
@@ -6764,7 +6773,8 @@  lang_reset_memory_regions (void)
     {
       /* Save the last size for possible use by bfd_relax_section.  */
       o->rawsize = o->size;
-      o->size = 0;
+      if (!(o->flags & SEC_FIXED_SIZE))
+	o->size = 0;
     }
 }