[binutils-gdb] PR 31728 testcases

Alan Modra amodra@sourceware.org
Mon Jul 29 10:32:55 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fb2a924990d3595c4b39cbcd37ebc36df761a3ad

commit fb2a924990d3595c4b39cbcd37ebc36df761a3ad
Author: Pali Rohár <pali@kernel.org>
Date:   Fri Jul 26 15:10:18 2024 +0930

    PR 31728 testcases

Diff:
---
 binutils/testsuite/lib/binutils-common.exp         | 23 ++++++++++++++++--
 ld/testsuite/ld-pe/exclude-symbols-def-i386.d      |  8 ++++---
 ld/testsuite/ld-pe/exclude-symbols-def-x86_64.d    |  8 ++++---
 ld/testsuite/ld-pe/exclude-symbols-embedded-i386.d |  8 ++++---
 .../ld-pe/exclude-symbols-embedded-x86_64.d        |  8 ++++---
 ld/testsuite/ld-pe/pe.exp                          |  5 ++++
 .../ld-pe/symbols-ordinals-hints-call-imports.s    |  8 +++++++
 .../ld-pe/symbols-ordinals-hints-exports-dlltool.d | 21 +++++++++++++++++
 .../ld-pe/symbols-ordinals-hints-exports-ld.d      | 20 ++++++++++++++++
 .../ld-pe/symbols-ordinals-hints-exports.s         | 12 ++++++++++
 .../ld-pe/symbols-ordinals-hints-imports-dlltool.d | 27 ++++++++++++++++++++++
 .../ld-pe/symbols-ordinals-hints-imports-ld.d      | 26 +++++++++++++++++++++
 ld/testsuite/ld-pe/symbols-ordinals-hints.def      |  9 ++++++++
 13 files changed, 169 insertions(+), 14 deletions(-)

diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
index cffd9cfe290..8d284071087 100644
--- a/binutils/testsuite/lib/binutils-common.exp
+++ b/binutils/testsuite/lib/binutils-common.exp
@@ -814,6 +814,9 @@ proc prune_dump_output { output } {
 #       the "as" flags for their corresponding files, and any extra processing
 #       (e.g. with "ld" and "objcopy") is repeated for each test.
 #
+#   dlltool: FLAGS
+#       Before linking, run dlltool with FLAGS.
+#
 #   ld: FLAGS
 #	Link assembled files using FLAGS, in the order of the "source"
 #	directives, when using multiple files.
@@ -956,7 +959,7 @@ proc run_dump_test { name {extra_options {}} } {
     global ELFEDIT ELFEDITFLAGS LD LDFLAGS NM NMFLAGS OBJCOPY OBJCOPYFLAGS
     global OBJDUMP OBJDUMPFLAGS READELF READELFFLAGS STRIP STRIPFLAGS
     global SIZE SIZEFLAGS
-    global copyfile env runtests srcdir subdir verbose
+    global copyfile env runtests srcdir subdir verbose base_dir
     global DT_RELR_LDFLAGS NO_DT_RELR_LDFLAGS
 
     if [string match "*/*" $name] {
@@ -990,6 +993,7 @@ proc run_dump_test { name {extra_options {}} } {
     set as_final_flags {}
     set as_additional_flags {}
     set opts(cc) {}
+    set opts(dlltool) {}
     set opts(dump) {}
     set opts(elfedit) {}
     set opts(error) {}
@@ -1036,12 +1040,14 @@ proc run_dump_test { name {extra_options {}} } {
 	# Allow more substitutions, including tcl functions, for as, ld,
 	# and cc.  Not done in general because extra quoting is needed for glob
 	# args used for example in binutils-all/remove-relocs-04.d.
-	if { $opt_name == "as" || $opt_name == "ld" || $opt_name == "cc" } {
+	if { $opt_name == "as" || $opt_name == "ld" || $opt_name == "ld_after_inputfiles" || $opt_name == "cc" } {
 	    set opt_val [subst $opt_val]
 	} else {
 	    # Just substitute $srcdir and $subdir
 	    regsub -all {\$srcdir} "$opt_val" "$srcdir" opt_val
 	    regsub -all {\$subdir} "$opt_val" "$subdir" opt_val
+	    regsub -all {\$\{srcdir\}} "$opt_val" "$srcdir" opt_val
+	    regsub -all {\$\{subdir\}} "$opt_val" "$subdir" opt_val
 	}
 
 	switch -- $opt_name {
@@ -1381,6 +1387,19 @@ proc run_dump_test { name {extra_options {}} } {
 	    }
 	}
 
+	# Run dlltool.
+	if { $cmdret == 0 && $opts(dlltool) != "" } {
+	    set dlltool [findfile $base_dir/../binutils/dlltool]
+	    set cmd "$dlltool -S $AS $opts(dlltool)"
+	    send_log "$cmd\n"
+	    set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "dump.tmp"]
+	    remote_upload host "dump.tmp"
+	    append comp_output [prune_warnings [file_contents "dump.tmp"]]
+	    remote_file host delete "dump.tmp"
+	    remote_file build delete "dump.tmp"
+	    set cmdret [lindex $cmdret 0]
+	}
+
 	# Perhaps link the file(s).
 	if { $cmdret == 0 && $run_ld } {
 	    set objfile "tmpdir/dump"
diff --git a/ld/testsuite/ld-pe/exclude-symbols-def-i386.d b/ld/testsuite/ld-pe/exclude-symbols-def-i386.d
index 91426c57b12..512b9ab3cda 100644
--- a/ld/testsuite/ld-pe/exclude-symbols-def-i386.d
+++ b/ld/testsuite/ld-pe/exclude-symbols-def-i386.d
@@ -4,7 +4,9 @@
 #objdump: -p
 
 #...
-.*\[[ 	]*0\].*sym1
-.*\[[ 	]*1\].*sym3
-.*\[[ 	]*2\].*sym5
+.*      Ordinal   Hint Name
+.*\+base\[   1\]  0000 sym1
+.*\+base\[   2\]  0001 sym3
+.*\+base\[   3\]  0002 sym5
+
 #pass
diff --git a/ld/testsuite/ld-pe/exclude-symbols-def-x86_64.d b/ld/testsuite/ld-pe/exclude-symbols-def-x86_64.d
index e3f0698b2ad..d17de410e38 100644
--- a/ld/testsuite/ld-pe/exclude-symbols-def-x86_64.d
+++ b/ld/testsuite/ld-pe/exclude-symbols-def-x86_64.d
@@ -4,7 +4,9 @@
 #objdump: -p
 
 #...
-.*\[[ 	]*0\].*sym1
-.*\[[ 	]*1\].*sym3
-.*\[[ 	]*2\].*sym5
+.*      Ordinal   Hint Name
+.*\+base\[   1\]  0000 sym1
+.*\+base\[   2\]  0001 sym3
+.*\+base\[   3\]  0002 sym5
+
 #pass
diff --git a/ld/testsuite/ld-pe/exclude-symbols-embedded-i386.d b/ld/testsuite/ld-pe/exclude-symbols-embedded-i386.d
index fd79a7c9f41..89ca6e6d02e 100644
--- a/ld/testsuite/ld-pe/exclude-symbols-embedded-i386.d
+++ b/ld/testsuite/ld-pe/exclude-symbols-embedded-i386.d
@@ -4,7 +4,9 @@
 #objdump: -p
 
 #...
-.*\[[ 	]*0\].*sym1
-.*\[[ 	]*1\].*sym3
-.*\[[ 	]*2\].*sym5
+.*      Ordinal   Hint Name
+.*\+base\[   1\]  0000 sym1
+.*\+base\[   2\]  0001 sym3
+.*\+base\[   3\]  0002 sym5
+
 #pass
diff --git a/ld/testsuite/ld-pe/exclude-symbols-embedded-x86_64.d b/ld/testsuite/ld-pe/exclude-symbols-embedded-x86_64.d
index 780482e8d09..5bbda0f1b58 100644
--- a/ld/testsuite/ld-pe/exclude-symbols-embedded-x86_64.d
+++ b/ld/testsuite/ld-pe/exclude-symbols-embedded-x86_64.d
@@ -4,7 +4,9 @@
 #objdump: -p
 
 #...
-.*\[[ 	]*0\].*sym1
-.*\[[ 	]*1\].*sym3
-.*\[[ 	]*2\].*sym5
+.*      Ordinal   Hint Name
+.*\+base\[   1\]  0000 sym1
+.*\+base\[   2\]  0001 sym3
+.*\+base\[   3\]  0002 sym5
+
 #pass
diff --git a/ld/testsuite/ld-pe/pe.exp b/ld/testsuite/ld-pe/pe.exp
index 6a30366ff61..457b667c364 100644
--- a/ld/testsuite/ld-pe/pe.exp
+++ b/ld/testsuite/ld-pe/pe.exp
@@ -144,3 +144,8 @@ run_dump_test "exclude-symbols-embedded-i386"
 run_dump_test "exclude-symbols-embedded-x86_64"
 run_dump_test "exclude-symbols-def-i386"
 run_dump_test "exclude-symbols-def-x86_64"
+
+run_dump_test "symbols-ordinals-hints-exports-ld"
+run_dump_test "symbols-ordinals-hints-exports-dlltool"
+run_dump_test "symbols-ordinals-hints-imports-ld"
+run_dump_test "symbols-ordinals-hints-imports-dlltool"
diff --git a/ld/testsuite/ld-pe/symbols-ordinals-hints-call-imports.s b/ld/testsuite/ld-pe/symbols-ordinals-hints-call-imports.s
new file mode 100644
index 00000000000..475f72ee85e
--- /dev/null
+++ b/ld/testsuite/ld-pe/symbols-ordinals-hints-call-imports.s
@@ -0,0 +1,8 @@
+.global _func
+_func:
+  call __imp__sym1
+  call __imp__sym2
+  call __imp__sym3
+  call __imp__sym4
+  call __imp__sym5
+  ret
diff --git a/ld/testsuite/ld-pe/symbols-ordinals-hints-exports-dlltool.d b/ld/testsuite/ld-pe/symbols-ordinals-hints-exports-dlltool.d
new file mode 100644
index 00000000000..8de09760cec
--- /dev/null
+++ b/ld/testsuite/ld-pe/symbols-ordinals-hints-exports-dlltool.d
@@ -0,0 +1,21 @@
+#source: symbols-ordinals-hints-exports.s
+#dlltool: -d ${srcdir}/${subdir}/symbols-ordinals-hints.def -e exports-dlltool.o
+#ld: -shared exports-dlltool.o
+#objdump: -p
+
+# Rules for Ordinal/Name Pointer Table:
+# - Table rows must be lexicographically sorted by symbol names
+# - Hint numbers must be in sequence starting from zero
+# - Ordinal numbers must match the @ordinal keyword from .def file
+# - Symbols in .def file without @ordinal keyword have assigned the first free ordinal starting from 1
+# - Symbols in .def file with NONAME keyword must not be present in Name Pointer Table
+
+#...
+.*\[Ordinal/Name Pointer\] Table -- Ordinal Base.*
+.*      Ordinal   Hint Name
+.*\+base\[   2\]  0000 sym1
+.*\+base\[   5\]  0001 sym2
+.*\+base\[   3\]  0002 sym4
+.*\+base\[   4\]  0003 sym5
+
+#pass
diff --git a/ld/testsuite/ld-pe/symbols-ordinals-hints-exports-ld.d b/ld/testsuite/ld-pe/symbols-ordinals-hints-exports-ld.d
new file mode 100644
index 00000000000..0e7dcaca6f3
--- /dev/null
+++ b/ld/testsuite/ld-pe/symbols-ordinals-hints-exports-ld.d
@@ -0,0 +1,20 @@
+#source: symbols-ordinals-hints-exports.s
+#ld: -shared ${srcdir}/${subdir}/symbols-ordinals-hints.def
+#objdump: -p
+
+# Rules for Ordinal/Name Pointer Table:
+# - Table rows must be lexicographically sorted by symbol names
+# - Hint numbers must be in sequence starting from zero
+# - Ordinal numbers must match the @ordinal keyword from .def file
+# - Symbols in .def file without @ordinal keyword have assigned the first free ordinal starting from 1
+# - Symbols in .def file with NONAME keyword must not be present in Name Pointer Table
+
+#...
+.*\[Ordinal/Name Pointer\] Table -- Ordinal Base.*
+.*      Ordinal   Hint Name
+.*\+base\[   2\]  0000 sym1
+.*\+base\[   5\]  0001 sym2
+.*\+base\[   3\]  0002 sym4
+.*\+base\[   4\]  0003 sym5
+
+#pass
diff --git a/ld/testsuite/ld-pe/symbols-ordinals-hints-exports.s b/ld/testsuite/ld-pe/symbols-ordinals-hints-exports.s
new file mode 100644
index 00000000000..d775d7093c5
--- /dev/null
+++ b/ld/testsuite/ld-pe/symbols-ordinals-hints-exports.s
@@ -0,0 +1,12 @@
+# define symbols in no specific order
+.global _sym2
+.global _sym5
+.global _sym3
+.global _sym1
+.global _sym4
+_sym2:
+_sym5:
+_sym3:
+_sym1:
+_sym4:
+  ret
diff --git a/ld/testsuite/ld-pe/symbols-ordinals-hints-imports-dlltool.d b/ld/testsuite/ld-pe/symbols-ordinals-hints-imports-dlltool.d
new file mode 100644
index 00000000000..6cfa5c4a02f
--- /dev/null
+++ b/ld/testsuite/ld-pe/symbols-ordinals-hints-imports-dlltool.d
@@ -0,0 +1,27 @@
+#source: symbols-ordinals-hints-call-imports.s
+#dlltool: -d ${srcdir}/${subdir}/symbols-ordinals-hints.def -l libimports-dlltool.a
+#ld: -shared
+#ld_after_inputfiles: libimports-dlltool.a
+#objdump: -p
+
+# Rules for Import Tables:
+# - Ordinal, Hint and Member-Name (what is present) match Ordinal/Name Pointer Table of
+#   the external DLL (from corresponding symbols-ordinals-hints-exports-*.d test)
+# - Symbols in .def file with NONAME keyword have only Ordinal, must no have Hint and Member-Name
+# - Symbols in .def file without NONAME keyword have Hint and Member-Name, must not have Ordinal
+
+#...
+The Import Tables \(interpreted \.idata section contents\)
+ vma:            Hint    Time      Forward  DLL       First
+                 Table   Stamp     Chain    Name      Thunk
+.*
+
+.*DLL Name:.*
+.* Ordinal  Hint  Member-Name  Bound-To
+.*  <none>  0000  sym1
+.*  <none>  0001  sym2
+.*      1  <none> <none>
+.*  <none>  0002  sym4
+.*  <none>  0003  sym5
+
+#pass
diff --git a/ld/testsuite/ld-pe/symbols-ordinals-hints-imports-ld.d b/ld/testsuite/ld-pe/symbols-ordinals-hints-imports-ld.d
new file mode 100644
index 00000000000..1b173510a84
--- /dev/null
+++ b/ld/testsuite/ld-pe/symbols-ordinals-hints-imports-ld.d
@@ -0,0 +1,26 @@
+#source: symbols-ordinals-hints-exports.s
+#ld: -shared ${srcdir}/${subdir}/symbols-ordinals-hints.def --out-implib libimports-ld.a
+#ld_after_inputfiles: && $AS ${srcdir}/${subdir}/symbols-ordinals-hints-call-imports.s -o call-imports-ld.o && $LD -shared call-imports-ld.o libimports-ld.a -o tmpdir/dump
+#objdump: -p
+
+# Rules for Import Tables:
+# - Ordinal, Hint and Member-Name (what is present) match Ordinal/Name Pointer Table of
+#   the external DLL (from corresponding symbols-ordinals-hints-exports-*.d test)
+# - Symbols in .def file with NONAME keyword have only Ordinal, must no have Hint and Member-Name
+# - Symbols in .def file without NONAME keyword have Hint and Member-Name, must not have Ordinal
+
+#...
+The Import Tables \(interpreted \.idata section contents\)
+ vma:            Hint    Time      Forward  DLL       First
+                 Table   Stamp     Chain    Name      Thunk
+.*
+
+.*DLL Name:.*
+.* Ordinal  Hint  Member-Name  Bound-To
+.*  <none>  0000  sym1
+.*  <none>  0001  sym2
+.*      1  <none> <none>
+.*  <none>  0002  sym4
+.*  <none>  0003  sym5
+
+#pass
diff --git a/ld/testsuite/ld-pe/symbols-ordinals-hints.def b/ld/testsuite/ld-pe/symbols-ordinals-hints.def
new file mode 100644
index 00000000000..5b79a483eeb
--- /dev/null
+++ b/ld/testsuite/ld-pe/symbols-ordinals-hints.def
@@ -0,0 +1,9 @@
+LIBRARY "symbols-ordinals-hints.dll"
+EXPORTS
+; define symbols in no specific order
+; define ordinals also in no specific order
+sym2 @5
+sym5
+sym3 @1 NONAME
+sym1 @2
+sym4


More information about the Binutils-cvs mailing list