x86: Force relocation against local absolute symbol

Message ID 20200401123223.648757-1-hjl.tools@gmail.com
State New
Headers show
Series
  • x86: Force relocation against local absolute symbol
Related show

Commit Message

Alan Modra via Binutils April 1, 2020, 12:32 p.m.
Define TC_FORCE_RELOCATION_ABS to force relocation against local
absolute symbol.

	PR gas/25756
	* config/tc-i386.h (TC_FORCE_RELOCATION_ABS): New.
	* testsuite/gas/i386/localpic.s: Add a test for relocation
	against local absolute symbol.
	* testsuite/gas/i386/x86-64-localpic.s: Likewise.
	* testsuite/gas/i386/localpic.d: Updated.
	* testsuite/gas/i386/x86-64-localpic.d: Likewise.
---
 gas/config/tc-i386.h                     | 8 ++++++++
 gas/testsuite/gas/i386/localpic.d        | 4 +++-
 gas/testsuite/gas/i386/localpic.s        | 2 ++
 gas/testsuite/gas/i386/x86-64-localpic.d | 4 +++-
 gas/testsuite/gas/i386/x86-64-localpic.s | 2 ++
 5 files changed, 18 insertions(+), 2 deletions(-)

-- 
2.25.1

Patch

diff --git a/gas/config/tc-i386.h b/gas/config/tc-i386.h
index 93678c2282..cb426b5b91 100644
--- a/gas/config/tc-i386.h
+++ b/gas/config/tc-i386.h
@@ -180,6 +180,14 @@  extern int tc_i386_fix_adjustable (struct fix *);
    || (FIX)->fx_r_type == BFD_RELOC_X86_64_GOTPCRELX		\
    || (FIX)->fx_r_type == BFD_RELOC_X86_64_REX_GOTPCRELX)
 
+#define TC_FORCE_RELOCATION_ABS(FIX)				\
+  (TC_FORCE_RELOCATION (FIX)					\
+   || (FIX)->fx_r_type == BFD_RELOC_386_GOT32			\
+   || (FIX)->fx_r_type == BFD_RELOC_386_GOT32X			\
+   || (FIX)->fx_r_type == BFD_RELOC_X86_64_GOTPCREL		\
+   || (FIX)->fx_r_type == BFD_RELOC_X86_64_GOTPCRELX		\
+   || (FIX)->fx_r_type == BFD_RELOC_X86_64_REX_GOTPCRELX)
+
 extern int i386_parse_name (char *, expressionS *, char *);
 #define md_parse_name(s, e, m, c) i386_parse_name (s, e, c)
 
diff --git a/gas/testsuite/gas/i386/localpic.d b/gas/testsuite/gas/i386/localpic.d
index 88d3566412..b06137f437 100644
--- a/gas/testsuite/gas/i386/localpic.d
+++ b/gas/testsuite/gas/i386/localpic.d
@@ -2,9 +2,11 @@ 
 #readelf: -rs
 #name: i386 local PIC
 
-Relocation section '.rel.text' at offset 0x[0-9a-f]+ contains 1 entry:
+Relocation section '.rel.text' at offset 0x[0-9a-f]+ contains 2 entries:
  Offset     Info    Type            Sym.Value  Sym. Name
 [0-9a-f]+ +[0-9a-f]+ R_386_GOT32X +[0-9a-f]+ +foo
+[0-9a-f]+ +[0-9a-f]+ R_386_GOT32X +[0-9a-f]+ +bar
 #...
  +[0-9]+: +[0-9a-f]+ +[0-9a-f]+ +NOTYPE +LOCAL +DEFAULT +[0-9]+ +foo
+ +[0-9]+: +fffffff0 +[0-9a-f]+ +NOTYPE +LOCAL +DEFAULT +ABS +bar
 #pass
diff --git a/gas/testsuite/gas/i386/localpic.s b/gas/testsuite/gas/i386/localpic.s
index e63394445e..f57fb18638 100644
--- a/gas/testsuite/gas/i386/localpic.s
+++ b/gas/testsuite/gas/i386/localpic.s
@@ -3,3 +3,5 @@  foo:
 	.long 0
 	.text
 movl	foo@GOT(%ecx), %eax
+movl	bar@GOT(%ecx), %eax
+	bar = 0xfffffff0
diff --git a/gas/testsuite/gas/i386/x86-64-localpic.d b/gas/testsuite/gas/i386/x86-64-localpic.d
index 9f8b43edb0..11dddd2e80 100644
--- a/gas/testsuite/gas/i386/x86-64-localpic.d
+++ b/gas/testsuite/gas/i386/x86-64-localpic.d
@@ -2,9 +2,11 @@ 
 #readelf: -rsW
 #name: x86-64 local PIC
 
-Relocation section '.rela.text' at offset 0x[0-9a-f]+ contains 1 entry:
+Relocation section '.rela.text' at offset 0x[0-9a-f]+ contains 2 entries:
  +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
 [0-9a-f]+ +[0-9a-f]+ R_X86_64_REX_GOTPCRELX +[0-9a-f]+ +foo - 4
+[0-9a-f]+ +[0-9a-f]+ R_X86_64_REX_GOTPCRELX +[0-9a-f]+ +bar - 4
 #...
  +[0-9]+: +[0-9a-f]+ +[0-9a-f]+ +NOTYPE +LOCAL +DEFAULT +[0-9]+ +foo
+ +[0-9]+: +0+1fffffff0 +[0-9a-f]+ +NOTYPE +LOCAL +DEFAULT +ABS +bar
 #pass
diff --git a/gas/testsuite/gas/i386/x86-64-localpic.s b/gas/testsuite/gas/i386/x86-64-localpic.s
index c73a7c563b..fee508b1bc 100644
--- a/gas/testsuite/gas/i386/x86-64-localpic.s
+++ b/gas/testsuite/gas/i386/x86-64-localpic.s
@@ -2,3 +2,5 @@ 
 foo:
 	.quad 0
 	movq	foo@GOTPCREL(%rip), %rax
+	movq	bar@GOTPCREL(%rip), %rax
+	bar = 0x1fffffff0