[binutils-gdb] x86: allow @size to also (sensibly) apply to sections

Jan Beulich jbeulich@sourceware.org
Thu Apr 29 09:45:26 GMT 2021


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=44f871628ccfcfd931f4619c60554f3bd6b57b8d

commit 44f871628ccfcfd931f4619c60554f3bd6b57b8d
Author: Jan Beulich <jbeulich@suse.com>
Date:   Thu Apr 29 11:43:53 2021 +0200

    x86: allow @size to also (sensibly) apply to sections
    
    So far this (counter-intuitively) produced the size as recorded in the
    (section) symbol. Obtain the section's size instead for section symbols.
    (I wonder whether STT_SECTION symbols couldn't properly hold the
    section's size in their st_size field, which in turn would likely mean
    the internal symbol would also have its size properly updated.)
    
    Note that this is not the same as the .sizeof.() pseudo-operator: @size
    yields the local file's contribution to a section, while .sizeof.() gets
    resolved by the linker to produce the final full section's size.
    
    As to the 3rd each of the expected output lines in the changed testcase:
    I can't find justification for zzz to come after yyy despite them being
    defined in the opposite order in source. Therefore I think it's better
    to permit both possible outcomes.

Diff:
---
 gas/ChangeLog                          |  8 ++++++++
 gas/config/tc-i386.c                   |  6 +++++-
 gas/testsuite/gas/i386/size-2.d        | 13 ++++++++++---
 gas/testsuite/gas/i386/size-2.s        |  3 +++
 gas/testsuite/gas/i386/x86-64-size-2.d | 13 ++++++++++---
 5 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 5d341e8004e..e36170a2f91 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,11 @@
+2021-04-29  Jan Beulich  <jbeulich@suse.com>
+
+	* config/tc-i386.c (tc_gen_reloc): Use section size for section
+	symbols when resolving BFD_RELOC_SIZE*.
+	* testsuite/gas/i386/size-2.s: Add section size cases.
+	* testsuite/gas/i386/size-2.d,
+	testsuite/gas/i386/x86-64-size-2.d: Adjust expectations.
+
 2021-04-28  Jan Beulich  <jbeulich@suse.com>
             H.J. Lu  <hjl.tools@gmail.com>
 
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index bd2da65bece..9c544ee231d 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -14241,7 +14241,11 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
 	{
 	  /* Resolve size relocation against local symbol to size of
 	     the symbol plus addend.  */
-	  valueT value = S_GET_SIZE (fixp->fx_addsy) + fixp->fx_offset;
+	  valueT value = S_GET_SIZE (fixp->fx_addsy);
+
+	  if (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_SECTION_SYM)
+	    value = bfd_section_size (S_GET_SEGMENT (fixp->fx_addsy));
+	  value += fixp->fx_offset;
 	  if (fixp->fx_r_type == BFD_RELOC_SIZE32
 	      && object_64bit
 	      && !fits_in_unsigned_long (value))
diff --git a/gas/testsuite/gas/i386/size-2.d b/gas/testsuite/gas/i386/size-2.d
index 685720b3c50..38b96f68f22 100644
--- a/gas/testsuite/gas/i386/size-2.d
+++ b/gas/testsuite/gas/i386/size-2.d
@@ -1,10 +1,14 @@
 #name: i386 size 2
-#objdump: -dwr
-
+#objdump: -dhwr
 
 .*: +file format .*
 
-
+Sections:
+Idx Name +Size .*
+  0 \.text +0*3c .*
+  1 \.data +0*5c .*
+  2 \.bss +0*199999(ae|b0) .*
+#...
 Disassembly of section .text:
 
 0+ <.text>:
@@ -17,4 +21,7 @@ Disassembly of section .text:
 [ 	]*[a-f0-9]+:	b8 90 99 99 19       	mov    \$0x19999990,%eax
 [ 	]*[a-f0-9]+:	b8 70 99 99 19       	mov    \$0x19999970,%eax
 [ 	]*[a-f0-9]+:	b8 b0 99 99 19       	mov    \$0x199999b0,%eax
+[ 	]*[a-f0-9]+:	b8 3c 00 00 00       	mov    \$0x3c,%eax
+[ 	]*[a-f0-9]+:	b8 60 00 00 00       	mov    \$0x60,%eax
+[ 	]*[a-f0-9]+:	b8 (ae|b0) 99 99 09       	mov    \$0x99999(ae|b0),%eax
 #pass
diff --git a/gas/testsuite/gas/i386/size-2.s b/gas/testsuite/gas/i386/size-2.s
index 09f8f4724b2..b1f814a3765 100644
--- a/gas/testsuite/gas/i386/size-2.s
+++ b/gas/testsuite/gas/i386/size-2.s
@@ -9,6 +9,9 @@
 	movl	$zzz@SIZE, %eax
 	movl	$zzz@SIZE - 32, %eax
 	movl	$zzz@SIZE + 32, %eax
+	movl	$.text@SIZE, %eax
+	movl	$.data@SIZE + 4, %eax
+	movl	$.bss@SIZE - 0x10000000, %eax
 	.local	zzz
 	.comm	zzz,429496720,32
 	.bss
diff --git a/gas/testsuite/gas/i386/x86-64-size-2.d b/gas/testsuite/gas/i386/x86-64-size-2.d
index f144c4780b5..2c49d5307c7 100644
--- a/gas/testsuite/gas/i386/x86-64-size-2.d
+++ b/gas/testsuite/gas/i386/x86-64-size-2.d
@@ -1,11 +1,15 @@
 #name: x86-64 size 2
 #source: size-2.s
-#objdump: -dwr
-
+#objdump: -dhwr
 
 .*: +file format .*
 
-
+Sections:
+Idx Name +Size .*
+  0 \.text +0*3c .*
+  1 \.data +0*5c .*
+  2 \.bss +0*199999(ae|b0) .*
+#...
 Disassembly of section .text:
 
 0+ <.text>:
@@ -18,4 +22,7 @@ Disassembly of section .text:
 [ 	]*[a-f0-9]+:	b8 90 99 99 19       	mov    \$0x19999990,%eax
 [ 	]*[a-f0-9]+:	b8 70 99 99 19       	mov    \$0x19999970,%eax
 [ 	]*[a-f0-9]+:	b8 b0 99 99 19       	mov    \$0x199999b0,%eax
+[ 	]*[a-f0-9]+:	b8 3c 00 00 00       	mov    \$0x3c,%eax
+[ 	]*[a-f0-9]+:	b8 60 00 00 00       	mov    \$0x60,%eax
+[ 	]*[a-f0-9]+:	b8 (ae|b0) 99 99 09       	mov    \$0x99999(ae|b0),%eax
 #pass


More information about the Binutils-cvs mailing list