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]

[commit] [PATCH] x86: fix gas' relocation type selection


>It is OK if you add a testcase. Thanks.

FYI:

Added the requested testcases. However, in the course of preparing it
I
had to disable half of what I intended to test for due to unrelated
breakages elsewhere. I intend to try to fix those as time permits.

Re-built and re-tested on i386-pc-linux-gnu and
x86_64-unknown-linux-gnu.

Jan

gas/
2005-08-22  Jan Beulich  <jbeulich@novell.com>

	* config/tc-i386.c (object_64bit): New.
	(i386_target_format): Initialize it.
	(output_disp): Use object_64bit for relocation type
determination.
	(output_imm): Likewise.
	(i386_validate_fix): Likewise.
	(tc_gen_reloc): Likewise.
	(lex_got): Likewise. Remove static mode_name. Change array size
	of gotrel's rel field, and adjust its initializer. Adjust
diagnostic.
	(x86_cons): Use object_64bit for deciding whether quad fields
can
	have relocations.

gas/testsuite/
2005-08-22  Jan Beulich  <jbeulich@novell.com>

	* gas/i386/mixed-mode-reloc.s, gas/i386/mixed-mode-reloc32.d,
	gas/i386/mixed-mode-reloc64.d: New.
	* gas/i386/i386.exp: Run new tests.

