aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPali Rohár <pali@kernel.org>2024-07-26 15:10:18 +0930
committerAlan Modra <amodra@gmail.com>2024-07-29 20:01:06 +0930
commitfb2a924990d3595c4b39cbcd37ebc36df761a3ad (patch)
treeab733665ef3bbc937acbd936b884ecf46c406c31
parent972092a9eda941a5744125f79fe58e52fb7007e4 (diff)
downloadbinutils-fb2a924990d3595c4b39cbcd37ebc36df761a3ad.zip
binutils-fb2a924990d3595c4b39cbcd37ebc36df761a3ad.tar.gz
binutils-fb2a924990d3595c4b39cbcd37ebc36df761a3ad.tar.bz2
PR 31728 testcases
-rw-r--r--binutils/testsuite/lib/binutils-common.exp23
-rw-r--r--ld/testsuite/ld-pe/exclude-symbols-def-i386.d8
-rw-r--r--ld/testsuite/ld-pe/exclude-symbols-def-x86_64.d8
-rw-r--r--ld/testsuite/ld-pe/exclude-symbols-embedded-i386.d8
-rw-r--r--ld/testsuite/ld-pe/exclude-symbols-embedded-x86_64.d8
-rw-r--r--ld/testsuite/ld-pe/pe.exp5
-rw-r--r--ld/testsuite/ld-pe/symbols-ordinals-hints-call-imports.s8
-rw-r--r--ld/testsuite/ld-pe/symbols-ordinals-hints-exports-dlltool.d21
-rw-r--r--ld/testsuite/ld-pe/symbols-ordinals-hints-exports-ld.d20
-rw-r--r--ld/testsuite/ld-pe/symbols-ordinals-hints-exports.s12
-rw-r--r--ld/testsuite/ld-pe/symbols-ordinals-hints-imports-dlltool.d27
-rw-r--r--ld/testsuite/ld-pe/symbols-ordinals-hints-imports-ld.d26
-rw-r--r--ld/testsuite/ld-pe/symbols-ordinals-hints.def9
13 files changed, 169 insertions, 14 deletions
diff --git a/binutils/testsuite/lib/binutils-common.exp b/binutils/testsuite/lib/binutils-common.exp
index cffd9cf..8d28407 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 91426c5..512b9ab 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 e3f0698..d17de41 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 fd79a7c..89ca6e6 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 780482e..5bbda0f 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 6a30366..457b667 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 0000000..475f72e
--- /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 0000000..8de0976
--- /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 0000000..0e7dcac
--- /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 0000000..d775d70
--- /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 0000000..6cfa5c4
--- /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 0000000..1b17351
--- /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 0000000..5b79a48
--- /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