This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: PR ld/9970: -pie doesn't warn missing entry symbol
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: binutils at sources dot redhat dot com
- Date: Fri, 20 Mar 2009 10:37:16 -0700
- Subject: PATCH: PR ld/9970: -pie doesn't warn missing entry symbol
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
-pie sets both link_info.shared and link_info.executable to true.
We need to test link_info.executable for -pie. We also need -fpie
for PIE. Otherwise, we will get
gcc -pie /export/gnu/src/binutils/binutils/ld/testsuite/ld-pie/pie.c -o
tmpdir/pie/usr/local/bin/ld: /tmp/ccyjSy17.o: relocation R_X86_64_32
against `a local symbol' can not be used when making a shared object;
recompile with -fPIC
/tmp/ccyjSy17.o: could not read symbols: Bad value
on Linux/x86-64. I am checking in this patch as an obvious fix.
Thanks.
H.J.
----
ld/
2009-03-20 H.J. Lu <hongjiu.lu@intel.com>
PR ld/9970
* ldlang.c (lang_end): Warn missing entry symbol for -pie.
ld/testsuite/
2009-03-20 H.J. Lu <hongjiu.lu@intel.com>
PR ld/9970
* ld-pie/pie.exp: Use -fpie to compile. Run *.d tests.
* ld-pie/start.d: New.
* ld-pie/start.s: Likewise.
--- ld/ldlang.c.foo 2009-03-05 05:49:33.000000000 -0800
+++ ld/ldlang.c 2009-03-20 10:28:37.000000000 -0700
@@ -5417,7 +5417,7 @@ lang_end (void)
bfd_boolean warn;
if ((link_info.relocatable && !link_info.gc_sections)
- || link_info.shared)
+ || (link_info.shared && !link_info.executable))
warn = entry_from_cmdline;
else
warn = TRUE;
--- ld/testsuite/ld-pie/pie.exp.foo 2009-03-20 10:24:36.000000000 -0700
+++ ld/testsuite/ld-pie/pie.exp 2009-03-20 10:26:19.000000000 -0700
@@ -28,8 +28,8 @@ if { ![istarget *-*-linux*] } {
}
# Check if -pie is supported or not.
-send_log "$CC -pie $srcdir/$subdir/pie.c -o tmpdir/pie"
-catch "exec $CC -pie $srcdir/$subdir/pie.c -o tmpdir/pie" exec_output
+send_log "$CC -fpie -pie $srcdir/$subdir/pie.c -o tmpdir/pie"
+catch "exec $CC -fpie -pie $srcdir/$subdir/pie.c -o tmpdir/pie" exec_output
send_log "$exec_output\n"
if { ![string match "" $exec_output] } {
return
@@ -41,3 +41,10 @@ set array_tests {
}
run_ld_link_exec_tests [] $array_tests
+
+set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
+foreach t $test_list {
+ # We need to strip the ".d", but can leave the dirname.
+ verbose [file rootname $t]
+ run_dump_test [file rootname $t]
+}
--- ld/testsuite/ld-pie/start.d.foo 2009-03-20 10:28:53.000000000 -0700
+++ ld/testsuite/ld-pie/start.d 2009-03-20 10:28:02.000000000 -0700
@@ -0,0 +1,8 @@
+#name: missing entry symbol
+#ld: -pie
+#warning: .*: warning: cannot find entry symbol .*
+#nm: -n
+
+#...
+[0-9a-f]+ T +foo
+#...
--- ld/testsuite/ld-pie/start.s.foo 2009-03-20 10:28:50.000000000 -0700
+++ ld/testsuite/ld-pie/start.s 2009-03-20 10:16:32.000000000 -0700
@@ -0,0 +1,4 @@
+ .text
+ .globl foo
+foo:
+ .byte 0