From c64efb4be7d6e005f3768494ff671a075225b010 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Sat, 3 Jul 2010 22:15:58 +0000
Subject: [PATCH] Don't call section_symbol() with expr_section.

gas/

2010-07-03  Jan Beulich  <jbeulich@novell.com>

	PR gas/11732
	* config/tc-i386.c (i386_finalize_displacement): Don't call
	section_symbol() with expr_section.

gas/testsuite/

2010-07-03  Jan Beulich  <jbeulich@novell.com>

	PR gas/11732
	* gas/i386/i386.exp: Run new tests.
	* gas/i386/intel-got{32,64}.{s,d}: New.
---
 gas/ChangeLog                        |  6 ++++++
 gas/config/tc-i386.c                 |  3 ++-
 gas/testsuite/ChangeLog              |  6 ++++++
 gas/testsuite/gas/i386/i386.exp      |  2 ++
 gas/testsuite/gas/i386/intel-got32.d | 11 +++++++++++
 gas/testsuite/gas/i386/intel-got32.s |  7 +++++++
 gas/testsuite/gas/i386/intel-got64.d | 12 ++++++++++++
 gas/testsuite/gas/i386/intel-got64.s |  8 ++++++++
 8 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 gas/testsuite/gas/i386/intel-got32.d
 create mode 100644 gas/testsuite/gas/i386/intel-got32.s
 create mode 100644 gas/testsuite/gas/i386/intel-got64.d
 create mode 100644 gas/testsuite/gas/i386/intel-got64.s

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 50dd6c1c895..32769f71d5d 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,9 @@
+2010-07-03  Jan Beulich  <jbeulich@novell.com>
+
+	PR gas/11732
+	* config/tc-i386.c (i386_finalize_displacement): Don't call
+	section_symbol() with expr_section.
+
 2010-07-03  Cary Coutant  <ccoutant@google.com>
 
 	* Makefile.am: Add compress-debug.c and compress-debug.h.
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index d065b90fff7..281faaaf193 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -6878,7 +6878,8 @@ i386_finalize_displacement (segT exp_seg ATTRIBUTE_UNUSED, expressionS *exp,
 	goto inv_disp;
 
       if (S_IS_LOCAL (exp->X_add_symbol)
-	  && S_GET_SEGMENT (exp->X_add_symbol) != undefined_section)
+	  && S_GET_SEGMENT (exp->X_add_symbol) != undefined_section
+	  && S_GET_SEGMENT (exp->X_add_symbol) != expr_section)
 	section_symbol (S_GET_SEGMENT (exp->X_add_symbol));
       exp->X_op = O_subtract;
       exp->X_op_symbol = GOT_symbol;
diff --git a/gas/testsuite/ChangeLog b/gas/testsuite/ChangeLog
index c5f4325f35c..c8c5e2b82bb 100644
--- a/gas/testsuite/ChangeLog
+++ b/gas/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2010-07-03  Jan Beulich  <jbeulich@novell.com>
+
+	PR gas/11732
+	* gas/i386/i386.exp: Run new tests.
+	* gas/i386/intel-got{32,64}.{s,d}: New.
+
 2010-07-01  H.J. Lu  <hongjiu.lu@intel.com>
 
 	AVX Programming Reference (June, 2010)
diff --git a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.exp
index ccda6f5ac76..ecddc387f7f 100644
--- a/gas/testsuite/gas/i386/i386.exp
+++ b/gas/testsuite/gas/i386/i386.exp
@@ -37,6 +37,7 @@ if [expr ([istarget "i*86-*-*"] ||  [istarget "x86_64-*-*"]) && [gas_32_check]]
     run_dump_test "intel16"
     run_list_test "intelbad" ""
     run_dump_test "intelok"
+    run_dump_test "intel-got32"
     run_dump_test "prefix"
     run_dump_test "amd"
     run_dump_test "katmai"
@@ -321,6 +322,7 @@ if [expr ([istarget "i*86-*-*"] || [istarget "x86_64-*-*"]) && [gas_64_check]] t
       run_dump_test "x86-64-opcode-inval-intel"
     }
     run_dump_test "rexw"
+    run_dump_test "intel-got64"
     run_dump_test "x86-64-fxsave"
     run_dump_test "x86-64-fxsave-intel"
     run_dump_test "x86-64-arch-1"
diff --git a/gas/testsuite/gas/i386/intel-got32.d b/gas/testsuite/gas/i386/intel-got32.d
new file mode 100644
index 00000000000..8e5c797979a
--- /dev/null
+++ b/gas/testsuite/gas/i386/intel-got32.d
@@ -0,0 +1,11 @@
+#objdump: -dwMintel
+#name: i386 intel-got
+
+.*: +file format .*
+
+Disassembly of section .text:
+
+0+000 <_start>:
+[ 	]*[0-9a-f]+:[ 	]+8b 15 04 00 00 00[ 	]+mov[ 	]+edx,(DWORD PTR )?(ds:)?0x4
+[ 	]*[0-9a-f]+:[ 	]+c3[ 	]+ret[ 	]*
+#pass
diff --git a/gas/testsuite/gas/i386/intel-got32.s b/gas/testsuite/gas/i386/intel-got32.s
new file mode 100644
index 00000000000..af1caa912ae
--- /dev/null
+++ b/gas/testsuite/gas/i386/intel-got32.s
@@ -0,0 +1,7 @@
+.text
+.intel_syntax noprefix
+_start:
+	mov	edx, [x1@GOTOFF + x2]
+	ret
+
+.equ x2, 4
diff --git a/gas/testsuite/gas/i386/intel-got64.d b/gas/testsuite/gas/i386/intel-got64.d
new file mode 100644
index 00000000000..e16f552b00b
--- /dev/null
+++ b/gas/testsuite/gas/i386/intel-got64.d
@@ -0,0 +1,12 @@
+#objdump: -dwMintel
+#name: x86-64 intel-got
+
+.*: +file format .*
+
+Disassembly of section .text:
+
+0+000 <_start>:
+[ 	]*[0-9a-f]+:[ 	]+a1 00 00 00 00 00 00 00 00[ 	]+movabs[ 	]+eax,(ds:)?0x0
+[ 	]*[0-9a-f]+:[ 	]+ff 35 00 00 00 00[ 	]+push[ 	]+(QWORD PTR )?\[rip(\+(0x)?0)?\]([ 	]+#.*)?
+[ 	]*[0-9a-f]+:[ 	]+c3[ 	]+ret[ 	]*
+#pass
diff --git a/gas/testsuite/gas/i386/intel-got64.s b/gas/testsuite/gas/i386/intel-got64.s
new file mode 100644
index 00000000000..82988c94af0
--- /dev/null
+++ b/gas/testsuite/gas/i386/intel-got64.s
@@ -0,0 +1,8 @@
+.text
+.intel_syntax noprefix
+_start:
+	movabs	eax, [x1@GOTOFF + x2]
+	push	[rip + x1@GOTPCREL + x2]
+	ret
+
+.equ x2, 8