summaryrefslogtreecommitdiff
path: root/ld/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'ld/testsuite')
-rw-r--r--ld/testsuite/ld-elf/pr19719a.c12
-rw-r--r--ld/testsuite/ld-elf/pr19719b.c8
-rw-r--r--ld/testsuite/ld-elf/pr19719c.c8
-rw-r--r--ld/testsuite/ld-elf/pr19719d.c5
-rw-r--r--ld/testsuite/ld-elf/shared.exp60
-rw-r--r--ld/testsuite/ld-i386/i386.exp91
-rw-r--r--ld/testsuite/ld-i386/pr19636-1.s9
-rw-r--r--ld/testsuite/ld-i386/pr19636-1a.d16
-rw-r--r--ld/testsuite/ld-i386/pr19636-1b.d19
-rw-r--r--ld/testsuite/ld-i386/pr19636-1c.d9
-rw-r--r--ld/testsuite/ld-i386/pr19636-1d-nacl.d124
-rw-r--r--ld/testsuite/ld-i386/pr19636-1d.d26
-rw-r--r--ld/testsuite/ld-i386/pr19636-1e.d19
-rw-r--r--ld/testsuite/ld-i386/pr19636-1f.d19
-rw-r--r--ld/testsuite/ld-i386/pr19636-1g.d12
-rw-r--r--ld/testsuite/ld-i386/pr19636-1h.d19
-rw-r--r--ld/testsuite/ld-i386/pr19636-1i.d9
-rw-r--r--ld/testsuite/ld-i386/pr19636-2.s9
-rw-r--r--ld/testsuite/ld-i386/pr19636-2a.d19
-rw-r--r--ld/testsuite/ld-i386/pr19636-2b.d22
-rw-r--r--ld/testsuite/ld-i386/pr19636-2c-nacl.d126
-rw-r--r--ld/testsuite/ld-i386/pr19636-2c.d28
-rw-r--r--ld/testsuite/ld-i386/pr19636-2d-nacl.d21
-rw-r--r--ld/testsuite/ld-i386/pr19636-2d.d17
-rw-r--r--ld/testsuite/ld-i386/pr19636-2e-nacl.d21
-rw-r--r--ld/testsuite/ld-i386/pr19636-2e.d17
-rw-r--r--ld/testsuite/ld-i386/pr19636-3.s5
-rw-r--r--ld/testsuite/ld-i386/pr19636-3a.d10
-rw-r--r--ld/testsuite/ld-i386/pr19636-3b.d6
-rw-r--r--ld/testsuite/ld-i386/pr19636-3c.d9
-rw-r--r--ld/testsuite/ld-i386/pr19636-3d.d14
-rw-r--r--ld/testsuite/ld-i386/pr19636-3e.d14
-rw-r--r--ld/testsuite/ld-i386/pr19636-3f.d6
-rw-r--r--ld/testsuite/ld-i386/pr19636-3g.d9
-rw-r--r--ld/testsuite/ld-i386/pr19636-4.s14
-rw-r--r--ld/testsuite/ld-i386/pr19636-4a.d8
-rw-r--r--ld/testsuite/ld-i386/pr19636-4b.d10
-rw-r--r--ld/testsuite/ld-i386/pr19636-4c.d10
-rw-r--r--ld/testsuite/ld-i386/pr19636-4d.d10
-rw-r--r--ld/testsuite/ld-i386/pr19704.out1
-rw-r--r--ld/testsuite/ld-i386/pr19704a.c13
-rw-r--r--ld/testsuite/ld-i386/pr19704b.c7
-rw-r--r--ld/testsuite/ld-x86-64/pr13082-3b.d4
-rw-r--r--ld/testsuite/ld-x86-64/pr13082-4b.d4
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-1.s5
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-1a.d10
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-1b.d6
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-1c.d9
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-1d.d14
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-1e.d14
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-1f.d6
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-1g.d9
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-2.s9
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-2a.d17
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-2b.d20
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-2c.d9
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-2d-nacl.d37
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-2d.d25
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-2e.d19
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-2f.d19
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-2g.d13
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-2h.d20
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-2i.d9
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-3.s14
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-3a.d8
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-3b.d10
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-3c.d10
-rw-r--r--ld/testsuite/ld-x86-64/pr19636-3d.d10
-rw-r--r--ld/testsuite/ld-x86-64/pr19704.out1
-rw-r--r--ld/testsuite/ld-x86-64/pr19704a.c13
-rw-r--r--ld/testsuite/ld-x86-64/pr19704b.c7
-rw-r--r--ld/testsuite/ld-x86-64/x86-64.exp82
72 files changed, 1318 insertions, 6 deletions
diff --git a/ld/testsuite/ld-elf/pr19719a.c b/ld/testsuite/ld-elf/pr19719a.c
new file mode 100644
index 00000000000..72249a5777d
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr19719a.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+
+extern int foo (void);
+extern int bar (void);
+
+int
+main (void)
+{
+ if (foo () == bar ())
+ printf ("PASS\n");
+ return 0;
+}
diff --git a/ld/testsuite/ld-elf/pr19719b.c b/ld/testsuite/ld-elf/pr19719b.c
new file mode 100644
index 00000000000..6ef62685d24
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr19719b.c
@@ -0,0 +1,8 @@
+extern int __attribute__ ((weak)) fun (void);
+int
+foo (void)
+{
+ if (&fun != 0)
+ return fun ();
+ return 0;
+}
diff --git a/ld/testsuite/ld-elf/pr19719c.c b/ld/testsuite/ld-elf/pr19719c.c
new file mode 100644
index 00000000000..5c877d903ef
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr19719c.c
@@ -0,0 +1,8 @@
+extern int __attribute__ ((weak)) fun (void);
+int
+bar (void)
+{
+ if (&fun != 0)
+ return fun ();
+ return 0;
+}
diff --git a/ld/testsuite/ld-elf/pr19719d.c b/ld/testsuite/ld-elf/pr19719d.c
new file mode 100644
index 00000000000..231eeef9857
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr19719d.c
@@ -0,0 +1,5 @@
+int
+fun (void)
+{
+ return 20;
+}
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index a8644304cc9..e615f55b951 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -582,3 +582,63 @@ if { [istarget *-*-linux*]
] \
]
}
+
+proc mix_pic_and_non_pic {cflags ldflags} {
+ set testname "Mixing PIC and non-PIC"
+ if { ![ string match "" $cflags$ldflags] } {
+ set testname "$testname ($cflags $ldflags)"
+ }
+
+ run_cc_link_tests [list \
+ [list \
+ "Build libpr19719a.so" \
+ "-shared -Wl,-soname,libpr19719.so" \
+ "-fPIC" \
+ { pr19719d.c } \
+ {} \
+ "libpr19719a.so" \
+ ] \
+ [list \
+ "Build libpr19719b.so" \
+ "-shared -Wl,-soname,libpr19719.so" \
+ "-fPIC" \
+ { dummy.c } \
+ {} \
+ "libpr19719b.so" \
+ ] \
+ [list \
+ "Build pr19073b.o" \
+ "-r -nostdlib" \
+ "-fPIC" \
+ { pr19719b.c } \
+ {} \
+ "libpr19719b.o" \
+ ] \
+ ]
+
+ exec cp tmpdir/libpr19719b.so tmpdir/libpr19719.so
+
+ run_ld_link_exec_tests [] [list \
+ [list \
+ "Run pr19719" \
+ "$ldflags tmpdir/libpr19719b.o tmpdir/libpr19719.so -R tmpdir" \
+ "" \
+ { pr19719a.c pr19719c.c } \
+ "pr19719" \
+ "pass.out" \
+ "$cflags" \
+ ] \
+ ]
+
+ exec cp tmpdir/libpr19719a.so tmpdir/libpr19719.so
+
+ set exec_output [run_host_cmd tmpdir/pr19719 ""]
+ if {![string match "PASS" $exec_output]} {
+ fail $testname
+ } else {
+ pass $testname
+ }
+}
+
+mix_pic_and_non_pic "" ""
+mix_pic_and_non_pic "-fPIE" "-pie"
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index 1a79694943b..ab8f017c937 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -320,6 +320,35 @@ run_dump_test "load5b"
run_dump_test "load6"
run_dump_test "pr19175"
run_dump_test "pr19615"
+run_dump_test "pr19636-1a"
+run_dump_test "pr19636-1b"
+run_dump_test "pr19636-1c"
+run_dump_test "pr19636-1d"
+run_dump_test "pr19636-1d-nacl"
+run_dump_test "pr19636-1e"
+run_dump_test "pr19636-1f"
+run_dump_test "pr19636-1g"
+run_dump_test "pr19636-1h"
+run_dump_test "pr19636-1i"
+run_dump_test "pr19636-2a"
+run_dump_test "pr19636-2b"
+run_dump_test "pr19636-2c"
+run_dump_test "pr19636-2c-nacl"
+run_dump_test "pr19636-2d"
+run_dump_test "pr19636-2d-nacl"
+run_dump_test "pr19636-2e"
+run_dump_test "pr19636-2e-nacl"
+run_dump_test "pr19636-3a"
+run_dump_test "pr19636-3b"
+run_dump_test "pr19636-3c"
+run_dump_test "pr19636-3d"
+run_dump_test "pr19636-3e"
+run_dump_test "pr19636-3f"
+run_dump_test "pr19636-3g"
+run_dump_test "pr19636-4a"
+run_dump_test "pr19636-4b"
+run_dump_test "pr19636-4c"
+run_dump_test "pr19636-4d"
if { !([istarget "i?86-*-linux*"]
|| [istarget "i?86-*-gnu*"]
@@ -339,6 +368,62 @@ run_dump_test "pr17935-2"
run_dump_test "pr18801"
run_dump_test "pr18815"
+proc undefined_weak {cflags ldflags} {
+ set testname "Undefined weak symbol"
+ if { ![ string match "" $cflags$ldflags] } {
+ set testname "$testname ($cflags $ldflags)"
+ }
+
+ if { [ regexp "\-fPIE" $cflags]
+ && ![ regexp "\-z nodynamic-undefined-weak" $ldflags] } {
+ set weak_symbol "Weak defined"
+ } else {
+ set weak_symbol "Weak undefined"
+ }
+
+ run_cc_link_tests [list \
+ [list \
+ "Build libpr19704a.so" \
+ "-shared -Wl,-soname,libpr19704.so" \
+ "" \
+ { dummy.s } \
+ {} \
+ "libpr19704a.so" \
+ ] \
+ [list \
+ "Build libpr19704b.so" \
+ "-shared -Wl,-soname,libpr19704.so" \
+ "-fPIC" \
+ { pr19704b.c } \
+ {} \
+ "libpr19704b.so" \
+ ] \
+ ]
+
+ exec cp tmpdir/libpr19704a.so tmpdir/libpr19704.so
+
+ run_ld_link_exec_tests [] [list \
+ [list \
+ "Run pr19704" \
+ "$ldflags tmpdir/libpr19704.so -R tmpdir" \
+ "" \
+ { pr19704a.c } \
+ "pr19704" \
+ "pr19704.out" \
+ "$cflags" \
+ ] \
+ ]
+
+ exec cp tmpdir/libpr19704b.so tmpdir/libpr19704.so
+
+ set exec_output [run_host_cmd tmpdir/pr19704 ""]
+ if {![string match $weak_symbol $exec_output]} {
+ fail $testname
+ } else {
+ pass $testname
+ }
+}
+
# Add $PLT_CFLAGS if PLT is expected.
global PLT_CFLAGS
@@ -636,6 +721,12 @@ if { [isnative]
"got1.out" \
] \
]
+
+ undefined_weak "" ""
+ undefined_weak "-fPIE" ""
+ undefined_weak "-fPIE" "-pie"
+ undefined_weak "-fPIE" "-z nodynamic-undefined-weak"
+ undefined_weak "-fPIE" "-pie -z nodynamic-undefined-weak"
}
if { !([istarget "i?86-*-linux*"]
diff --git a/ld/testsuite/ld-i386/pr19636-1.s b/ld/testsuite/ld-i386/pr19636-1.s
new file mode 100644
index 00000000000..b2bc4df15ca
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-1.s
@@ -0,0 +1,9 @@
+ .text
+ .weak func1
+ .weak func2
+ .weak func3
+ .globl _start
+_start:
+ cmp func1@GOT(%eax), %eax
+ jmp *func2@GOT(%eax)
+ call func3@PLT
diff --git a/ld/testsuite/ld-i386/pr19636-1a.d b/ld/testsuite/ld-i386/pr19636-1a.d
new file mode 100644
index 00000000000..e96a46009dd
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-1a.d
@@ -0,0 +1,16 @@
+#source: pr19636-1.s
+#as: --32 -mrelax-relocations=no
+#ld: -pie -m elf_i386 -z nodynamic-undefined-weak
+#readelf : -r --wide -x .got -x .got.plt --dyn-syms
+
+There are no relocations in this file.
+
+Symbol table '\.dynsym' contains 1 entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+ +0: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND +
+
+Hex dump of section '.got':
+ 0x[0-9a-f]+ [0 ]+\.+
+
+Hex dump of section '.got.plt':
+ 0x[0-9a-f]+ +[0-9a-f]+ +[0 ]+ .\.+
diff --git a/ld/testsuite/ld-i386/pr19636-1b.d b/ld/testsuite/ld-i386/pr19636-1b.d
new file mode 100644
index 00000000000..5bce6cc6dfb
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-1b.d
@@ -0,0 +1,19 @@
+#source: pr19636-1.s
+#as: --32 -mrelax-relocations=no
+#ld: -pie -E -m elf_i386 -z nodynamic-undefined-weak
+#readelf : -r --wide -x .got -x .got.plt --dyn-syms
+
+There are no relocations in this file.
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+ +0: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND +
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +GLOBAL +DEFAULT +[0-9]+ +_start
+#...
+
+Hex dump of section '.got':
+ 0x[0-9a-f]+ [0 ]+\.+
+
+Hex dump of section '.got.plt':
+ 0x[0-9a-f]+ +[0-9a-f]+ +[0 ]+ .\.+
diff --git a/ld/testsuite/ld-i386/pr19636-1c.d b/ld/testsuite/ld-i386/pr19636-1c.d
new file mode 100644
index 00000000000..baf5aa3350a
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-1c.d
@@ -0,0 +1,9 @@
+#source: pr19636-1.s
+#as: --32 -mrelax-relocations=no
+#ld: -pie -E -m elf_i386 -z nodynamic-undefined-weak
+#readelf : --wide --dyn-syms
+
+#failif
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func[0-9]?
+#...
diff --git a/ld/testsuite/ld-i386/pr19636-1d-nacl.d b/ld/testsuite/ld-i386/pr19636-1d-nacl.d
new file mode 100644
index 00000000000..7ff0e895cdc
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-1d-nacl.d
@@ -0,0 +1,124 @@
+#source: pr19636-1.s
+#as: --32 -mrelax-relocations=no
+#ld: -pie -m elf_i386 -z nodynamic-undefined-weak
+#objdump: -dw
+#target: i?86-*-nacl* x86_64-*-nacl*
+
+.*: +file format .*
+
+
+Disassembly of section .plt:
+
+0+ <.plt>:
+[ ]*[a-f0-9]+: ff 73 04 pushl 0x4\(%ebx\)
+[ ]*[a-f0-9]+: 8b 4b 08 mov 0x8\(%ebx\),%ecx
+[ ]*[a-f0-9]+: 83 e1 e0 and \$0xffffffe0,%ecx
+[ ]*[a-f0-9]+: ff e1 jmp \*%ecx
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 8b 8b 0c 00 00 00 mov 0xc\(%ebx\),%ecx
+[ ]*[a-f0-9]+: 83 e1 e0 and \$0xffffffe0,%ecx
+[ ]*[a-f0-9]+: ff e1 jmp \*%ecx
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 68 00 00 00 00 push \$0x0
+[ ]*[a-f0-9]+: e9 00 00 00 00 jmp 6a <_start-0x16>
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+
+Disassembly of section .text:
+
+0+80 <_start>:
+[ ]*[a-f0-9]+: 3b 80 f8 ff ff ff cmp -0x8\(%eax\),%eax
+[ ]*[a-f0-9]+: ff a0 fc ff ff ff jmp \*-0x4\(%eax\)
+[ ]*[a-f0-9]+: e8 af ff ff ff call 40 <_start-0x40>
diff --git a/ld/testsuite/ld-i386/pr19636-1d.d b/ld/testsuite/ld-i386/pr19636-1d.d
new file mode 100644
index 00000000000..d413b87d5b2
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-1d.d
@@ -0,0 +1,26 @@
+#source: pr19636-1.s
+#as: --32 -mrelax-relocations=no
+#ld: -pie -m elf_i386 -z nodynamic-undefined-weak
+#objdump: -dw
+#notarget: i?86-*-nacl* x86_64-*-nacl*
+
+.*: +file format .*
+
+
+Disassembly of section .plt:
+
+0+110 <.plt>:
+[ ]*[a-f0-9]+: ff b3 04 00 00 00 pushl 0x4\(%ebx\)
+[ ]*[a-f0-9]+: ff a3 08 00 00 00 jmp \*0x8\(%ebx\)
+[ ]*[a-f0-9]+: 00 00 add %al,\(%eax\)
+[ ]*[a-f0-9]+: 00 00 add %al,\(%eax\)
+[ ]*[a-f0-9]+: ff a3 0c 00 00 00 jmp \*0xc\(%ebx\)
+[ ]*[a-f0-9]+: 68 00 00 00 00 push \$0x0
+[ ]*[a-f0-9]+: e9 00 00 00 00 jmp [a-f0-9]+ <.*>
+
+Disassembly of section .text:
+
+0+130 <_start>:
+[ ]*[a-f0-9]+: 3b 80 f8 ff ff ff cmp -0x8\(%eax\),%eax
+[ ]*[a-f0-9]+: ff a0 fc ff ff ff jmp \*-0x4\(%eax\)
+[ ]*[a-f0-9]+: e8 df ff ff ff call 120 <_start-0x10>
diff --git a/ld/testsuite/ld-i386/pr19636-1e.d b/ld/testsuite/ld-i386/pr19636-1e.d
new file mode 100644
index 00000000000..bcabd4d2012
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-1e.d
@@ -0,0 +1,19 @@
+#source: pr19636-1.s
+#as: --32 -mrelax-relocations=no
+#ld: -shared -m elf_i386 -z nodynamic-undefined-weak
+#readelf : -r --wide --dyn-syms
+
+Relocation section '\.rel\.dyn' at offset [0x0-9a-f]+ contains 2 entries:
+ +Offset +Info +Type +Sym. Value +Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_GLOB_DAT +0+ +func1
+[0-9a-f]+ +[0-9a-f]+ +R_386_GLOB_DAT +0+ +func2
+
+Relocation section '\.rel\.plt' at offset 0x[0-9a-f]+ contains 1 entries:
+ +Offset +Info +Type +Sym. Value +Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_JUMP_SLOT +0+ +func3
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func[0-9]?
+#pass
diff --git a/ld/testsuite/ld-i386/pr19636-1f.d b/ld/testsuite/ld-i386/pr19636-1f.d
new file mode 100644
index 00000000000..52513fc8b73
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-1f.d
@@ -0,0 +1,19 @@
+#source: pr19636-1.s
+#as: --32 -mrelax-relocations=no
+#ld: -shared -Bsymbolic -m elf_i386 -z nodynamic-undefined-weak
+#readelf : -r --wide --dyn-syms
+
+Relocation section '\.rel\.dyn' at offset [0x0-9a-f]+ contains 2 entries:
+ +Offset +Info +Type +Sym. Value +Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_GLOB_DAT +0+ +func1
+[0-9a-f]+ +[0-9a-f]+ +R_386_GLOB_DAT +0+ +func2
+
+Relocation section '\.rel\.plt' at offset 0x[0-9a-f]+ contains 1 entries:
+ +Offset +Info +Type +Sym. Value +Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_JUMP_SLOT +0+ +func3
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func[0-9]?
+#pass
diff --git a/ld/testsuite/ld-i386/pr19636-1g.d b/ld/testsuite/ld-i386/pr19636-1g.d
new file mode 100644
index 00000000000..9cd44728d31
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-1g.d
@@ -0,0 +1,12 @@
+#source: pr19636-1.s
+#as: --32 -mrelax-relocations=no
+#ld: -m elf_i386 -z nodynamic-undefined-weak
+#readelf : -r --wide -x .got -x .got.plt --dyn-syms
+
+There are no relocations in this file.
+
+Hex dump of section '.got':
+ 0x[0-9a-f]+ [0 ]+\.+
+
+Hex dump of section '.got.plt':
+ 0x[0-9a-f]+ [0 ]+\.+
diff --git a/ld/testsuite/ld-i386/pr19636-1h.d b/ld/testsuite/ld-i386/pr19636-1h.d
new file mode 100644
index 00000000000..ed06d2f232e
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-1h.d
@@ -0,0 +1,19 @@
+#source: pr19636-1.s
+#as: --32 -mrelax-relocations=no
+#ld: -E -m elf_i386 -z nodynamic-undefined-weak
+#readelf : -r --wide -x .got -x .got.plt --dyn-syms
+
+There are no relocations in this file.
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+ +0: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND +
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +GLOBAL +DEFAULT +[0-9]+ +_start
+#...
+
+Hex dump of section '.got':
+ 0x[0-9a-f]+ [0 ]+\.+
+
+Hex dump of section '.got.plt':
+ 0x[0-9a-f]+ +[0-9a-f]+ +[0 ]+ .\.+
diff --git a/ld/testsuite/ld-i386/pr19636-1i.d b/ld/testsuite/ld-i386/pr19636-1i.d
new file mode 100644
index 00000000000..c65a267f3bb
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-1i.d
@@ -0,0 +1,9 @@
+#source: pr19636-1.s
+#as: --32 -mrelax-relocations=no
+#ld: -E -m elf_i386 -z nodynamic-undefined-weak
+#readelf : --wide --dyn-syms
+
+#failif
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func[0-9]?
+#...
diff --git a/ld/testsuite/ld-i386/pr19636-2.s b/ld/testsuite/ld-i386/pr19636-2.s
new file mode 100644
index 00000000000..e8e7c9f953e
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-2.s
@@ -0,0 +1,9 @@
+ .text
+ .weak func
+ .globl _start
+_start:
+ cmp func@GOT(%eax), %eax
+ jmp *func@GOT(%eax)
+ call func@PLT
+ cmp $func, %eax
+ call func
diff --git a/ld/testsuite/ld-i386/pr19636-2a.d b/ld/testsuite/ld-i386/pr19636-2a.d
new file mode 100644
index 00000000000..fbed7e7ad3d
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-2a.d
@@ -0,0 +1,19 @@
+#source: pr19636-2.s
+#as: --32 -mrelax-relocations=no
+#ld: -pie -m elf_i386
+#readelf : -r --wide -x .got -x .got.plt --dyn-syms
+
+Relocation section '\.rel\.dyn' at offset [0x0-9a-f]+ contains 1 entries:
+ +Offset +Info +Type +Sym. Value +Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_PC32 +0+ +func
+
+Symbol table '\.dynsym' contains 2 entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+ +0: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND +
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func
+
+Hex dump of section '.got':
+ 0x[0-9a-f]+ [0 ]+\.+
+
+Hex dump of section '.got.plt':
+ 0x[0-9a-f]+ +[0-9a-f]+ +[0 ]+ .\.+
diff --git a/ld/testsuite/ld-i386/pr19636-2b.d b/ld/testsuite/ld-i386/pr19636-2b.d
new file mode 100644
index 00000000000..9a0a26314ee
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-2b.d
@@ -0,0 +1,22 @@
+#source: pr19636-2.s
+#as: --32 -mrelax-relocations=no
+#ld: -pie -E -m elf_i386
+#readelf : -r --wide -x .got -x .got.plt --dyn-syms
+
+Relocation section '\.rel\.dyn' at offset [0x0-9a-f]+ contains 1 entries:
+ +Offset +Info +Type +Sym. Value +Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_PC32 +0+ +func
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +GLOBAL +DEFAULT +[0-9]+ +_start
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func
+#...
+
+Hex dump of section '.got':
+ 0x[0-9a-f]+ [0 ]+\.+
+
+Hex dump of section '.got.plt':
+ 0x[0-9a-f]+ +[0-9a-f]+ +[0 ]+ .\.+
diff --git a/ld/testsuite/ld-i386/pr19636-2c-nacl.d b/ld/testsuite/ld-i386/pr19636-2c-nacl.d
new file mode 100644
index 00000000000..7543e0e2ac2
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-2c-nacl.d
@@ -0,0 +1,126 @@
+#source: pr19636-2.s
+#as: --32 -mrelax-relocations=no
+#ld: -pie -m elf_i386
+#objdump: -dw
+#target: i?86-*-nacl* x86_64-*-nacl*
+
+.*: +file format .*
+
+
+Disassembly of section .plt:
+
+0+ <.plt>:
+[ ]*[a-f0-9]+: ff 73 04 pushl 0x4\(%ebx\)
+[ ]*[a-f0-9]+: 8b 4b 08 mov 0x8\(%ebx\),%ecx
+[ ]*[a-f0-9]+: 83 e1 e0 and \$0xffffffe0,%ecx
+[ ]*[a-f0-9]+: ff e1 jmp \*%ecx
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 8b 8b 0c 00 00 00 mov 0xc\(%ebx\),%ecx
+[ ]*[a-f0-9]+: 83 e1 e0 and \$0xffffffe0,%ecx
+[ ]*[a-f0-9]+: ff e1 jmp \*%ecx
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 68 00 00 00 00 push \$0x0
+[ ]*[a-f0-9]+: e9 00 00 00 00 jmp 6a <_start-0x16>
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+[ ]*[a-f0-9]+: 90 nop
+
+Disassembly of section .text:
+
+0+80 <_start>:
+[ ]*[a-f0-9]+: 3b 80 fc ff ff ff cmp -0x4\(%eax\),%eax
+[ ]*[a-f0-9]+: ff a0 fc ff ff ff jmp \*-0x4\(%eax\)
+[ ]*[a-f0-9]+: e8 af ff ff ff call 40 <_start-0x40>
+[ ]*[a-f0-9]+: 3d 00 00 00 00 cmp \$0x0,%eax
+[ ]*[a-f0-9]+: e8 fc ff ff ff call 97 <_start\+0x17>
diff --git a/ld/testsuite/ld-i386/pr19636-2c.d b/ld/testsuite/ld-i386/pr19636-2c.d
new file mode 100644
index 00000000000..98b53aaf0de
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-2c.d
@@ -0,0 +1,28 @@
+#source: pr19636-2.s
+#as: --32 -mrelax-relocations=no
+#ld: -pie -m elf_i386
+#objdump: -dw
+#notarget: i?86-*-nacl* x86_64-*-nacl*
+
+.*: +file format .*
+
+
+Disassembly of section .plt:
+
+0+130 <.plt>:
+[ ]*[a-f0-9]+: ff b3 04 00 00 00 pushl 0x4\(%ebx\)
+[ ]*[a-f0-9]+: ff a3 08 00 00 00 jmp \*0x8\(%ebx\)
+[ ]*[a-f0-9]+: 00 00 add %al,\(%eax\)
+[ ]*[a-f0-9]+: 00 00 add %al,\(%eax\)
+[ ]*[a-f0-9]+: ff a3 0c 00 00 00 jmp \*0xc\(%ebx\)
+[ ]*[a-f0-9]+: 68 00 00 00 00 push \$0x0
+[ ]*[a-f0-9]+: e9 00 00 00 00 jmp 150 <_start>
+
+Disassembly of section .text:
+
+0+150 <_start>:
+[ ]*[a-f0-9]+: 3b 80 fc ff ff ff cmp -0x4\(%eax\),%eax
+[ ]*[a-f0-9]+: ff a0 fc ff ff ff jmp \*-0x4\(%eax\)
+[ ]*[a-f0-9]+: e8 df ff ff ff call 140 <_start-0x10>
+[ ]*[a-f0-9]+: 3d 00 00 00 00 cmp \$0x0,%eax
+[ ]*[a-f0-9]+: e8 fc ff ff ff call 167 <_start\+0x17>
diff --git a/ld/testsuite/ld-i386/pr19636-2d-nacl.d b/ld/testsuite/ld-i386/pr19636-2d-nacl.d
new file mode 100644
index 00000000000..99c491f58e8
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-2d-nacl.d
@@ -0,0 +1,21 @@
+#source: pr19636-2.s
+#as: --32 -mrelax-relocations=no
+#ld: -shared -m elf_i386
+#readelf : -r --wide --dyn-syms
+#target: i?86-*-nacl* x86_64-*-nacl*
+
+Relocation section '\.rel\.dyn' at offset [0x0-9a-f]+ contains 3 entries:
+ +Offset +Info +Type +Sym. Value +Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_32 +0+ +func
+[0-9a-f]+ +[0-9a-f]+ +R_386_PC32 +0+ +func
+[0-9a-f]+ +[0-9a-f]+ +R_386_GLOB_DAT +0+ +func
+
+Relocation section '\.rel\.plt' at offset [0x0-9a-f]+ contains 1 entries:
+ +Offset +Info +Type +Sym. Value +Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_JUMP_SLOT +0+ +func
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func
+#pass
diff --git a/ld/testsuite/ld-i386/pr19636-2d.d b/ld/testsuite/ld-i386/pr19636-2d.d
new file mode 100644
index 00000000000..28eaa04d2bb
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-2d.d
@@ -0,0 +1,17 @@
+#source: pr19636-2.s
+#as: --32 -mrelax-relocations=no
+#ld: -shared -m elf_i386
+#readelf : -r --wide --dyn-syms
+#notarget: i?86-*-nacl* x86_64-*-nacl*
+
+Relocation section '\.rel\.dyn' at offset [0x0-9a-f]+ contains 3 entries:
+ +Offset +Info +Type +Sym. Value +Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_32 +0+ +func
+[0-9a-f]+ +[0-9a-f]+ +R_386_PC32 +0+ +func
+[0-9a-f]+ +[0-9a-f]+ +R_386_GLOB_DAT +0+ +func
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func
+#pass
diff --git a/ld/testsuite/ld-i386/pr19636-2e-nacl.d b/ld/testsuite/ld-i386/pr19636-2e-nacl.d
new file mode 100644
index 00000000000..f791128b8c0
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-2e-nacl.d
@@ -0,0 +1,21 @@
+#source: pr19636-2.s
+#as: --32 -mrelax-relocations=no
+#ld: -shared -Bsymbolic -m elf_i386
+#readelf : -r --wide --dyn-syms
+#target: i?86-*-nacl* x86_64-*-nacl*
+
+Relocation section '\.rel\.dyn' at offset [0x0-9a-f]+ contains 3 entries:
+ +Offset +Info +Type +Sym. Value +Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_32 +0+ +func
+[0-9a-f]+ +[0-9a-f]+ +R_386_PC32 +0+ +func
+[0-9a-f]+ +[0-9a-f]+ +R_386_GLOB_DAT +0+ +func
+
+Relocation section '\.rel\.plt' at offset [0x0-9a-f]+ contains 1 entries:
+ +Offset +Info +Type +Sym. Value +Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_JUMP_SLOT +0+ +func
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func
+#pass
diff --git a/ld/testsuite/ld-i386/pr19636-2e.d b/ld/testsuite/ld-i386/pr19636-2e.d
new file mode 100644
index 00000000000..148e3060a7f
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-2e.d
@@ -0,0 +1,17 @@
+#source: pr19636-2.s
+#as: --32 -mrelax-relocations=no
+#ld: -shared -Bsymbolic -m elf_i386
+#readelf : -r --wide --dyn-syms
+#notarget: i?86-*-nacl* x86_64-*-nacl*
+
+Relocation section '\.rel\.dyn' at offset [0x0-9a-f]+ contains 3 entries:
+ +Offset +Info +Type +Sym. Value +Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_32 +0+ +func
+[0-9a-f]+ +[0-9a-f]+ +R_386_PC32 +0+ +func
+[0-9a-f]+ +[0-9a-f]+ +R_386_GLOB_DAT +0+ +func
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func
+#pass
diff --git a/ld/testsuite/ld-i386/pr19636-3.s b/ld/testsuite/ld-i386/pr19636-3.s
new file mode 100644
index 00000000000..9bd7e4a819f
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-3.s
@@ -0,0 +1,5 @@
+ .text
+ .weak func
+ .globl _start
+_start:
+ .dc.a func
diff --git a/ld/testsuite/ld-i386/pr19636-3a.d b/ld/testsuite/ld-i386/pr19636-3a.d
new file mode 100644
index 00000000000..078896ebecb
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-3a.d
@@ -0,0 +1,10 @@
+#source: pr19636-3.s
+#as: --32
+#ld: -pie -m elf_i386
+#readelf : -r --dyn-syms --wide
+
+There are no relocations in this file.
+
+Symbol table '\.dynsym' contains 1 entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+ +0: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND +
diff --git a/ld/testsuite/ld-i386/pr19636-3b.d b/ld/testsuite/ld-i386/pr19636-3b.d
new file mode 100644
index 00000000000..e8f9138ef6f
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-3b.d
@@ -0,0 +1,6 @@
+#source: pr19636-3.s
+#as: --32
+#ld: -pie -E -m elf_i386
+#readelf : -r --wide
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-i386/pr19636-3c.d b/ld/testsuite/ld-i386/pr19636-3c.d
new file mode 100644
index 00000000000..701b131b23d
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-3c.d
@@ -0,0 +1,9 @@
+#source: pr19636-3.s
+#as: --32
+#ld: -pie -E -m elf_i386
+#readelf : --dyn-syms --wide
+
+#failif
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func
+#...
diff --git a/ld/testsuite/ld-i386/pr19636-3d.d b/ld/testsuite/ld-i386/pr19636-3d.d
new file mode 100644
index 00000000000..12ff6b86b6f
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-3d.d
@@ -0,0 +1,14 @@
+#source: pr19636-3.s
+#as: --32
+#ld: -shared -m elf_i386
+#readelf : -r --wide --dyn-syms
+
+Relocation section '\.rela?\..*' at offset 0x[0-9a-f]+ contains [0-9]+ entries:
+#...
+[0-9a-f]+[ \t]+[0-9a-f]+[ \t]+R_.*[ \t]+[0-9a-f]+[ \t]+func.*
+#...
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func
+#...
diff --git a/ld/testsuite/ld-i386/pr19636-3e.d b/ld/testsuite/ld-i386/pr19636-3e.d
new file mode 100644
index 00000000000..a0f3344b9b7
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-3e.d
@@ -0,0 +1,14 @@
+#source: pr19636-3.s
+#as: --32
+#ld: -shared -Bsymbolic -m elf_i386
+#readelf : -r --wide --dyn-syms
+
+Relocation section '\.rela?\..*' at offset 0x[0-9a-f]+ contains [0-9]+ entries:
+#...
+[0-9a-f]+[ \t]+[0-9a-f]+[ \t]+R_.*[ \t]+[0-9a-f]+[ \t]+func.*
+#...
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func
+#...
diff --git a/ld/testsuite/ld-i386/pr19636-3f.d b/ld/testsuite/ld-i386/pr19636-3f.d
new file mode 100644
index 00000000000..858850b9d4a
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-3f.d
@@ -0,0 +1,6 @@
+#source: pr19636-3.s
+#as: --32
+#ld: -E -m elf_i386
+#readelf : -r --wide
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-i386/pr19636-3g.d b/ld/testsuite/ld-i386/pr19636-3g.d
new file mode 100644
index 00000000000..1b0d6689648
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-3g.d
@@ -0,0 +1,9 @@
+#source: pr19636-3.s
+#as: --32
+#ld: -E -m elf_i386
+#readelf : --dyn-syms --wide
+
+#failif
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func
+#...
diff --git a/ld/testsuite/ld-i386/pr19636-4.s b/ld/testsuite/ld-i386/pr19636-4.s
new file mode 100644
index 00000000000..6c981f5e034
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-4.s
@@ -0,0 +1,14 @@
+ .text
+ .type start,"function"
+ .global start
+start:
+ .type _start,"function"
+ .global _start
+_start:
+ .type __start,"function"
+ .global __start
+__start:
+ .type main,"function"
+ .global main
+main:
+ .long 0
diff --git a/ld/testsuite/ld-i386/pr19636-4a.d b/ld/testsuite/ld-i386/pr19636-4a.d
new file mode 100644
index 00000000000..8cdbc1c498e
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-4a.d
@@ -0,0 +1,8 @@
+#source: pr19636-4.s
+#as: --32
+#ld: -pie --defsym foobar=0x100 -m elf_i386
+#readelf : --dyn-syms --wide
+
+Symbol table '\.dynsym' contains 1 entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+ +0: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND +
diff --git a/ld/testsuite/ld-i386/pr19636-4b.d b/ld/testsuite/ld-i386/pr19636-4b.d
new file mode 100644
index 00000000000..7ac3629071b
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-4b.d
@@ -0,0 +1,10 @@
+#source: pr19636-4.s
+#as: --32
+#ld: -pie -E --defsym foobar=0x100 -m elf_i386
+#readelf : --dyn-syms --wide
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +0+100 +0 +NOTYPE +GLOBAL +DEFAULT +ABS +foobar
+#pass
diff --git a/ld/testsuite/ld-i386/pr19636-4c.d b/ld/testsuite/ld-i386/pr19636-4c.d
new file mode 100644
index 00000000000..a3891c44cb7
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-4c.d
@@ -0,0 +1,10 @@
+#source: pr19636-4.s
+#as: --32
+#ld: -shared -Bsymbolic --defsym foobar=0x100 -m elf_i386
+#readelf : --dyn-syms --wide
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +0+100 +0 +NOTYPE +GLOBAL +DEFAULT +ABS +foobar
+#pass
diff --git a/ld/testsuite/ld-i386/pr19636-4d.d b/ld/testsuite/ld-i386/pr19636-4d.d
new file mode 100644
index 00000000000..a9487f0be64
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19636-4d.d
@@ -0,0 +1,10 @@
+#source: pr19636-4.s
+#as: --32
+#ld: -E --defsym foobar=0x100 -m elf_i386
+#readelf : --dyn-syms --wide
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +0+100 +0 +NOTYPE +GLOBAL +DEFAULT +ABS +foobar
+#pass
diff --git a/ld/testsuite/ld-i386/pr19704.out b/ld/testsuite/ld-i386/pr19704.out
new file mode 100644
index 00000000000..3506f46c914
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19704.out
@@ -0,0 +1 @@
+Weak undefined
diff --git a/ld/testsuite/ld-i386/pr19704a.c b/ld/testsuite/ld-i386/pr19704a.c
new file mode 100644
index 00000000000..aa52e0011d2
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19704a.c
@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+extern int __attribute__ ((weak)) fun (void);
+
+int
+main (void)
+{
+ if (&fun != 0)
+ fun ();
+ else
+ printf ("Weak undefined\n");
+ return 0;
+}
diff --git a/ld/testsuite/ld-i386/pr19704b.c b/ld/testsuite/ld-i386/pr19704b.c
new file mode 100644
index 00000000000..1d688e13dc8
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19704b.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+void
+fun (void)
+{
+ printf ("Weak defined\n");
+}
diff --git a/ld/testsuite/ld-x86-64/pr13082-3b.d b/ld/testsuite/ld-x86-64/pr13082-3b.d
index 12efaf09646..766dd741bbb 100644
--- a/ld/testsuite/ld-x86-64/pr13082-3b.d
+++ b/ld/testsuite/ld-x86-64/pr13082-3b.d
@@ -4,6 +4,4 @@
#ld: -pie -melf32_x86_64
#readelf: -r --wide
-Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries:
- Offset Info Type Sym. Value Symbol's Name \+ Addend
-[0-9a-f]+ +[0-9a-f]+ +R_X86_64_32 +[0-9a-f]+ +func \+ 0
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-x86-64/pr13082-4b.d b/ld/testsuite/ld-x86-64/pr13082-4b.d
index cb4d90af198..6d4a35b7d65 100644
--- a/ld/testsuite/ld-x86-64/pr13082-4b.d
+++ b/ld/testsuite/ld-x86-64/pr13082-4b.d
@@ -4,6 +4,4 @@
#ld: -pie -melf32_x86_64
#readelf: -r --wide
-Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries:
- Offset Info Type Sym. Value Symbol's Name \+ Addend
-[0-9a-f]+ +[0-9a-f]+ +R_X86_64_64 +[0-9a-f]+ +func \+ 1
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-x86-64/pr19636-1.s b/ld/testsuite/ld-x86-64/pr19636-1.s
new file mode 100644
index 00000000000..9bd7e4a819f
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-1.s
@@ -0,0 +1,5 @@
+ .text
+ .weak func
+ .globl _start
+_start:
+ .dc.a func
diff --git a/ld/testsuite/ld-x86-64/pr19636-1a.d b/ld/testsuite/ld-x86-64/pr19636-1a.d
new file mode 100644
index 00000000000..5cdfcb972eb
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-1a.d
@@ -0,0 +1,10 @@
+#source: pr19636-1.s
+#as: --64
+#ld: -pie -m elf_x86_64
+#readelf : -r --dyn-syms --wide
+
+There are no relocations in this file.
+
+Symbol table '\.dynsym' contains 1 entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+ +0: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND +
diff --git a/ld/testsuite/ld-x86-64/pr19636-1b.d b/ld/testsuite/ld-x86-64/pr19636-1b.d
new file mode 100644
index 00000000000..e68e399ab0a
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-1b.d
@@ -0,0 +1,6 @@
+#source: pr19636-1.s
+#as: --64
+#ld: -pie -E -m elf_x86_64
+#readelf : -r --wide
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-x86-64/pr19636-1c.d b/ld/testsuite/ld-x86-64/pr19636-1c.d
new file mode 100644
index 00000000000..5262a514462
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-1c.d
@@ -0,0 +1,9 @@
+#source: pr19636-1.s
+#as: --64
+#ld: -pie -E -m elf_x86_64
+#readelf : --dyn-syms --wide
+
+#failif
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func
+#...
diff --git a/ld/testsuite/ld-x86-64/pr19636-1d.d b/ld/testsuite/ld-x86-64/pr19636-1d.d
new file mode 100644
index 00000000000..00da41eca86
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-1d.d
@@ -0,0 +1,14 @@
+#source: pr19636-1.s
+#as: --64
+#ld: -shared -m elf_x86_64
+#readelf : -r --wide --dyn-syms
+
+Relocation section '\.rela?\..*' at offset 0x[0-9a-f]+ contains [0-9]+ entries:
+#...
+[0-9a-f]+[ \t]+[0-9a-f]+[ \t]+R_.*[ \t]+[0-9a-f]+[ \t]+func.*
+#...
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func
+#...
diff --git a/ld/testsuite/ld-x86-64/pr19636-1e.d b/ld/testsuite/ld-x86-64/pr19636-1e.d
new file mode 100644
index 00000000000..ea369b230b9
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-1e.d
@@ -0,0 +1,14 @@
+#source: pr19636-1.s
+#as: --64
+#ld: -shared -Bsymbolic -m elf_x86_64
+#readelf : -r --wide --dyn-syms
+
+Relocation section '\.rela?\..*' at offset 0x[0-9a-f]+ contains [0-9]+ entries:
+#...
+[0-9a-f]+[ \t]+[0-9a-f]+[ \t]+R_.*[ \t]+[0-9a-f]+[ \t]+func.*
+#...
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func
+#...
diff --git a/ld/testsuite/ld-x86-64/pr19636-1f.d b/ld/testsuite/ld-x86-64/pr19636-1f.d
new file mode 100644
index 00000000000..4fc721a17b8
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-1f.d
@@ -0,0 +1,6 @@
+#source: pr19636-1.s
+#as: --64
+#ld: -E -m elf_x86_64
+#readelf : -r --wide
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-x86-64/pr19636-1g.d b/ld/testsuite/ld-x86-64/pr19636-1g.d
new file mode 100644
index 00000000000..7cd52a55675
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-1g.d
@@ -0,0 +1,9 @@
+#source: pr19636-1.s
+#as: --64
+#ld: -E -m elf_x86_64
+#readelf : --dyn-syms --wide
+
+#failif
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func
+#...
diff --git a/ld/testsuite/ld-x86-64/pr19636-2.s b/ld/testsuite/ld-x86-64/pr19636-2.s
new file mode 100644
index 00000000000..8814ecd987d
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-2.s
@@ -0,0 +1,9 @@
+ .text
+ .weak func1
+ .weak func2
+ .weak func3
+ .globl _start
+_start:
+ cmp func1@GOTPCREL(%rip),%rax
+ jmp *func2@GOTPCREL(%rip)
+ call func3@PLT
diff --git a/ld/testsuite/ld-x86-64/pr19636-2a.d b/ld/testsuite/ld-x86-64/pr19636-2a.d
new file mode 100644
index 00000000000..66311703431
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-2a.d
@@ -0,0 +1,17 @@
+#source: pr19636-2.s
+#as: --64 -mrelax-relocations=no
+#ld: -pie -m elf_x86_64 -z nodynamic-undefined-weak
+#readelf : -r --wide -x .got -x .got.plt --dyn-syms
+
+There are no relocations in this file.
+
+Symbol table '\.dynsym' contains 1 entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+ +0: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND +
+
+Hex dump of section '.got':
+ 0x[0-9a-f]+ [0 ]+\.+
+
+Hex dump of section '.got.plt':
+ 0x[0-9a-f]+ +[0-9a-f]+ +[0 ]+ .+
+ 0x[0-9a-f]+ [0 ]+\.+
diff --git a/ld/testsuite/ld-x86-64/pr19636-2b.d b/ld/testsuite/ld-x86-64/pr19636-2b.d
new file mode 100644
index 00000000000..d1df9ba37f7
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-2b.d
@@ -0,0 +1,20 @@
+#source: pr19636-2.s
+#as: --64 -mrelax-relocations=no
+#ld: -pie -E -m elf_x86_64 -z nodynamic-undefined-weak
+#readelf : -r --wide -x .got -x .got.plt --dyn-syms
+
+There are no relocations in this file.
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+ +0: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND +
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +GLOBAL +DEFAULT +[0-9]+ +_start
+#...
+
+Hex dump of section '.got':
+ 0x[0-9a-f]+ [0 ]+\.+
+
+Hex dump of section '.got.plt':
+ 0x[0-9a-f]+ +[0-9a-f]+ +[0 ]+ .+
+ 0x[0-9a-f]+ [0 ]+\.+
diff --git a/ld/testsuite/ld-x86-64/pr19636-2c.d b/ld/testsuite/ld-x86-64/pr19636-2c.d
new file mode 100644
index 00000000000..cbbbd5272e7
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-2c.d
@@ -0,0 +1,9 @@
+#source: pr19636-2.s
+#as: --64 -mrelax-relocations=no
+#ld: -pie -E -m elf_x86_64 -z nodynamic-undefined-weak
+#readelf : --wide --dyn-syms
+
+#failif
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func[0-9]?
+#...
diff --git a/ld/testsuite/ld-x86-64/pr19636-2d-nacl.d b/ld/testsuite/ld-x86-64/pr19636-2d-nacl.d
new file mode 100644
index 00000000000..2e00053c970
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-2d-nacl.d
@@ -0,0 +1,37 @@
+#source: pr19636-2.s
+#as: --64 -mrelax-relocations=no
+#ld: -pie -m elf_x86_64 -z nodynamic-undefined-weak
+#objdump: -dw
+#target: x86_64-*-nacl*
+
+.*: +file format .*
+
+
+Disassembly of section .plt:
+
+0+ <.plt>:
+[ ]*[a-f0-9]+: ff 35 c2 02 01 10 pushq 0x100102c2\(%rip\) # 100102c8 <_GLOBAL_OFFSET_TABLE_\+0x8>
+[ ]*[a-f0-9]+: 4c 8b 1d c3 02 01 10 mov 0x100102c3\(%rip\),%r11 # 100102d0 <_GLOBAL_OFFSET_TABLE_\+0x10>
+[ ]*[a-f0-9]+: 41 83 e3 e0 and \$0xffffffe0,%r11d
+[ ]*[a-f0-9]+: 4d 01 fb add %r15,%r11
+[ ]*[a-f0-9]+: 41 ff e3 jmpq \*%r11
+[ ]*[a-f0-9]+: 66 0f 1f 84 00 00 00 00 00 nopw 0x0\(%rax,%rax,1\)
+[ ]*[a-f0-9]+: 66 66 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 data16 data16 data16 data16 data16 nopw %cs:0x0\(%rax,%rax,1\)
+[ ]*[a-f0-9]+: 66 66 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 data16 data16 data16 data16 data16 nopw %cs:0x0\(%rax,%rax,1\)
+[ ]*[a-f0-9]+: 66 90 xchg %ax,%ax
+[ ]*[a-f0-9]+: 4c 8b 1d 91 02 01 10 mov 0x10010291\(%rip\),%r11 # 100102d8 <_GLOBAL_OFFSET_TABLE_\+0x18>
+[ ]*[a-f0-9]+: 41 83 e3 e0 and \$0xffffffe0,%r11d
+[ ]*[a-f0-9]+: 4d 01 fb add %r15,%r11
+[ ]*[a-f0-9]+: 41 ff e3 jmpq \*%r11
+[ ]*[a-f0-9]+: 66 66 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 data16 data16 data16 data16 data16 nopw %cs:0x0\(%rax,%rax,1\)
+[ ]*[a-f0-9]+: 68 00 00 00 00 pushq \$0x0
+[ ]*[a-f0-9]+: e9 00 00 00 00 jmpq 6a <_start-0x16>
+[ ]*[a-f0-9]+: 66 66 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 data16 data16 data16 data16 data16 nopw %cs:0x0\(%rax,%rax,1\)
+[ ]*[a-f0-9]+: 0f 1f 80 00 00 00 00 nopl 0x0\(%rax\)
+
+Disassembly of section .text:
+
+0+80 <_start>:
+[ ]*[a-f0-9]+: 48 3b 05 29 02 01 10 cmp 0x10010229\(%rip\),%rax # 100102b0 <_DYNAMIC\+0xe0>
+[ ]*[a-f0-9]+: ff 25 2b 02 01 10 jmpq \*0x1001022b\(%rip\) # 100102b8 <_DYNAMIC\+0xe8>
+[ ]*[a-f0-9]+: e8 ae ff ff ff callq 40 <_start-0x40>
diff --git a/ld/testsuite/ld-x86-64/pr19636-2d.d b/ld/testsuite/ld-x86-64/pr19636-2d.d
new file mode 100644
index 00000000000..52e118fdeba
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-2d.d
@@ -0,0 +1,25 @@
+#source: pr19636-2.s
+#as: --64 -mrelax-relocations=no
+#ld: -pie -m elf_x86_64 -z nodynamic-undefined-weak
+#objdump: -dw
+#notarget: x86_64-*-nacl*
+
+.*: +file format .*
+
+
+Disassembly of section .plt:
+
+0+1a0 <.plt>:
+[ ]*[a-f0-9]+: ff 35 2a 01 20 00 pushq 0x20012a\(%rip\) # 2002d0 <_GLOBAL_OFFSET_TABLE_\+0x8>
+[ ]*[a-f0-9]+: ff 25 2c 01 20 00 jmpq \*0x20012c\(%rip\) # 2002d8 <_GLOBAL_OFFSET_TABLE_\+0x10>
+[ ]*[a-f0-9]+: 0f 1f 40 00 nopl 0x0\(%rax\)
+[ ]*[a-f0-9]+: ff 25 2a 01 20 00 jmpq \*0x20012a\(%rip\) # 2002e0 <_GLOBAL_OFFSET_TABLE_\+0x18>
+[ ]*[a-f0-9]+: 68 00 00 00 00 pushq \$0x0+
+[ ]*[a-f0-9]+: e9 00 00 00 00 jmpq [a-f0-9]+ <.*>
+
+Disassembly of section .text:
+
+0+1c0 <_start>:
+[ ]*[a-f0-9]+: 48 3b 05 f1 00 20 00 cmp 0x2000f1\(%rip\),%rax # 2002b8 <_DYNAMIC\+0xe0>
+[ ]*[a-f0-9]+: ff 25 f3 00 20 00 jmpq \*0x2000f3\(%rip\) # 2002c0 <_DYNAMIC\+0xe8>
+[ ]*[a-f0-9]+: e8 de ff ff ff callq 1b0 <_start-0x10>
diff --git a/ld/testsuite/ld-x86-64/pr19636-2e.d b/ld/testsuite/ld-x86-64/pr19636-2e.d
new file mode 100644
index 00000000000..2d4f06455a1
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-2e.d
@@ -0,0 +1,19 @@
+#source: pr19636-2.s
+#as: --64 -mrelax-relocations=no
+#ld: -shared -m elf_x86_64 -z nodynamic-undefined-weak
+#readelf : -r --wide --dyn-syms
+
+Relocation section '\.rela\.dyn' at offset [0x0-9a-f]+ contains 2 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_GLOB_DAT +0+ +func1 \+ 0
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_GLOB_DAT +0+ +func2 \+ 0
+
+Relocation section '\.rela\.plt' at offset 0x[0-9a-f]+ contains 1 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_JUMP_SLOT +0+ +func3 \+ 0
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func[0-9]?
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr19636-2f.d b/ld/testsuite/ld-x86-64/pr19636-2f.d
new file mode 100644
index 00000000000..2b12ede394f
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-2f.d
@@ -0,0 +1,19 @@
+#source: pr19636-2.s
+#as: --64 -mrelax-relocations=no
+#ld: -shared -Bsymbolic -m elf_x86_64 -z nodynamic-undefined-weak
+#readelf : -r --wide --dyn-syms
+
+Relocation section '\.rela\.dyn' at offset [0x0-9a-f]+ contains 2 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_GLOB_DAT +0+ +func1 \+ 0
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_GLOB_DAT +0+ +func2 \+ 0
+
+Relocation section '\.rela\.plt' at offset 0x[0-9a-f]+ contains 1 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_JUMP_SLOT +0+ +func3 \+ 0
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func[0-9]?
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr19636-2g.d b/ld/testsuite/ld-x86-64/pr19636-2g.d
new file mode 100644
index 00000000000..b0cd2b272b0
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-2g.d
@@ -0,0 +1,13 @@
+#source: pr19636-2.s
+#as: --64 -mrelax-relocations=no
+#ld: -m elf_x86_64 -z nodynamic-undefined-weak
+#readelf : -r --wide -x .got -x .got.plt --dyn-syms
+
+There are no relocations in this file.
+
+Hex dump of section '.got':
+ 0x[0-9a-f]+ [0 ]+\.+
+
+Hex dump of section '.got.plt':
+ 0x[0-9a-f]+ [0 ]+\.+
+ 0x[0-9a-f]+ [0 ]+\.+
diff --git a/ld/testsuite/ld-x86-64/pr19636-2h.d b/ld/testsuite/ld-x86-64/pr19636-2h.d
new file mode 100644
index 00000000000..a1935e43eeb
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-2h.d
@@ -0,0 +1,20 @@
+#source: pr19636-2.s
+#as: --64 -mrelax-relocations=no
+#ld: -E -m elf_x86_64 -z nodynamic-undefined-weak
+#readelf : -r --wide -x .got -x .got.plt --dyn-syms
+
+There are no relocations in this file.
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+ +0: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND +
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +GLOBAL +DEFAULT +[0-9]+ +_start
+#...
+
+Hex dump of section '.got':
+ 0x[0-9a-f]+ [0 ]+\.+
+
+Hex dump of section '.got.plt':
+ 0x[0-9a-f]+ +[0-9a-f]+ +[0 ]+ .+
+ 0x[0-9a-f]+ [0 ]+\.+
diff --git a/ld/testsuite/ld-x86-64/pr19636-2i.d b/ld/testsuite/ld-x86-64/pr19636-2i.d
new file mode 100644
index 00000000000..b4ec4c89687
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-2i.d
@@ -0,0 +1,9 @@
+#source: pr19636-2.s
+#as: --64 -mrelax-relocations=no
+#ld: -E -m elf_x86_64 -z nodynamic-undefined-weak
+#readelf : --wide --dyn-syms
+
+#failif
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +WEAK +DEFAULT +UND +func[0-9]?
+#...
diff --git a/ld/testsuite/ld-x86-64/pr19636-3.s b/ld/testsuite/ld-x86-64/pr19636-3.s
new file mode 100644
index 00000000000..6c981f5e034
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-3.s
@@ -0,0 +1,14 @@
+ .text
+ .type start,"function"
+ .global start
+start:
+ .type _start,"function"
+ .global _start
+_start:
+ .type __start,"function"
+ .global __start
+__start:
+ .type main,"function"
+ .global main
+main:
+ .long 0
diff --git a/ld/testsuite/ld-x86-64/pr19636-3a.d b/ld/testsuite/ld-x86-64/pr19636-3a.d
new file mode 100644
index 00000000000..af01939e31d
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-3a.d
@@ -0,0 +1,8 @@
+#source: pr19636-3.s
+#as: --64
+#ld: -pie --defsym foobar=0x100 -m elf_x86_64
+#readelf : --dyn-syms --wide
+
+Symbol table '\.dynsym' contains 1 entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+ +0: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND +
diff --git a/ld/testsuite/ld-x86-64/pr19636-3b.d b/ld/testsuite/ld-x86-64/pr19636-3b.d
new file mode 100644
index 00000000000..be8c4f628fd
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-3b.d
@@ -0,0 +1,10 @@
+#source: pr19636-3.s
+#as: --64
+#ld: -pie -E --defsym foobar=0x100 -m elf_x86_64
+#readelf : --dyn-syms --wide
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +0+100 +0 +NOTYPE +GLOBAL +DEFAULT +ABS +foobar
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr19636-3c.d b/ld/testsuite/ld-x86-64/pr19636-3c.d
new file mode 100644
index 00000000000..02b6464f8b1
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-3c.d
@@ -0,0 +1,10 @@
+#source: pr19636-3.s
+#as: --64
+#ld: -shared -Bsymbolic --defsym foobar=0x100 -m elf_x86_64
+#readelf : --dyn-syms --wide
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +0+100 +0 +NOTYPE +GLOBAL +DEFAULT +ABS +foobar
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr19636-3d.d b/ld/testsuite/ld-x86-64/pr19636-3d.d
new file mode 100644
index 00000000000..3d9a6d76eab
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19636-3d.d
@@ -0,0 +1,10 @@
+#source: pr19636-3.s
+#as: --64
+#ld: -E --defsym foobar=0x100 -m elf_x86_64
+#readelf : --dyn-syms --wide
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +0+100 +0 +NOTYPE +GLOBAL +DEFAULT +ABS +foobar
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr19704.out b/ld/testsuite/ld-x86-64/pr19704.out
new file mode 100644
index 00000000000..3506f46c914
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19704.out
@@ -0,0 +1 @@
+Weak undefined
diff --git a/ld/testsuite/ld-x86-64/pr19704a.c b/ld/testsuite/ld-x86-64/pr19704a.c
new file mode 100644
index 00000000000..aa52e0011d2
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19704a.c
@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+extern int __attribute__ ((weak)) fun (void);
+
+int
+main (void)
+{
+ if (&fun != 0)
+ fun ();
+ else
+ printf ("Weak undefined\n");
+ return 0;
+}
diff --git a/ld/testsuite/ld-x86-64/pr19704b.c b/ld/testsuite/ld-x86-64/pr19704b.c
new file mode 100644
index 00000000000..1d688e13dc8
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19704b.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+void
+fun (void)
+{
+ printf ("Weak defined\n");
+}
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 7248377c9b6..214b08b05fd 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -355,6 +355,82 @@ run_dump_test "pr19162"
run_dump_test "pr19175"
run_dump_test "pr18591"
run_dump_test "pr19615"
+run_dump_test "pr19636-1a"
+run_dump_test "pr19636-1b"
+run_dump_test "pr19636-1c"
+run_dump_test "pr19636-1d"
+run_dump_test "pr19636-1e"
+run_dump_test "pr19636-1f"
+run_dump_test "pr19636-1g"
+run_dump_test "pr19636-2a"
+run_dump_test "pr19636-2b"
+run_dump_test "pr19636-2c"
+run_dump_test "pr19636-2d"
+run_dump_test "pr19636-2d-nacl"
+run_dump_test "pr19636-2e"
+run_dump_test "pr19636-2f"
+run_dump_test "pr19636-2g"
+run_dump_test "pr19636-2h"
+run_dump_test "pr19636-2i"
+run_dump_test "pr19636-3a"
+run_dump_test "pr19636-3b"
+run_dump_test "pr19636-3c"
+
+proc undefined_weak {cflags ldflags} {
+ set testname "Undefined weak symbol"
+ if { ![ string match "" $cflags$ldflags] } {
+ set testname "$testname ($cflags $ldflags)"
+ }
+
+ if { [ regexp "\-fPIE" $cflags]
+ && ![ regexp "\-z nodynamic-undefined-weak" $ldflags] } {
+ set weak_symbol "Weak defined"
+ } else {
+ set weak_symbol "Weak undefined"
+ }
+
+ run_cc_link_tests [list \
+ [list \
+ "Build libpr19704a.so" \
+ "-shared -Wl,-soname,libpr19704.so" \
+ "" \
+ { dummy.s } \
+ {} \
+ "libpr19704a.so" \
+ ] \
+ [list \
+ "Build libpr19704b.so" \
+ "-shared -Wl,-soname,libpr19704.so" \
+ "-fPIC" \
+ { pr19704b.c } \
+ {} \
+ "libpr19704b.so" \
+ ] \
+ ]
+
+ exec cp tmpdir/libpr19704a.so tmpdir/libpr19704.so
+
+ run_ld_link_exec_tests [] [list \
+ [list \
+ "Run pr19704" \
+ "$ldflags tmpdir/libpr19704.so -R tmpdir" \
+ "" \
+ { pr19704a.c } \
+ "pr19704" \
+ "pr19704.out" \
+ "$cflags" \
+ ] \
+ ]
+
+ exec cp tmpdir/libpr19704b.so tmpdir/libpr19704.so
+
+ set exec_output [run_host_cmd tmpdir/pr19704 ""]
+ if {![string match $weak_symbol $exec_output]} {
+ fail $testname
+ } else {
+ pass $testname
+ }
+}
# Add $PLT_CFLAGS if PLT is expected.
global PLT_CFLAGS
@@ -686,6 +762,12 @@ if { [isnative] && [which $CC] != 0 } {
] \
]
}
+
+ undefined_weak "" ""
+ undefined_weak "-fPIE" ""
+ undefined_weak "-fPIE" "-pie"
+ undefined_weak "-fPIE" "-z nodynamic-undefined-weak"
+ undefined_weak "-fPIE" "-pie -z nodynamic-undefined-weak"
}
if { ![istarget "x86_64-*-linux*"]} {