Don't trim trailing newline in run_host_cmd

Testcases like ld-elf/pr19719a.c that
    printf ("PASS\n");
on success ought to see the whole output for "string match".
Similarly, the ld-pe/ pdb*.d files shouldn't need to remove the last
newline to match.  For most of the testsuite it doesn't matter whether
the trailing newline is present or not, and there are only a few cases
where we need to remove it.

	* testsuite/lib/ld-lib.exp (run_host_cmd): Don't regsub away
	output trailing newline.  Do string trim for gcc/ld version checks.
	* testsuite/config/default.exp (plug_so): Do string trim output of
	run_host_cmd.
	* testsuite/ld-elf/shared.exp (mix_pic_and_non_pic): Adjust
	string match to include trailing newline.
	* testsuite/ld-i386/i386.exp (undefined_weak): Likewise.
	* testsuite/ld-x86-64/x86-64.exp (undefined_weak): Likewise.
	* testsuite/ld-plugin/libdep.exp (run_test): Likewise.
	* testsuite/ld-plugin/lto.exp (PR ld/28138 run): Likewise.
	* testsuite/ld-pe/pdb-strings.d,
	* testsuite/ld-pe/pdb-syms1-globals.d,
	* testsuite/ld-pe/pdb-syms1-records.d,
	* testsuite/ld-pe/pdb-syms1-symbols1.d,
	* testsuite/ld-pe/pdb-syms1-symbols2.d,
	* testsuite/ld-pe/pdb-syms2-symbols1.d,
	* testsuite/ld-pe/pdb-types1-hashlist.d,
	* testsuite/ld-pe/pdb-types1-skiplist.d,
	* testsuite/ld-pe/pdb-types1-typelist.d,
	* testsuite/ld-pe/pdb-types2-hashlist.d,
	* testsuite/ld-pe/pdb-types2-skiplist.d,
	* testsuite/ld-pe/pdb-types2-typelist.d,
	* testsuite/ld-pe/pdb-types3-hashlist.d,
	* testsuite/ld-pe/pdb-types3-skiplist.d,
	* testsuite/ld-pe/pdb-types3-typelist.d,
	* testsuite/ld-pe/pdb1-publics.d,
	* testsuite/ld-pe/pdb1-sym-record.d,
	* testsuite/ld-pe/pdb2-section-contrib.d,
	* testsuite/ld-pe/pdb3-c13-info1.d,
	* testsuite/ld-pe/pdb3-c13-info2.d,
	* testsuite/ld-pe/pdb3-source-info.d: Add trailing newline.
diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp
index 8374920..9ffcc58 100644
--- a/ld/testsuite/config/default.exp
+++ b/ld/testsuite/config/default.exp
@@ -519,9 +519,9 @@
 	cyglto_plugin-0.dll
     }
     foreach plug $plugin_names {
-	set plug_so [run_host_cmd $CC_FOR_TARGET "--print-prog-name $plug"]
+	set plug_so [string trim [run_host_cmd $CC_FOR_TARGET "--print-prog-name $plug"]]
 	if { $plug_so eq $plug } then {
-	    set plug_so [run_host_cmd $CC_FOR_TARGET "--print-file-name $plug"]
+	    set plug_so [string trim [run_host_cmd $CC_FOR_TARGET "--print-file-name $plug"]]
 	}
 	if { $plug_so ne $plug } then {
 	    set plug_opt "--plugin $plug_so"
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index 97ca778..281c3f5 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -1687,7 +1687,7 @@
     }
 
     set exec_output [run_host_cmd "tmpdir/$exe" ""]
-    if {![string match "PASS" $exec_output]} {
+    if {![string match "PASS\n" $exec_output]} {
 	fail "Run $exe fun undefined"
     } else {
 	pass "Run $exe fun undefined"
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index f96c514..5c9153f 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -553,9 +553,9 @@
 
     if { [string match "*-fPIE*" $cflags]
 	 && ![string match "*-z nodynamic-undefined-weak*" $ldflags] } {
-	set weak_symbol "Weak defined"
+	set weak_symbol "Weak defined\n"
     } else {
-	set weak_symbol "Weak undefined"
+	set weak_symbol "Weak undefined\n"
     }
 
     run_cc_link_tests [list \
diff --git a/ld/testsuite/ld-pe/pdb-strings.d b/ld/testsuite/ld-pe/pdb-strings.d
index 8be853e..2c9cd2e 100644
--- a/ld/testsuite/ld-pe/pdb-strings.d
+++ b/ld/testsuite/ld-pe/pdb-strings.d
@@ -7,4 +7,4 @@
  0020 7578000c 00000001 0000000a 00000000  ux..............
  0030 00000000 00000000 00000012 00000000  ................
  0040 00000000 00000002 00000006 00000000  ................
- 0050 0000000e 00000006 000000             ...........     
\ No newline at end of file
+ 0050 0000000e 00000006 000000             ...........     
diff --git a/ld/testsuite/ld-pe/pdb-syms1-globals.d b/ld/testsuite/ld-pe/pdb-syms1-globals.d
index 450f3a2..59f067b 100644
--- a/ld/testsuite/ld-pe/pdb-syms1-globals.d
+++ b/ld/testsuite/ld-pe/pdb-syms1-globals.d
@@ -53,4 +53,4 @@
  0300 54000000 60000000 6c000000 78000000  T...`...l...x...
  0310 90000000 9c000000 a8000000 b4000000  ................
  0320 c0000000 cc000000 d8000000 e4000000  ................
- 0330 f0000000 fc000000 14010000 2c010000  ............,...
\ No newline at end of file
+ 0330 f0000000 fc000000 14010000 2c010000  ............,...
diff --git a/ld/testsuite/ld-pe/pdb-syms1-records.d b/ld/testsuite/ld-pe/pdb-syms1-records.d
index d0abb6d..a0852ec 100644
--- a/ld/testsuite/ld-pe/pdb-syms1-records.d
+++ b/ld/testsuite/ld-pe/pdb-syms1-records.d
@@ -58,4 +58,4 @@
  0350 1c000000 02006776 61723300 12000e11  ......gvar3.....
  0360 00000000 08000000 03006776 61723400  ..........gvar4.
  0370 12000e11 02000000 00000000 01006d61  ..............ma
- 0380 696e0000                             in..            
\ No newline at end of file
+ 0380 696e0000                             in..            
diff --git a/ld/testsuite/ld-pe/pdb-syms1-symbols1.d b/ld/testsuite/ld-pe/pdb-syms1-symbols1.d
index 4de22ac..4c56508 100644
--- a/ld/testsuite/ld-pe/pdb-syms1-symbols1.d
+++ b/ld/testsuite/ld-pe/pdb-syms1-symbols1.d
@@ -5,4 +5,4 @@
  0000 04000000 2e001011 00000000 34000000  ............4...
  0010 00000000 01000000 00000000 00000000  ................
  0020 02100000 06000000 01000070 726f6332  ...........proc2
- 0030 00f3f2f1 02000600 00000000           ............    
\ No newline at end of file
+ 0030 00f3f2f1 02000600 00000000           ............    
diff --git a/ld/testsuite/ld-pe/pdb-syms1-symbols2.d b/ld/testsuite/ld-pe/pdb-syms1-symbols2.d
index c94d3ac..22c2f30 100644
--- a/ld/testsuite/ld-pe/pdb-syms1-symbols2.d
+++ b/ld/testsuite/ld-pe/pdb-syms1-symbols2.d
@@ -53,4 +53,4 @@
  0300 6f643400 02000600 12001211 00100000  od4.............
  0310 20000000 02006c76 61723500 12001211   .....lvar5.....
  0320 00100000 12000000 03006c76 61723600  ..........lvar6.
- 0330 00000000                             ....            
\ No newline at end of file
+ 0330 00000000                             ....            
diff --git a/ld/testsuite/ld-pe/pdb-syms2-symbols1.d b/ld/testsuite/ld-pe/pdb-syms2-symbols1.d
index 34132d1..028545b 100644
--- a/ld/testsuite/ld-pe/pdb-syms2-symbols1.d
+++ b/ld/testsuite/ld-pe/pdb-syms2-symbols1.d
@@ -35,4 +35,4 @@
  01e0 02000600 1e000211 48000000 04020000  ........H.......
  01f0 00000000 06000000 01000100 00746875  .............thu
  0200 6e6b00f1 02000600 0e005e11 04000000  nk........^.....
- 0210 01000100 02100000 02000600 00000000  ................
\ No newline at end of file
+ 0210 01000100 02100000 02000600 00000000  ................
diff --git a/ld/testsuite/ld-pe/pdb-types1-hashlist.d b/ld/testsuite/ld-pe/pdb-types1-hashlist.d
index 7d314ed..f9d8a74 100644
--- a/ld/testsuite/ld-pe/pdb-types1-hashlist.d
+++ b/ld/testsuite/ld-pe/pdb-types1-hashlist.d
@@ -12,4 +12,4 @@
  0070 4d5e0200 8a940200 4b710300 6aa90300  *
  0080 0a2c0300 67e10300 4a3d0300 fa460300  *
  0090 db020200 ec4e0100 131e0300 fb120300  *
- 00a0 aece0200 1db70100 99a30000 a8010100  *
\ No newline at end of file
+ 00a0 aece0200 1db70100 99a30000 a8010100  *
diff --git a/ld/testsuite/ld-pe/pdb-types1-skiplist.d b/ld/testsuite/ld-pe/pdb-types1-skiplist.d
index 52c10fa..f13b1d8 100644
--- a/ld/testsuite/ld-pe/pdb-types1-skiplist.d
+++ b/ld/testsuite/ld-pe/pdb-types1-skiplist.d
@@ -2,4 +2,4 @@
 *:     file format binary
 
 Contents of section .data:
- 0000 00100000 00000000                    *
\ No newline at end of file
+ 0000 00100000 00000000                    *
diff --git a/ld/testsuite/ld-pe/pdb-types1-typelist.d b/ld/testsuite/ld-pe/pdb-types1-typelist.d
index 248dda5..db08b52 100644
--- a/ld/testsuite/ld-pe/pdb-types1-typelist.d
+++ b/ld/testsuite/ld-pe/pdb-types1-typelist.d
@@ -77,4 +77,4 @@
  0480 3a001d15 2a100000 00000000 00000000  :...*...........
  0490 27000000 49556e6b 6e6f776e 00517565  '...IUnknown.Que
  04a0 7279496e 74657266 61636500 41646452  ryInterface.AddR
- 04b0 65660052 656c6561 736500f1           ef.Release..    
\ No newline at end of file
+ 04b0 65660052 656c6561 736500f1           ef.Release..    
diff --git a/ld/testsuite/ld-pe/pdb-types2-hashlist.d b/ld/testsuite/ld-pe/pdb-types2-hashlist.d
index 71d9045..d09fb3e 100644
--- a/ld/testsuite/ld-pe/pdb-types2-hashlist.d
+++ b/ld/testsuite/ld-pe/pdb-types2-hashlist.d
@@ -5,4 +5,4 @@
  0000 75cf0100 8d660300 f2a20300 aea00000  *
  0010 ef990300 223d0000 d6b60000 24070100  *
  0020 7f220100 f6d10200 16100200 010a0300  *
- 0030 0b4f0300 12690300 a56d0300           *
\ No newline at end of file
+ 0030 0b4f0300 12690300 a56d0300           *
diff --git a/ld/testsuite/ld-pe/pdb-types2-skiplist.d b/ld/testsuite/ld-pe/pdb-types2-skiplist.d
index 52c10fa..f13b1d8 100644
--- a/ld/testsuite/ld-pe/pdb-types2-skiplist.d
+++ b/ld/testsuite/ld-pe/pdb-types2-skiplist.d
@@ -2,4 +2,4 @@
 *:     file format binary
 
 Contents of section .data:
- 0000 00100000 00000000                    *
\ No newline at end of file
+ 0000 00100000 00000000                    *
diff --git a/ld/testsuite/ld-pe/pdb-types2-typelist.d b/ld/testsuite/ld-pe/pdb-types2-typelist.d
index d0fd26e..d8a36cc 100644
--- a/ld/testsuite/ld-pe/pdb-types2-typelist.d
+++ b/ld/testsuite/ld-pe/pdb-types2-typelist.d
@@ -17,4 +17,4 @@
  00c0 6500f2f1 12000116 00000000 01100000  e...............
  00d0 66756e63 3100f2f1 12000116 0b100000  func1...........
  00e0 01100000 66756e63 3200f2f1 12000216  ....func2.......
- 00f0 02100000 04100000 6d657468 6f6400f1  ........method..
\ No newline at end of file
+ 00f0 02100000 04100000 6d657468 6f6400f1  ........method..
diff --git a/ld/testsuite/ld-pe/pdb-types3-hashlist.d b/ld/testsuite/ld-pe/pdb-types3-hashlist.d
index 4a3775b..eda23d7 100644
--- a/ld/testsuite/ld-pe/pdb-types3-hashlist.d
+++ b/ld/testsuite/ld-pe/pdb-types3-hashlist.d
@@ -2,4 +2,4 @@
 *:     file format binary
 
 Contents of section .data:
- 0000 d4d90000 0c1c0000                    *
\ No newline at end of file
+ 0000 d4d90000 0c1c0000                    *
diff --git a/ld/testsuite/ld-pe/pdb-types3-skiplist.d b/ld/testsuite/ld-pe/pdb-types3-skiplist.d
index 52c10fa..f13b1d8 100644
--- a/ld/testsuite/ld-pe/pdb-types3-skiplist.d
+++ b/ld/testsuite/ld-pe/pdb-types3-skiplist.d
@@ -2,4 +2,4 @@
 *:     file format binary
 
 Contents of section .data:
- 0000 00100000 00000000                    *
\ No newline at end of file
+ 0000 00100000 00000000                    *
diff --git a/ld/testsuite/ld-pe/pdb-types3-typelist.d b/ld/testsuite/ld-pe/pdb-types3-typelist.d
index d6ffaad..48d7dbd 100644
--- a/ld/testsuite/ld-pe/pdb-types3-typelist.d
+++ b/ld/testsuite/ld-pe/pdb-types3-typelist.d
@@ -4,4 +4,4 @@
 Contents of section .data:
  0000 0e000516 00000000 666f6f2e 6800f2f1  ........foo.h...
  0010 10000716 01100000 01000000 2a000000  ............*...
- 0020 0100                                 ..              
\ No newline at end of file
+ 0020 0100                                 ..              
diff --git a/ld/testsuite/ld-pe/pdb1-publics.d b/ld/testsuite/ld-pe/pdb1-publics.d
index f7df2d9..0882f1b 100644
--- a/ld/testsuite/ld-pe/pdb1-publics.d
+++ b/ld/testsuite/ld-pe/pdb1-publics.d
@@ -38,4 +38,4 @@
  0210 00000000 00000000 00000000 00000000  ................
  0220 00000000 00000000 00000000 00000000  ................
  0230 00000000 00000000 00000000 00000000  ................
- 0240 00000000 0c000000 00000000 14000000  ................
\ No newline at end of file
+ 0240 00000000 0c000000 00000000 14000000  ................
diff --git a/ld/testsuite/ld-pe/pdb1-sym-record.d b/ld/testsuite/ld-pe/pdb1-sym-record.d
index 2078a5e..88cc21e 100644
--- a/ld/testsuite/ld-pe/pdb1-sym-record.d
+++ b/ld/testsuite/ld-pe/pdb1-sym-record.d
@@ -4,4 +4,4 @@
 Contents of section .data:
  0000 12000e11 02000000 08000000 0100666f  ..............fo
  0010 6f000000 12000e11 00000000 04000000  o...............
- 0020 02006261 72000000                    ..bar...        
\ No newline at end of file
+ 0020 02006261 72000000                    ..bar...        
diff --git a/ld/testsuite/ld-pe/pdb2-section-contrib.d b/ld/testsuite/ld-pe/pdb2-section-contrib.d
index 65ed76d..5b1df9f 100644
--- a/ld/testsuite/ld-pe/pdb2-section-contrib.d
+++ b/ld/testsuite/ld-pe/pdb2-section-contrib.d
@@ -9,4 +9,4 @@
  0040 00000000 3d000000 40000040 00000000  ....=...@..@....
  0050 00000000 00000000 04000000 00000000  ................
  0060 0c000000 40000042 02000000 00000000  ....@..B........
- 0070 00000000                             ....            
\ No newline at end of file
+ 0070 00000000                             ....            
diff --git a/ld/testsuite/ld-pe/pdb3-c13-info1.d b/ld/testsuite/ld-pe/pdb3-c13-info1.d
index 5a4f948..8c2f320 100644
--- a/ld/testsuite/ld-pe/pdb3-c13-info1.d
+++ b/ld/testsuite/ld-pe/pdb3-c13-info1.d
@@ -11,4 +11,4 @@
  0060 04000000 02000080 18000000 02000000  ................
  0070 1c000000 08000000 03000080 0c000000  ................
  0080 04000080 00000000 01000000 14000000  ................
- 0090 10000000 05000080                    ........        
\ No newline at end of file
+ 0090 10000000 05000080                    ........        
diff --git a/ld/testsuite/ld-pe/pdb3-c13-info2.d b/ld/testsuite/ld-pe/pdb3-c13-info2.d
index 1c33ce1..f74af2f 100644
--- a/ld/testsuite/ld-pe/pdb3-c13-info2.d
+++ b/ld/testsuite/ld-pe/pdb3-c13-info2.d
@@ -5,4 +5,4 @@
  0000 f4000000 30000000 06000000 100198ba  ....0...........
  0010 dcfe1023 45676745 2301efcd ab890000  ...#EggE#.......
  0020 0a000000 10013b2a 19087f6e 5d4c4c5d  ......;*...n]LL]
- 0030 6e7f0819 2a3b0000                    n...*;..        
\ No newline at end of file
+ 0030 6e7f0819 2a3b0000                    n...*;..        
diff --git a/ld/testsuite/ld-pe/pdb3-source-info.d b/ld/testsuite/ld-pe/pdb3-source-info.d
index 5b7d58c..4239c1c 100644
--- a/ld/testsuite/ld-pe/pdb3-source-info.d
+++ b/ld/testsuite/ld-pe/pdb3-source-info.d
@@ -4,4 +4,4 @@
 Contents of section .data:
  0000 03000300 00000100 02000200 02000000  ................
  0010 00000000 04000000 04000000 08000000  ................
- 0020 666f6f00 62617200 62617a00           foo.bar.baz.    
\ No newline at end of file
+ 0020 666f6f00 62617200 62617a00           foo.bar.baz.    
diff --git a/ld/testsuite/ld-plugin/libdep.exp b/ld/testsuite/ld-plugin/libdep.exp
index 6e56b6b..83b0872 100644
--- a/ld/testsuite/ld-plugin/libdep.exp
+++ b/ld/testsuite/ld-plugin/libdep.exp
@@ -104,7 +104,7 @@
     set exec_output [run_host_cmd "$ld" "-plugin $libdep_plugin -o libdep.exe libdep-main.o -L libdep-a -la -e 0"]
     set exec_output [prune_warnings $exec_output]
 
-    set expected_output "got deps for library libdep-a/liba.a: -Llibdep-b -lc"
+    set expected_output "got deps for library libdep-a/liba.a: -Llibdep-b -lc\n"
     
     if ![string match $expected_output $exec_output] then {
 	fail "$testname: did not get expected output from the linker"
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 9476caf..ad59e2a 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -895,7 +895,7 @@
 if [string match "" $exec_output] then {
     if { [isnative] } {
 	set exec_output [run_host_cmd "tmpdir/pr28138" ""]
-	if [string match "PASS" $exec_output] then {
+	if [string match "PASS\n" $exec_output] then {
 	    pass "PR ld/28138 (build & run)"
 	} else {
 	    fail "PR ld/28138 (built ok, run failed)"
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 57a1cc4..ea1a91a 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -774,9 +774,9 @@
 
     if { [string match "*-fPIE*" $cflags]
 	 && ![string match "*nodynamic-undefined-weak*" $ldflags] } {
-	set weak_symbol "Weak defined"
+	set weak_symbol "Weak defined\n"
     } else {
-	set weak_symbol "Weak undefined"
+	set weak_symbol "Weak undefined\n"
     }
 
     run_cc_link_tests [list \
diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index e6e643c..aeef82a 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -109,12 +109,12 @@
 	set gccflags "$gcc_B_opt $gccflags $ld_L_opt"
 	if {![info exists gcc_ld_B_opt_tested]} {
 	    set gcc_ld_B_opt_tested 1
-	    set ld_version_message [run_host_cmd "$ld" "--version"]
+	    set ld_version_message [string trim [run_host_cmd "$ld" "--version"]]
 	    set ver "-Wl,--version"
 	    if [check_lto_available] {
 		set ver "-fno-lto $ver"
 	    }
-	    set gcc_ld_version_message [run_host_cmd "$prog" "$gccflags $ver"]
+	    set gcc_ld_version_message [string trim [run_host_cmd "$prog" "$gccflags $ver"]]
 	    if {[string first $ld_version_message $gcc_ld_version_message] < 0} {
 		perror "************************************************************************"
 		perror "Your compiler apparently ignores -B when choosing ld."
@@ -123,7 +123,7 @@
 		    perror "Hint: don't configure gcc using --with-ld (or --with-as)"
 		}
 		perror "You will not be testing the new ld in many of the following tests."
-		set gcc_ld_version [run_host_cmd "$prog" "$gccflags --print-prog-name=ld"]
+		set gcc_ld_version [string trim [run_host_cmd "$prog" "$gccflags --print-prog-name=ld"]]
 		if {![string match "" $gcc_ld_version] && ![string match "ld" $gcc_ld_version]} {
 		    perror "It seems you will be testing $gcc_ld_version instead."
 		}
@@ -136,9 +136,8 @@
     set status [remote_exec host [concat sh -c [list "$prog $gccflags $command 2>&1"]] "" "/dev/null" "ld.tmp"]
     remote_upload host "ld.tmp"
     set link_output [file_contents "ld.tmp"]
-    regsub "\n$" $link_output "" link_output
     if { [lindex $status 0] != 0 && [string match "" $link_output] } then {
-	append link_output "child process exited abnormally"
+	set link_output "child process exited abnormally"
     }
     remote_file build delete ld.tmp
     remote_file host delete ld.tmp