---
/home/jbeulich/src/binutils/mainline/2005-08-22/gas/config/tc-i386.c	2005-08-18
08:51:27.000000000 +0200
+++ 2005-08-22/gas/config/tc-i386.c	2005-08-22 14:30:45.535157512
+0200
@@ -287,6 +287,7 @@ enum flag_code {
 #define NUM_FLAG_CODE ((int) CODE_64BIT + 1)
 
 static enum flag_code flag_code;
+static unsigned int object_64bit;
 static int use_rela_relocations = 0;
 
 /* The names used to print error messages.  */
@@ -3611,7 +3612,7 @@ output_disp (insn_start_frag, insn_start
 		      add += p - frag_now->fr_literal;
 		    }
 
-		  if (flag_code != CODE_64BIT)
+		  if (!object_64bit)
 		    reloc_type = BFD_RELOC_386_GOTPC;
 		  else
 		    reloc_type = BFD_RELOC_X86_64_GOTPC32;
@@ -3748,7 +3749,7 @@ output_imm (insn_start_frag, insn_start_
 		      add += p - frag_now->fr_literal;
 		    }
 
-		  if (flag_code != CODE_64BIT)
+		  if (!object_64bit)
 		    reloc_type = BFD_RELOC_386_GOTPC;
 		  else
 		    reloc_type = BFD_RELOC_X86_64_GOTPC32;
@@ -3778,25 +3779,24 @@ lex_got (enum bfd_reloc_code_real *reloc
      int *adjust,
      unsigned int *types)
 {
-  static const char * const mode_name[NUM_FLAG_CODE] = { "32", "16",
"64" };
   static const struct {
     const char *str;
-    const enum bfd_reloc_code_real rel[NUM_FLAG_CODE];
+    const enum bfd_reloc_code_real rel[2];
     const unsigned int types64;
   } gotrel[] = {
-    { "PLT",      { BFD_RELOC_386_PLT32,      0,
BFD_RELOC_X86_64_PLT32    }, Imm32|Imm32S|Disp32 },
-    { "GOTOFF",   { BFD_RELOC_386_GOTOFF,     0,
BFD_RELOC_X86_64_GOTOFF64 }, Imm64|Disp64 },
-    { "GOTPCREL", { 0,                        0,
BFD_RELOC_X86_64_GOTPCREL }, Imm32|Imm32S|Disp32 },
-    { "TLSGD",    { BFD_RELOC_386_TLS_GD,     0,
BFD_RELOC_X86_64_TLSGD    }, Imm32|Imm32S|Disp32 },
-    { "TLSLDM",   { BFD_RELOC_386_TLS_LDM,    0, 0                    
    }, 0 },
-    { "TLSLD",    { 0,                        0,
BFD_RELOC_X86_64_TLSLD    }, Imm32|Imm32S|Disp32 },
-    { "GOTTPOFF", { BFD_RELOC_386_TLS_IE_32,  0,
BFD_RELOC_X86_64_GOTTPOFF }, Imm32|Imm32S|Disp32 },
-    { "TPOFF",    { BFD_RELOC_386_TLS_LE_32,  0,
BFD_RELOC_X86_64_TPOFF32  }, Imm32|Imm32S|Imm64|Disp32|Disp64 },
-    { "NTPOFF",   { BFD_RELOC_386_TLS_LE,     0, 0                    
    }, 0 },
-    { "DTPOFF",   { BFD_RELOC_386_TLS_LDO_32, 0,
BFD_RELOC_X86_64_DTPOFF32 }, Imm32|Imm32S|Imm64|Disp32|Disp64 },
-    { "GOTNTPOFF",{ BFD_RELOC_386_TLS_GOTIE,  0, 0                    
    }, 0 },
-    { "INDNTPOFF",{ BFD_RELOC_386_TLS_IE,     0, 0                    
    }, 0 },
-    { "GOT",      { BFD_RELOC_386_GOT32,      0,
BFD_RELOC_X86_64_GOT32    }, Imm32|Imm32S|Disp32 }
+    { "PLT",      { BFD_RELOC_386_PLT32,      BFD_RELOC_X86_64_PLT32  
 }, Imm32|Imm32S|Disp32 },
+    { "GOTOFF",   { BFD_RELOC_386_GOTOFF,    
BFD_RELOC_X86_64_GOTOFF64 }, Imm64|Disp64 },
+    { "GOTPCREL", { 0,                       
BFD_RELOC_X86_64_GOTPCREL }, Imm32|Imm32S|Disp32 },
+    { "TLSGD",    { BFD_RELOC_386_TLS_GD,     BFD_RELOC_X86_64_TLSGD  
 }, Imm32|Imm32S|Disp32 },
+    { "TLSLDM",   { BFD_RELOC_386_TLS_LDM,    0                       
 }, 0 },
+    { "TLSLD",    { 0,                        BFD_RELOC_X86_64_TLSLD  
 }, Imm32|Imm32S|Disp32 },
+    { "GOTTPOFF", { BFD_RELOC_386_TLS_IE_32, 
BFD_RELOC_X86_64_GOTTPOFF }, Imm32|Imm32S|Disp32 },
+    { "TPOFF",    { BFD_RELOC_386_TLS_LE_32,  BFD_RELOC_X86_64_TPOFF32
 }, Imm32|Imm32S|Imm64|Disp32|Disp64 },
+    { "NTPOFF",   { BFD_RELOC_386_TLS_LE,     0                       
 }, 0 },
+    { "DTPOFF",   { BFD_RELOC_386_TLS_LDO_32,
BFD_RELOC_X86_64_DTPOFF32 }, Imm32|Imm32S|Imm64|Disp32|Disp64 },
+    { "GOTNTPOFF",{ BFD_RELOC_386_TLS_GOTIE,  0                       
 }, 0 },
+    { "INDNTPOFF",{ BFD_RELOC_386_TLS_IE,     0                       
 }, 0 },
+    { "GOT",      { BFD_RELOC_386_GOT32,      BFD_RELOC_X86_64_GOT32  
 }, Imm32|Imm32S|Disp32 }
   };
   char *cp;
   unsigned int j;
@@ -3815,12 +3815,12 @@ lex_got (enum bfd_reloc_code_real *reloc
       len = strlen (gotrel[j].str);
       if (strncasecmp (cp + 1, gotrel[j].str, len) == 0)
 	{
-	  if (gotrel[j].rel[(unsigned int) flag_code] != 0)
+	  if (gotrel[j].rel[object_64bit] != 0)
 	    {
 	      int first, second;
 	      char *tmpbuf, *past_reloc;
 
-	      *reloc = gotrel[j].rel[(unsigned int) flag_code];
+	      *reloc = gotrel[j].rel[object_64bit];
 	      if (adjust)
 		*adjust = len;
 
@@ -3859,8 +3859,8 @@ lex_got (enum bfd_reloc_code_real *reloc
 	      return tmpbuf;
 	    }
 
-	  as_bad (_("@%s reloc is not supported in %s bit mode"),
-		  gotrel[j].str, mode_name[(unsigned int) flag_code]);
+	  as_bad (_("@%s reloc is not supported with %d-bit output
format"),
+		  gotrel[j].str, 1 << (5 + object_64bit));
 	  return NULL;
 	}
     }
@@ -3890,7 +3890,7 @@ x86_cons (exp, size)
      expressionS *exp;
      int size;
 {
-  if (size == 4 || (flag_code == CODE_64BIT && size == 8))
+  if (size == 4 || (object_64bit && size == 8))
     {
       /* Handle @GOTOFF and the like in an expression.  */
       char *save;
@@ -5319,7 +5319,10 @@ i386_target_format ()
     case bfd_target_elf_flavour:
       {
 	if (flag_code == CODE_64BIT)
-	  use_rela_relocations = 1;
+	  {
+	    object_64bit = 1;
+	    use_rela_relocations = 1;
+	  }
 	return flag_code == CODE_64BIT ? "elf64-x86-64" :
ELF_TARGET_FORMAT;
       }
 #endif
@@ -5456,13 +5459,13 @@ i386_validate_fix (fixp)
     {
       if (fixp->fx_r_type == BFD_RELOC_32_PCREL)
 	{
-	  if (flag_code != CODE_64BIT)
+	  if (!object_64bit)
 	    abort ();
 	  fixp->fx_r_type = BFD_RELOC_X86_64_GOTPCREL;
 	}
       else
 	{
-	  if (flag_code != CODE_64BIT)
+	  if (!object_64bit)
 	    fixp->fx_r_type = BFD_RELOC_386_GOTOFF;
 	  else
 	    fixp->fx_r_type = BFD_RELOC_X86_64_GOTOFF64;
@@ -5564,7 +5567,7 @@ tc_gen_reloc (section, fixp)
       && GOT_symbol
       && fixp->fx_addsy == GOT_symbol)
     {
-      if (flag_code != CODE_64BIT)
+      if (!object_64bit)
 	code = BFD_RELOC_386_GOTPC;
       else
 	code = BFD_RELOC_X86_64_GOTPC32;
---
/home/jbeulich/src/binutils/mainline/2005-08-22/gas/testsuite/gas/i386/i386.exp	2005-07-26
14:36:18.000000000 +0200
+++ 2005-08-22/gas/testsuite/gas/i386/i386.exp	2005-08-22
14:19:00.816291064 +0200
@@ -107,6 +107,7 @@ if [expr ([istarget "i*86-*-*"] ||  [ist
 	run_dump_test "bss"
 	run_dump_test "reloc32"
 	run_list_test "reloc32" "--defsym _bad_=1"
+	run_dump_test "mixed-mode-reloc32"
     }
 
     # This is a PE specific test.
@@ -150,6 +151,7 @@ if [expr ([istarget "i*86-*-*"] || [ista
     if [is_elf_format] then {
 	run_dump_test "reloc64"
 	run_list_test "reloc64" "--defsym _bad_=1"
+	run_dump_test "mixed-mode-reloc64"
     }
 
     set ASFLAGS "$old_ASFLAGS"
---
/home/jbeulich/src/binutils/mainline/2005-08-22/gas/testsuite/gas/i386/mixed-mode-reloc.s	1970-01-01
01:00:00.000000000 +0100
+++
2005-08-22/gas/testsuite/gas/i386/mixed-mode-reloc.s	2005-08-22
13:48:13.000000000 +0200
@@ -0,0 +1,16 @@
+ .text
+
+ .code16
+_start16:
+#FIXME	movl	xtrn@got(%ebx), %eax
+#FIXME	calll	xtrn@plt
+
+ .code32
+_start32:
+#FIXME	movl	xtrn@got(%ebx), %eax
+	calll	xtrn@plt
+
+ .code64
+_start64:
+	movq	xtrn@got(%rbx), %rax
+	callq	xtrn@plt
---
/home/jbeulich/src/binutils/mainline/2005-08-22/gas/testsuite/gas/i386/mixed-mode-reloc32.d	1970-01-01
01:00:00.000000000 +0100
+++
2005-08-22/gas/testsuite/gas/i386/mixed-mode-reloc32.d	2005-08-22
13:48:19.000000000 +0200
@@ -0,0 +1,14 @@
+#objdump: -r
+#source: mixed-mode-reloc.s
+#name: x86 mixed mode relocs (32-bit object)
+
+.*: +file format .*i386.*
+
+RELOCATION RECORDS FOR \[.text\]:
+OFFSET[ 	]+TYPE[ 	]+VALUE[ 	]*
+#[0-9a-f]+[ 	]+R_386_GOT32[ 	]+xtrn[ 	]*
+#[0-9a-f]+[ 	]+R_386_PLT32[ 	]+xtrn[ 	]*
+#[0-9a-f]+[ 	]+R_386_GOT32[ 	]+xtrn[ 	]*
+[0-9a-f]+[ 	]+R_386_PLT32[ 	]+xtrn[ 	]*
+[0-9a-f]+[ 	]+R_386_GOT32[ 	]+xtrn[ 	]*
+[0-9a-f]+[ 	]+R_386_PLT32[ 	]+xtrn[ 	]*
---
/home/jbeulich/src/binutils/mainline/2005-08-22/gas/testsuite/gas/i386/mixed-mode-reloc64.d	1970-01-01
01:00:00.000000000 +0100
+++
2005-08-22/gas/testsuite/gas/i386/mixed-mode-reloc64.d	2005-08-22
13:49:25.000000000 +0200
@@ -0,0 +1,14 @@
+#objdump: -r
+#source: mixed-mode-reloc.s
+#name: x86 mixed mode relocs (64-bit object)
+
+.*: +file format .*x86-64.*
+
+RELOCATION RECORDS FOR \[.text\]:
+OFFSET[ 	]+TYPE[ 	]+VALUE[ 	]*
+#[0-9a-f]+[ 	]+R_X86_64_GOT32[ 	]+xtrn[ 	]*
+#[0-9a-f]+[ 	]+R_X86_64_PLT32[ 	]+xtrn\+0xf+c[ 	]*
+#[0-9a-f]+[ 	]+R_X86_64_GOT32[ 	]+xtrn[ 	]*
+[0-9a-f]+[ 	]+R_X86_64_PLT32[ 	]+xtrn\+0xf+c[ 	]*
+[0-9a-f]+[ 	]+R_X86_64_GOT32[ 	]+xtrn[ 	]*
+[0-9a-f]+[ 	]+R_X86_64_PLT32[ 	]+xtrn\+0xf+c[ 	]*

Attachment: binutils-mainline-x86-reloc-type.patch
Description: Binary data


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