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]

Re: [PATCH] x86-64: Check relocations with -z nocopyreloc


On Thu, Aug 24, 2017 at 5:14 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> On x86-64, when -z nocopyreloc is used to build executable, relocations
> may overflow at run-time or may not be resolved without PIC.  This patch
> checks these conditions and issues an error with suggestion for -fPIC.
>
> bfd/
>
>         PR ld/22001
>         * elf64-x86-64.c (elf_x86_64_relocate_section): Check for
>         R_X86_64_PC32 relocation run-time overflow and unresolvable
>         R_X86_64_32S relocation with -z nocopyreloc.
>
> ld/
>
>         PR ld/22001
>         * testsuite/ld-i386/i386.exp: Run -z nocopyreloc tests.
>         * testsuite/ld-x86-64/x86-64.exp: Likewise.
>         * ld/testsuite/ld-i386/pr22001-1a.c: New file.
>         * ld/testsuite/ld-i386/pr22001-1b.c: Likewise.
>         * ld/testsuite/ld-i386/pr22001-1c.S: Likewise.
>         * ld/testsuite/ld-x86-64/pr22001-1a.c: Likewise.
>         * ld/testsuite/ld-x86-64/pr22001-1a.err: Likewise.
>         * ld/testsuite/ld-x86-64/pr22001-1b.c: Likewise.
>         * ld/testsuite/ld-x86-64/pr22001-1b.err: Likewise.
>         * ld/testsuite/ld-x86-64/pr22001-1c.c: Likewise.

I checked in this patch to run pr22001-1b on x32 since R_X86_64_32S
relocation can be turned into dynamic R_X86_64_32 relocation which
won't overflow on x32.


-- 
H.J.
From 28e6a46bcb00e9972540e4d12a98cc3f6fbb9d87 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 24 Aug 2017 07:53:41 -0700
Subject: [PATCH] x86-64: Run pr22001-1b on x32

Run pr22001-1b on x32 since R_X86_64_32S relocation can be turned into
dynamic R_X86_64_32 relocation which won't overflow on x32.

	* testsuite/ld-x86-64/x86-64.exp: Run pr22001-1b on x32.
---
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 6dc3665712..7382a1bbfe 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -1056,16 +1056,33 @@ if { [isnative] && [which $CC] != 0 } {
 	    {{error_output "pr22001-1a.err"}} \
 	    "pr22001-1a" \
 	] \
-	[list \
-	    "Build pr22001-1b" \
-	    "$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
-	    "$NOPIE_CFLAGS" \
-	    { pr22001-1c.c } \
-	    {{error_output "pr22001-1b.err"}} \
-	    "pr22001-1b" \
-	] \
     ]
 
+    if  {[istarget "x86_64-*-linux*-gnux32"]} {
+	run_ld_link_exec_tests [list \
+	    [list \
+		"Run pr22001-1b" \
+		"$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
+		"" \
+		{ pr22001-1c.c } \
+		"pr22001-1b" \
+		"pass.out" \
+		"$NOPIE_CFLAGS" \
+	    ] \
+	]
+    } else {
+	run_cc_link_tests [list \
+	    [list \
+		"Build pr22001-1b" \
+		"$NOPIE_LDFLAGS -Wl,-z,nocopyreloc,--no-as-needed tmpdir/pr22001-1.so" \
+		"$NOPIE_CFLAGS" \
+		{ pr22001-1c.c } \
+		{{error_output "pr22001-1b.err"}} \
+		"pr22001-1b" \
+	    ] \
+	]
+    }
+
     run_ld_link_exec_tests [list \
 	[list \
 	    "Run plt-main" \
-- 
2.13.5


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