summaryrefslogtreecommitdiff
path: root/ld/testsuite/ld-scripts
diff options
context:
space:
mode:
authorRichard Henderson <rth@redhat.com>1999-05-03 07:29:11 +0000
committerRichard Henderson <rth@redhat.com>1999-05-03 07:29:11 +0000
commit252b5132c753830d5fd56823373aed85f2a0db63 (patch)
tree1af963bfd8d3e55167b81def4207f175eaff3a56 /ld/testsuite/ld-scripts
downloadbinutils-gdb-binu_ss_19990502.tar.gz
19990502 sourceware importbinu_ss_19990502
Diffstat (limited to 'ld/testsuite/ld-scripts')
-rw-r--r--ld/testsuite/ld-scripts/cross1.c6
-rw-r--r--ld/testsuite/ld-scripts/cross1.t6
-rw-r--r--ld/testsuite/ld-scripts/cross2.c5
-rw-r--r--ld/testsuite/ld-scripts/cross2.t6
-rw-r--r--ld/testsuite/ld-scripts/cross3.c7
-rw-r--r--ld/testsuite/ld-scripts/crossref.exp77
-rw-r--r--ld/testsuite/ld-scripts/defined.exp39
-rw-r--r--ld/testsuite/ld-scripts/defined.s2
-rw-r--r--ld/testsuite/ld-scripts/defined.t7
-rw-r--r--ld/testsuite/ld-scripts/phdrs.exp57
-rw-r--r--ld/testsuite/ld-scripts/phdrs.s8
-rw-r--r--ld/testsuite/ld-scripts/phdrs.t14
-rw-r--r--ld/testsuite/ld-scripts/script.exp64
-rw-r--r--ld/testsuite/ld-scripts/script.s8
-rw-r--r--ld/testsuite/ld-scripts/script.t16
-rw-r--r--ld/testsuite/ld-scripts/scriptm.t10
-rw-r--r--ld/testsuite/ld-scripts/sizeof.exp55
-rw-r--r--ld/testsuite/ld-scripts/sizeof.s1
-rw-r--r--ld/testsuite/ld-scripts/sizeof.t17
-rw-r--r--ld/testsuite/ld-scripts/weak.exp57
-rw-r--r--ld/testsuite/ld-scripts/weak.t12
-rw-r--r--ld/testsuite/ld-scripts/weak1.s11
-rw-r--r--ld/testsuite/ld-scripts/weak2.s11
23 files changed, 496 insertions, 0 deletions
diff --git a/ld/testsuite/ld-scripts/cross1.c b/ld/testsuite/ld-scripts/cross1.c
new file mode 100644
index 00000000000..56789452a5b
--- /dev/null
+++ b/ld/testsuite/ld-scripts/cross1.c
@@ -0,0 +1,6 @@
+extern int foo ();
+int
+func ()
+{
+ return foo ();
+}
diff --git a/ld/testsuite/ld-scripts/cross1.t b/ld/testsuite/ld-scripts/cross1.t
new file mode 100644
index 00000000000..e1948c9e09f
--- /dev/null
+++ b/ld/testsuite/ld-scripts/cross1.t
@@ -0,0 +1,6 @@
+NOCROSSREFS ( .text .data )
+SECTIONS
+{
+ .text : { tmpdir/cross1.o }
+ .data : { tmpdir/cross2.o }
+}
diff --git a/ld/testsuite/ld-scripts/cross2.c b/ld/testsuite/ld-scripts/cross2.c
new file mode 100644
index 00000000000..414317712d1
--- /dev/null
+++ b/ld/testsuite/ld-scripts/cross2.c
@@ -0,0 +1,5 @@
+int
+foo ()
+{
+ return 1;
+}
diff --git a/ld/testsuite/ld-scripts/cross2.t b/ld/testsuite/ld-scripts/cross2.t
new file mode 100644
index 00000000000..cf046f6c36b
--- /dev/null
+++ b/ld/testsuite/ld-scripts/cross2.t
@@ -0,0 +1,6 @@
+NOCROSSREFS ( .text .data )
+SECTIONS
+{
+ .text : { *(.text) *(.pr) }
+ .data : { *(.data) *(.sdata) *(.rw) *(.tc0) *(.tc) }
+}
diff --git a/ld/testsuite/ld-scripts/cross3.c b/ld/testsuite/ld-scripts/cross3.c
new file mode 100644
index 00000000000..1848c32fd0b
--- /dev/null
+++ b/ld/testsuite/ld-scripts/cross3.c
@@ -0,0 +1,7 @@
+int i = 4;
+
+int
+foo ()
+{
+ return i;
+}
diff --git a/ld/testsuite/ld-scripts/crossref.exp b/ld/testsuite/ld-scripts/crossref.exp
new file mode 100644
index 00000000000..fee97595a37
--- /dev/null
+++ b/ld/testsuite/ld-scripts/crossref.exp
@@ -0,0 +1,77 @@
+# Test NOCROSSREFS in a linker script.
+# By Ian Lance Taylor, Cygnus Support.
+
+set test1 "NOCROSSREFS 1"
+set test2 "NOCROSSREFS 2"
+
+if { [which $CC] == 0 } {
+ untested $test1
+ untested $test2
+ return
+}
+
+if { ![ld_compile $CC "$srcdir/$subdir/cross1.c" tmpdir/cross1.o] \
+ || ![ld_compile $CC "$srcdir/$subdir/cross2.c" tmpdir/cross2.o] } {
+ unresolved $test1
+ unresolved $test2
+ return
+}
+
+set flags ""
+
+# The a29k compiled code calls V_SPILL and V_FILL. Since we don't
+# need to run this code, but we don't have definitions for those
+# functions, we just define them out.
+if [istarget a29k*-*-*] {
+ set flags "$flags --defsym V_SPILL=0 --defsym V_FILL=0"
+}
+
+# hppa-elf needs a definition for $global$.
+if [istarget hppa*-*-*] {
+ set flags "$flags --defsym '\$global\$'=0"
+}
+
+verbose -log "$ld $flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o"
+
+catch "exec $ld $flags -o tmpdir/cross1 -T $srcdir/$subdir/cross1.t tmpdir/cross1.o tmpdir/cross2.o" exec_output
+
+set exec_output [prune_warnings $exec_output]
+
+regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
+
+if [string match "" $exec_output] then {
+ fail $test1
+} else {
+ verbose -log "$exec_output"
+ if [regexp "prohibited cross reference from .* to `foo' in" $exec_output] {
+ pass $test1
+ } else {
+ fail $test1
+ }
+}
+
+# Check cross references within a single object.
+
+if { ![ld_compile $CC "$srcdir/$subdir/cross3.c" tmpdir/cross3.o] } {
+ unresolved $test2
+ return
+}
+
+verbose -log "$ld $flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o"
+
+catch "exec $ld $flags -o tmpdir/cross2 -T $srcdir/$subdir/cross2.t tmpdir/cross3.o" exec_output
+
+set exec_output [prune_warnings $exec_output]
+
+regsub -all "(^|\n)($ld: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
+
+if [string match "" $exec_output] then {
+ fail $test2
+} else {
+ verbose -log "$exec_output"
+ if [regexp "prohibited cross reference from .* to `.*' in" $exec_output] {
+ pass $test2
+ } else {
+ fail $test2
+ }
+}
diff --git a/ld/testsuite/ld-scripts/defined.exp b/ld/testsuite/ld-scripts/defined.exp
new file mode 100644
index 00000000000..6da26bc3bc2
--- /dev/null
+++ b/ld/testsuite/ld-scripts/defined.exp
@@ -0,0 +1,39 @@
+# Test DEFINED in a linker script.
+# By Ian Lance Taylor, Cygnus Support.
+
+set testname "DEFINED"
+set prms_id 5699
+
+if ![ld_assemble $as $srcdir/$subdir/defined.s tmpdir/def.o] {
+ unresolved $testname
+ return
+}
+
+if ![ld_simple_link $ld tmpdir/def "-T $srcdir/$subdir/defined.t tmpdir/def.o"] {
+ fail $testname
+} else {
+ if ![ld_nm $nm tmpdir/def] {
+ unresolved $testname
+ } else {
+ if {![info exists nm_output(value1)] \
+ || ![info exists nm_output(value2)]} {
+ send_log "bad output from nm\n"
+ verbose "bad output from nm"
+ fail $testname
+ } else {
+ if {$nm_output(value1) != 1} {
+ send_log "value1 == $nm_output(value1)\n"
+ verbose "value1 == $nm_output(value1)"
+ fail $testname
+ } else {
+ if {$nm_output(value2) != 2} {
+ send_log "value2 == $nm_output(value2)\n"
+ verbose "value2 == $nm_output(value2)"
+ fail $testname
+ } else {
+ pass $testname
+ }
+ }
+ }
+ }
+}
diff --git a/ld/testsuite/ld-scripts/defined.s b/ld/testsuite/ld-scripts/defined.s
new file mode 100644
index 00000000000..a364bbbbe6c
--- /dev/null
+++ b/ld/testsuite/ld-scripts/defined.s
@@ -0,0 +1,2 @@
+ .globl defined
+ defined = 1
diff --git a/ld/testsuite/ld-scripts/defined.t b/ld/testsuite/ld-scripts/defined.t
new file mode 100644
index 00000000000..c1ef1b6a798
--- /dev/null
+++ b/ld/testsuite/ld-scripts/defined.t
@@ -0,0 +1,7 @@
+SECTIONS {
+ .text : { *(.text) }
+ .data : { *(.data) }
+ .bss : { *(.bss) *(COMMON) }
+}
+value1 = DEFINED (defined) ? 1 : 2;
+value2 = DEFINED (undefined) ? 1 : 2;
diff --git a/ld/testsuite/ld-scripts/phdrs.exp b/ld/testsuite/ld-scripts/phdrs.exp
new file mode 100644
index 00000000000..34ee00f899c
--- /dev/null
+++ b/ld/testsuite/ld-scripts/phdrs.exp
@@ -0,0 +1,57 @@
+# Test PHDRS in a linker script.
+# By Ian Lance Taylor, Cygnus Support.
+
+# PHDRS is only meaningful for ELF.
+if { ![istarget *-*-sysv4*] \
+ && ![istarget *-*-unixware*] \
+ && ![istarget *-*-elf*] \
+ && ![istarget *-*-eabi*] \
+ && ![istarget *-*-linux*] \
+ && ![istarget *-*-irix5*] \
+ && ![istarget *-*-irix6*] \
+ && ![istarget *-*-solaris2*] } {
+ return
+}
+
+if { [istarget *-*-linuxaout*] \
+ || [istarget *-*-linuxoldld*] } {
+ return
+}
+
+# This is a very simplistic test.
+
+set testname "PHDRS"
+
+if ![ld_assemble $as $srcdir/$subdir/phdrs.s tmpdir/phdrs.o] {
+ unresolved $testname
+ return
+}
+
+set phdrs_regexp \
+".*Program Header:.*PHDR *off *0x00*34 *vaddr *0x00*80034 *paddr *0x00*80034.*filesz *0x0\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* flags r--.*LOAD *off *0x00* *vaddr *0x00*80000 *paddr *0x00*80000.*filesz *0x00*\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* *flags r-x.*LOAD *off *0x0\[0-9a-f\]* *vaddr *0x00*80*\[0-9a-f\]* *paddr *0x00*80*\[0-9a-f\]*.*filesz *0x0\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* *flags *rw-.*"
+
+# On a 64 bit ELF format, we need different numbers.
+if { [istarget alpha*-*-*] } then {
+ set phdrs_regexp \
+".*Program Header:.*PHDR *off *0x00*40 *vaddr *0x00*80040 *paddr *0x00*80040.*filesz *0x0\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* flags r--.*LOAD *off *0x00* *vaddr *0x00*80000 *paddr *0x00*80000.*filesz *0x00*\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* *flags r-x.*LOAD *off *0x0\[0-9a-f\]* *vaddr *0x00*80*\[0-9a-f\]* *paddr *0x00*80*\[0-9a-f\]*.*filesz *0x0\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* *flags *rw-.*"
+}
+
+if ![ld_simple_link $ld tmpdir/phdrs "-T $srcdir/$subdir/phdrs.t tmpdir/phdrs.o"] {
+ fail $testname
+} else {
+ if {[which $objdump] == 0} {
+ unresolved $testname
+ return
+ }
+
+ verbose -log "$objdump --private tmpdir/phdrs"
+ catch "exec $objdump --private tmpdir/phdrs" exec_output
+ set exec_output [prune_warnings $exec_output]
+ verbose -log $exec_output
+
+ if [regexp $phdrs_regexp $exec_output] {
+ pass $testname
+ } else {
+ fail $testname
+ }
+}
diff --git a/ld/testsuite/ld-scripts/phdrs.s b/ld/testsuite/ld-scripts/phdrs.s
new file mode 100644
index 00000000000..ec1f0d17e6e
--- /dev/null
+++ b/ld/testsuite/ld-scripts/phdrs.s
@@ -0,0 +1,8 @@
+ .text
+
+ .long 1
+
+ .data
+
+ .long 2
+
diff --git a/ld/testsuite/ld-scripts/phdrs.t b/ld/testsuite/ld-scripts/phdrs.t
new file mode 100644
index 00000000000..8f710e23fdc
--- /dev/null
+++ b/ld/testsuite/ld-scripts/phdrs.t
@@ -0,0 +1,14 @@
+PHDRS
+{
+ header PT_PHDR PHDRS ;
+ text PT_LOAD FILEHDR PHDRS ;
+ data PT_LOAD ;
+}
+
+SECTIONS
+{
+ . = 0x80000 + SIZEOF_HEADERS;
+ .text : { *(.text) } :text
+ .data : { *(.data) } :data
+ /DISCARD/ : { *(.reginfo) }
+}
diff --git a/ld/testsuite/ld-scripts/script.exp b/ld/testsuite/ld-scripts/script.exp
new file mode 100644
index 00000000000..fe0a0411188
--- /dev/null
+++ b/ld/testsuite/ld-scripts/script.exp
@@ -0,0 +1,64 @@
+# Test basic linker script functionality
+# By Ian Lance Taylor, Cygnus Support
+
+set testname "script"
+
+if ![ld_assemble $as $srcdir/$subdir/script.s tmpdir/script.o] {
+ unresolved $testname
+ return
+}
+
+proc check_script { } {
+ global nm
+ global testname
+ global nm_output
+
+ if ![ld_nm $nm tmpdir/script] {
+ unresolved $testname
+ } else {
+ if {![info exists nm_output(text_start)] \
+ || ![info exists nm_output(text_end)] \
+ || ![info exists nm_output(data_start)] \
+ || ![info exists nm_output(data_end)]} {
+ send_log "bad output from nm\n"
+ verbose "bad output from nm"
+ fail $testname
+ } else {
+ if {$nm_output(text_start) != 0x100} {
+ send_log "text_start == $nm_output(text_start)\n"
+ verbose "text_start == $nm_output(text_start)"
+ fail $testname
+ } else { if {$nm_output(text_end) < 0x104 \
+ || $nm_output(text_end) > 0x110} {
+ send_log "text_end == $nm_output(text_end)\n"
+ verbose "text_end == $nm_output(text_end)"
+ fail $testname
+ } else { if {$nm_output(data_start) != 0x1000} {
+ send_log "data_start == $nm_output(data_start)\n"
+ verbose "data_start == $nm_output(data_start)"
+ fail $testname
+ } else { if {$nm_output(data_end) < 0x1004 \
+ || $nm_output(data_end) > 0x1010} {
+ send_log "data_end == $nm_output(data_end)\n"
+ verbose "data_end == $nm_output(data_end)"
+ fail $testname
+ } else {
+ pass $testname
+ } } } }
+ }
+ }
+}
+
+if ![ld_simple_link $ld tmpdir/script "-T $srcdir/$subdir/script.t tmpdir/script.o"] {
+ fail $testname
+} else {
+ check_script
+}
+
+set testname "MRI script"
+
+if ![ld_simple_link $ld tmpdir/script "-c $srcdir/$subdir/scriptm.t"] {
+ fail $testname
+} else {
+ check_script
+}
diff --git a/ld/testsuite/ld-scripts/script.s b/ld/testsuite/ld-scripts/script.s
new file mode 100644
index 00000000000..d7b65b0df55
--- /dev/null
+++ b/ld/testsuite/ld-scripts/script.s
@@ -0,0 +1,8 @@
+ .text
+ .globl text_symbol
+text_symbol:
+ .long 1
+ .data
+ .globl data_symbol
+data_symbol:
+ .long 2
diff --git a/ld/testsuite/ld-scripts/script.t b/ld/testsuite/ld-scripts/script.t
new file mode 100644
index 00000000000..ee7a48a9f60
--- /dev/null
+++ b/ld/testsuite/ld-scripts/script.t
@@ -0,0 +1,16 @@
+SECTIONS
+{
+ .text 0x100 : {
+ text_start = .;
+ *(.text)
+ *(.pr)
+ text_end = .;
+ }
+ . = 0x1000;
+ .data : {
+ data_start = .;
+ *(.data)
+ *(.rw)
+ data_end = .;
+ }
+}
diff --git a/ld/testsuite/ld-scripts/scriptm.t b/ld/testsuite/ld-scripts/scriptm.t
new file mode 100644
index 00000000000..57ccae13662
--- /dev/null
+++ b/ld/testsuite/ld-scripts/scriptm.t
@@ -0,0 +1,10 @@
+* MRI script
+sect .text = $100 ; .text start address
+sect .data = 1000h ; .data start address
+public text_start = $100
+public text_end = # continuation line
+ text_start + 4
+public data_start = 1000h
+public data_end = data_start + 4
+
+load tmpdir/script.o
diff --git a/ld/testsuite/ld-scripts/sizeof.exp b/ld/testsuite/ld-scripts/sizeof.exp
new file mode 100644
index 00000000000..3bdefd4f0dc
--- /dev/null
+++ b/ld/testsuite/ld-scripts/sizeof.exp
@@ -0,0 +1,55 @@
+# Test SIZEOF in a linker script.
+# By Ian Lance Taylor, Cygnus Support
+# Based on a bug report from anders.blomdell@control.lth.se.
+
+set testname "SIZEOF"
+
+if ![ld_assemble $as $srcdir/$subdir/sizeof.s tmpdir/sizeof.o] {
+ unresolved $testname
+ return
+}
+
+if ![ld_simple_link $ld tmpdir/sizeof "-T $srcdir/$subdir/sizeof.t tmpdir/sizeof.o"] {
+ fail $testname
+ return
+}
+
+if ![ld_nm $nm tmpdir/sizeof] {
+ unresolved $testname
+ return
+}
+
+if {![info exists nm_output(text_start)] \
+ || ![info exists nm_output(text_end)] \
+ || ![info exists nm_output(data_start)] \
+ || ![info exists nm_output(data_end)] \
+ || ![info exists nm_output(sizeof_text)] \
+ || ![info exists nm_output(sizeof_data)]} {
+ send_log "bad output from nm\n"
+ verbose "bad output from nm"
+ fail $testname
+ return
+}
+
+if {$nm_output(text_end) - $nm_output(text_start) != $nm_output(sizeof_text)} {
+ send_log "text_end - text_start != sizeof_text\n"
+ verbose "text_end - text_start != sizeof_text"
+ fail $testname
+ return
+}
+
+if {$nm_output(data_end) - $nm_output(data_start) != $nm_output(sizeof_data)} {
+ send_log "data_end - data_start != sizeof_data\n"
+ verbose "data_end - data_start != sizeof_data"
+ fail $testname
+ return
+}
+
+if {$nm_output(sizeof_text) != $nm_output(sizeof_data)} {
+ send_log "sizeof_text != sizeof_data\n"
+ verbose "sizeof_text != sizeof_data"
+ fail $testname
+ return
+}
+
+pass $testname
diff --git a/ld/testsuite/ld-scripts/sizeof.s b/ld/testsuite/ld-scripts/sizeof.s
new file mode 100644
index 00000000000..e221ca3c0b3
--- /dev/null
+++ b/ld/testsuite/ld-scripts/sizeof.s
@@ -0,0 +1 @@
+ .space 16
diff --git a/ld/testsuite/ld-scripts/sizeof.t b/ld/testsuite/ld-scripts/sizeof.t
new file mode 100644
index 00000000000..6244a37b7ac
--- /dev/null
+++ b/ld/testsuite/ld-scripts/sizeof.t
@@ -0,0 +1,17 @@
+SECTIONS {
+ .text :
+ {
+ text_start = .;
+ tmpdir/sizeof.o
+ text_end = .;
+ }
+ .data :
+ {
+ data_start = .;
+ . = . + SIZEOF(.text);
+ data_end = .;
+ }
+}
+
+sizeof_text = SIZEOF(.text);
+sizeof_data = SIZEOF(.data);
diff --git a/ld/testsuite/ld-scripts/weak.exp b/ld/testsuite/ld-scripts/weak.exp
new file mode 100644
index 00000000000..f69db5793cc
--- /dev/null
+++ b/ld/testsuite/ld-scripts/weak.exp
@@ -0,0 +1,57 @@
+# Test weak symbols.
+# By Ian Lance Taylor, Cygnus Solutions.
+
+set testname "weak symbols"
+
+# This test only works for ELF targets. It ought to work for some
+# a.out targets, but it doesn't.
+
+if { ![istarget *-*-sysv4*] \
+ && ![istarget *-*-unixware*] \
+ && ![istarget *-*-elf*] \
+ && ![istarget *-*-eabi*] \
+ && ![istarget *-*-linux*] \
+ && ![istarget *-*-irix5*] \
+ && ![istarget *-*-irix6*] \
+ && ![istarget *-*-solaris2*] } then {
+ return
+}
+
+if { [istarget *-*-linuxaout*] \
+ || [istarget *-*-linuxoldld*] } {
+ return
+}
+
+if {! [ld_assemble $as $srcdir/$subdir/weak1.s tmpdir/weak1.o]
+ || ! [ld_assemble $as $srcdir/$subdir/weak2.s tmpdir/weak2.o]} then {
+ # It's OK if .weak doesn't work on this target.
+ unresolved $testname
+ return
+}
+
+set weak_regexp_big \
+".*Contents of section .text:.*1000 00001008 0000200c 12121212 34343434.*Contents of section .data:.*2000 00001008 0000200c 56565656 78787878.*"
+
+set weak_regexp_little \
+".*Contents of section .text:.*1000 08100000 0c200000 12121212 34343434.*Contents of section .data:.*2000 08100000 0c200000 56565656 78787878.*"
+
+if {! [ld_simple_link $ld tmpdir/weak "-T $srcdir/$subdir/weak.t tmpdir/weak1.o tmpdir/weak2.o"] } then {
+ fail $testname
+} else {
+ if {[which $objdump] == 0} then {
+ unresolved $testname
+ return
+ }
+
+ verbose -log "$objdump -s tmpdir/weak"
+ catch "exec $objdump -s tmpdir/weak" exec_output
+ set exec_output [prune_warnings $exec_output]
+ verbose -log $exec_output
+
+ if {[regexp $weak_regexp_big $exec_output] \
+ || [regexp $weak_regexp_little $exec_output] } then {
+ pass $testname
+ } else {
+ fail $testname
+ }
+}
diff --git a/ld/testsuite/ld-scripts/weak.t b/ld/testsuite/ld-scripts/weak.t
new file mode 100644
index 00000000000..6cd013e11f7
--- /dev/null
+++ b/ld/testsuite/ld-scripts/weak.t
@@ -0,0 +1,12 @@
+SECTIONS
+{
+ .text 0x1000 : {
+ tmpdir/weak1.o(.data)
+ }
+ .data 0x2000 : {
+ tmpdir/weak2.o(.data)
+ }
+ /DISCARD/ : {
+ *(*)
+ }
+}
diff --git a/ld/testsuite/ld-scripts/weak1.s b/ld/testsuite/ld-scripts/weak1.s
new file mode 100644
index 00000000000..046fbe1fa46
--- /dev/null
+++ b/ld/testsuite/ld-scripts/weak1.s
@@ -0,0 +1,11 @@
+.data
+ .global foo1
+ .global sym1
+ .weak sym2
+foo1:
+ .long sym1
+ .long sym2
+sym1:
+ .long 0x12121212
+sym2:
+ .long 0x34343434
diff --git a/ld/testsuite/ld-scripts/weak2.s b/ld/testsuite/ld-scripts/weak2.s
new file mode 100644
index 00000000000..04edff5e541
--- /dev/null
+++ b/ld/testsuite/ld-scripts/weak2.s
@@ -0,0 +1,11 @@
+.data
+ .global foo2
+ .weak sym1
+ .global sym2
+foo2:
+ .long sym1
+ .long sym2
+sym1:
+ .long 0x56565656
+sym2:
+ .long 0x78787878