Add a testcase for PR ld/22751
authorH.J. Lu <hjl.tools@gmail.com>
Sun, 28 Jan 2018 00:04:34 +0000 (16:04 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Sun, 28 Jan 2018 00:04:34 +0000 (16:04 -0800)
Since dummy.o must be placed before

-Wl,--whole-archive tmpdir/pr22751.a -Wl,--no-whole-archive

to trigger the bug, this patch adds an optional trailing ld options to
run_ld_link_exec_tests.

PR ld/22751
* testsuite/config/default.exp (INT128_CFLAGS): New.
* testsuite/ld-plugin/lto.exp (INT128_CFLAGS): New.
Run ld/22751 tests.
* testsuite/ld-plugin/pr22751.c: New file.
* testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Add
ld trailing options.

ld/ChangeLog
ld/testsuite/config/default.exp
ld/testsuite/ld-plugin/lto.exp
ld/testsuite/ld-plugin/pr22751.c [new file with mode: 0644]
ld/testsuite/lib/ld-lib.exp

index f32b42fa904c6ffee26444e590404eae75704d57..d1de69843f4ff79f2f2128e8da08d30dd3eea11e 100644 (file)
@@ -1,3 +1,13 @@
+2018-01-27  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/22751
+       * testsuite/config/default.exp (INT128_CFLAGS): New.
+       * testsuite/ld-plugin/lto.exp (INT128_CFLAGS): New.
+       Run ld/22751 tests.
+       * testsuite/ld-plugin/pr22751.c: New file.
+       * testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Add
+       ld trailing options.
+
 2018-01-28  Alan Modra  <amodra@gmail.com>
 
        PR 22751
index 29c020ffa46ed77358d05c63fa8e6100e37e9a28..fe3bd3204aa445830da42cd5fb9673733702107b 100644 (file)
@@ -376,3 +376,40 @@ if { ![info exists GNU2_CFLAGS] } then {
        set GNU2_CFLAGS ""
     }
 }
+
+# Set INT128_CFLAGS to "-DHAS_INT128" if target compiler supports __int128.
+
+if { ![info exists INT128_CFLAGS] } then {
+    if { [which $CC] != 0 } {
+       # Check if gcc supports __int128.
+       set flags ""
+       if [board_info [target_info name] exists cflags] {
+           append flags " [board_info [target_info name] cflags]"
+       }
+       if [board_info [target_info name] exists ldflags] {
+           append flags " [board_info [target_info name] ldflags]"
+       }
+
+       set basename "tmpdir/int128[pid]"
+       set src ${basename}.c
+       set output ${basename}.o
+       set f [open $src "w"]
+       puts $f "__int128 a = 42;"
+       close $f
+       if [is_remote host] {
+           set src [remote_download host $src]
+       }
+       set int128_available [run_host_cmd_yesno "$CC" "$flags -c $src -o $output"]
+       remote_file host delete $src
+       remote_file host delete $output
+       file delete $src
+
+       if { $int128_available == 1 } then {
+           set INT128_CFLAGS "-DHAS_INT128"
+       } else {
+           set INT128_CFLAGS ""
+       }
+    } else {
+       set INT128_CFLAGS ""
+    }
+}
index 896f453def1d7787cb9a171a8b452002f8f12cf8..7300f481f31f16fdf4a971036ff59481a4f081c0 100644 (file)
@@ -29,6 +29,8 @@ if { ![check_plugin_api_available]
     return
 }
 
+global INT128_CFLAGS
+
 global CFLAGS
 global CXXFLAGS
 set saved_CFLAGS "$CFLAGS"
@@ -214,6 +216,9 @@ set lto_link_tests [list \
   [list "Build pr22502b.o" \
    "$plug_opt" "-flto $lto_no_fat" \
    {pr22502b.c}] \
+  [list "Build pr22751.a" \
+   "$plug_opt" "-flto $lto_no_fat $INT128_CFLAGS" \
+   {pr22751.c} {} "pr22751.a"] \
 ]
 
 if { [at_least_gcc_version 4 7] } {
@@ -400,6 +405,10 @@ set lto_run_tests [list \
   [list "Run pr22502" \
    "-O2 -flto tmpdir/pr22502a.o tmpdir/pr22502b.o" "" \
    {dummy.c} "pr20267" "pass.out" "-flto -O2" "c"] \
+  [list "Run pr22751" \
+   "-O2 -flto" "" \
+   {dummy.c} "pr22751" "pass.out" "-flto -O2" "c" "" \
+   "-Wl,--whole-archive tmpdir/pr22751.a -Wl,--no-whole-archive"] \
 ]
 
 if { [at_least_gcc_version 4 7] } {
diff --git a/ld/testsuite/ld-plugin/pr22751.c b/ld/testsuite/ld-plugin/pr22751.c
new file mode 100644 (file)
index 0000000..33c1bf3
--- /dev/null
@@ -0,0 +1,17 @@
+#include <stdio.h>
+
+#ifdef HAS_INT128
+volatile __int128 a = 42;
+volatile __int128 b = 1;
+#else
+volatile long long a = 42;
+volatile long long b = 1;
+#endif
+
+int
+main (void)
+{
+  if (((int) (a / b)) == 42)
+    printf ("PASS\n");
+  return 0;
+}
index 52baf0b04ce24592318d79db43105cc02df9e81c..a892b763984ad731b8bd781e9591f7b8fd036763 100644 (file)
@@ -1377,7 +1377,7 @@ if ![string length [info proc prune_warnings]] {
 # ldtests contains test-items with 3 items followed by 1 lists, 2 items
 # and 3 optional items:
 #   0:name
-#   1:ld options
+#   1:ld leading options, placed before object files
 #   2:assembler options
 #   3:filenames of source files
 #   4:name of output file
@@ -1385,6 +1385,7 @@ if ![string length [info proc prune_warnings]] {
 #   6:compiler flags (optional)
 #   7:language (optional)
 #   8:linker warning (optional)
+#   9:ld trailing options, placed after object files (optional)
 # args is an optional list of target triplets to be xfailed.
 
 proc run_ld_link_exec_tests { ldtests args } {
@@ -1424,6 +1425,7 @@ proc run_ld_link_exec_tests { ldtests args } {
        set cflags [lindex $testitem 6]
        set lang [lindex $testitem 7]
        set warning [lindex $testitem 8]
+       set ld_after [lindex $testitem 9]
        set objfiles {}
        set failed 0
 
@@ -1466,7 +1468,7 @@ proc run_ld_link_exec_tests { ldtests args } {
            # compile only
            pass $testname
            continue;
-       } elseif ![$link_proc $link_cmd $binfile "$board_cflags -L$srcdir/$subdir $ld_options $objfiles"] {
+       } elseif ![$link_proc $link_cmd $binfile "$board_cflags -L$srcdir/$subdir $ld_options $objfiles $ld_after"] {
            set failed 1
        }
 
This page took 0.029057 seconds and 4 git commands to generate.