[4/4] x86: allow @secrel32 also in data definitions

Message ID e4798e2c-cf45-95ce-a2b4-2227fabbbf5a@suse.com
State New
Headers show
Series
  • x86: assorted relocation handling related adjustments (part III)
Related show

Commit Message

Alan Modra via Binutils April 29, 2021, 10:01 a.m.
Now that lex_got() is uniform for all targets using it, permit COFF
targets to also use @secrel32 with, in particular, .long. This is more
natural than the custom .secrel32 directive, and also allows more
flexibility (the "+six" form of the two added test lines doesn't work
with a .secrel32 equivalent, in that it silently produces an unintended
relocation type).

As an extra benefit this also makes sure that data definitions in Intel
syntax mode would get treated like they do for e.g. ELF targets.

gas/
2021-04-XX  Jan Beulich  <jbeulich@suse.com>

	* config/tc-i386.h (TC_PARSE_CONS_EXPRESSION): Adjust surrounding
	#if.
	* testsuite/gas/i386/secrel.s: Convert some .secrel32 to .long.
	Add two further .long and an .equ.
	* testsuite/gas/i386/secrel.d: Adjust expecations.
---
Perhaps that shortcoming of .secrel32 should be addressed anyway, but
pe_directive_secrel()'s changing of X_op from O_symbol to O_secrel is
too ad hoc for me to see how a proper change ought to look like.

Perhaps, because of the Intel syntax aspect, TC_PARSE_CONS_EXPRESSION()
should unconditionally expand to x86_cons().

Patch

--- a/gas/config/tc-i386.h
+++ b/gas/config/tc-i386.h
@@ -126,7 +126,8 @@  extern const char *i386_comment_chars;
 #define GLOBAL_OFFSET_TABLE_NAME "_GLOBAL_OFFSET_TABLE_"
 #endif
 
-#if (defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) && !defined (LEX_AT)
+#if ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)) \
+     && !defined (LEX_AT)) || defined (TE_PE)
 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) x86_cons (EXP, NBYTES)
 #endif
 extern bfd_reloc_code_real_type x86_cons (expressionS *, int);
--- a/gas/testsuite/gas/i386/secrel.d
+++ b/gas/testsuite/gas/i386/secrel.d
@@ -21,7 +21,9 @@  OFFSET[ 	]+TYPE[ 	]+VALUE *
 0+89 secrel32          ext2d
 0+8e secrel32          ext36
 0+93 secrel32          ext3f
-0+a2 secrel32          bar
+0+a0 secrel32          \.text
+0+a4 secrel32          \.text
+0+aa secrel32          bar
 
 Contents of section \.text:
  0000 3e3e3e3e 3c3c3c3c 3e3e3e3e 3e3c3c3c  >>>><<<<>>>>><<<
@@ -37,7 +39,7 @@  Contents of section \.data:
  0070 0000111f 00000011 3c3c3c3c 3c3c3c3c  ........<<<<<<<<
  0080 3e3e3e3e 00000000 11000000 00110000  >>>>............
  0090 00001100 00000011 3c3c3c3c 3c3c3c3c  ........<<<<<<<<
- 00a0 8d902c00 00000000                    ..,..... *
+ 00a0 10000000 1c000000 8d902c00 00000000  ..........,.....
 Contents of section \.rdata:
  0000 3e3e3e3e 3c3c3c3c 3e3e3e3e 3e3c3c3c  >>>><<<<>>>>><<<
  0010 3e3e3e3e 3e3e3c3c 3e3e3e3e 3e3e3e3c  >>>>>><<>>>>>>><
--- a/gas/testsuite/gas/i386/secrel.s
+++ b/gas/testsuite/gas/i386/secrel.s
@@ -27,7 +27,7 @@  sam1f:	.ascii "<"
 	.byte 0x11
 	.secrel32 pre16
 	.byte 0x11
-	.secrel32 pre1f
+	.long pre1f@secrel32
 	.byte 0x11
 	.ascii "<<<<<<<<"
 
@@ -36,7 +36,7 @@  sam1f:	.ascii "<"
 	.byte 0x11
 	.secrel32 sam0d
 	.byte 0x11
-	.secrel32 sam16
+	.long sam16@secrel32
 	.byte 0x11
 	.secrel32 sam1f
 	.byte 0x11
@@ -45,7 +45,7 @@  sam1f:	.ascii "<"
 	.ascii ">>>>"
 	.secrel32 nex04
 	.byte 0x11
-	.secrel32 nex0d
+	.long nex0d@secrel32
 	.byte 0x11
 	.secrel32 nex16
 	.byte 0x11
@@ -54,7 +54,7 @@  sam1f:	.ascii "<"
 	.ascii "<<<<<<<<"
 
 	.ascii ">>>>"
-	.secrel32 ext24
+	.long ext24@secrel32
 	.byte 0x11
 	.secrel32 ext2d
 	.byte 0x11
@@ -64,6 +64,9 @@  sam1f:	.ascii "<"
 	.byte 0x11
 	.ascii "<<<<<<<<"
 
+	.long pre0d@secrel32+3
+	.long pre16@secrel32+six
+
 	leal	bar@SECREL32+44(%eax), %edx
 
 .section .rdata
@@ -79,3 +82,4 @@  nex1f:	.ascii "<"
 	.ascii ">>>>"
 
 	.p2align 4,0
+	.equ six,6