]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR 31728 testcases
authorPali Rohár <pali@kernel.org>
Fri, 26 Jul 2024 05:40:18 +0000 (15:10 +0930)
committerAlan Modra <amodra@gmail.com>
Mon, 29 Jul 2024 10:31:06 +0000 (20:01 +0930)
13 files changed:
binutils/testsuite/lib/binutils-common.exp
ld/testsuite/ld-pe/exclude-symbols-def-i386.d
ld/testsuite/ld-pe/exclude-symbols-def-x86_64.d
ld/testsuite/ld-pe/exclude-symbols-embedded-i386.d
ld/testsuite/ld-pe/exclude-symbols-embedded-x86_64.d
ld/testsuite/ld-pe/pe.exp
ld/testsuite/ld-pe/symbols-ordinals-hints-call-imports.s [new file with mode: 0644]
ld/testsuite/ld-pe/symbols-ordinals-hints-exports-dlltool.d [new file with mode: 0644]
ld/testsuite/ld-pe/symbols-ordinals-hints-exports-ld.d [new file with mode: 0644]
ld/testsuite/ld-pe/symbols-ordinals-hints-exports.s [new file with mode: 0644]
ld/testsuite/ld-pe/symbols-ordinals-hints-imports-dlltool.d [new file with mode: 0644]
ld/testsuite/ld-pe/symbols-ordinals-hints-imports-ld.d [new file with mode: 0644]
ld/testsuite/ld-pe/symbols-ordinals-hints.def [new file with mode: 0644]

index cffd9cfe290bdb15f17887f8efa4ab17e47b2fcf..8d2840710876b09289b807df1141461415d52ab5 100644 (file)
@@ -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"
index 91426c57b12e4b59e99a68cd1f71cdf2ef076576..512b9ab3cdad52fa499c5ae4f34e724645b18605 100644 (file)
@@ -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
index e3f0698b2adc01a85807ae36f82d4c518b394843..d17de410e38cd9e5759885e4c4a9e3ce57dd06d7 100644 (file)
@@ -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
index fd79a7c9f410d2905d0486ff10ffb884954c0f2e..89ca6e6d02e5630f77b4d0750be8c884e2f85661 100644 (file)
@@ -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
index 780482e8d096b44a49f1ef42f9427b367de78835..5bbda0f1b586d941cbb4aa724cdf43a04e1da405 100644 (file)
@@ -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
index 6a30366ff6149d00333e48c23f0eb79ef85b7c4b..457b667c3649de0f6cb2d132c799175c053e040c 100644 (file)
@@ -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 (file)
index 0000000..475f72e
--- /dev/null
@@ -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 (file)
index 0000000..8de0976
--- /dev/null
@@ -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 (file)
index 0000000..0e7dcac
--- /dev/null
@@ -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 (file)
index 0000000..d775d70
--- /dev/null
@@ -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 (file)
index 0000000..6cfa5c4
--- /dev/null
@@ -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 (file)
index 0000000..1b17351
--- /dev/null
@@ -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 (file)
index 0000000..5b79a48
--- /dev/null
@@ -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