Use ldflags instead of additional_flags for linker options

Message ID 20201207203512.7224-1-pedro@palves.net
State New
Headers show
Series
  • Use ldflags instead of additional_flags for linker options
Related show

Commit Message

Pedro Alves Dec. 7, 2020, 8:35 p.m.
A number of tests fail to compile against Clang like so:

  ...
  clang: warning: -Wl,--gdb-index: 'linker' input unused [-Wunused-command-line-argument]
  clang: warning: argument unused during compilation: '-fuse-ld=gold' [-Wunused-command-line-argument]
  output is:
  clang: warning: -Wl,--gdb-index: 'linker' input unused [-Wunused-command-line-argument]
  clang: warning: argument unused during compilation: '-fuse-ld=gold' [-Wunused-command-line-argument]

  gdb compile failed, clang: warning: -Wl,--gdb-index: 'linker' input unused [-Wunused-command-line-argument]
  clang: warning: argument unused during compilation: '-fuse-ld=gold' [-Wunused-command-line-argument]
  UNTESTED: gdb.base/gold-gdb-index.exp: failed to prepare
  ...

This is because Clang emits that warning when you specify a link
option but just compile without invoking the linker.  I.e., when you
do:

 $ clang test.c -Wl,--build-id -c
 clang: warning: -Wl,--build-id: 'linker' input unused [-Wunused-command-line-argument]

If you remove the -c, then clang doesn't warn:

 $ clang test.c -Wl,--build-id
 $

So to fix such tests, all we need is to move the -Wl,foo options from
additional_flags to ldflags.  ldflags is only used when linking,
additional_flags is passed to all compilations.  A number of tests
already use ldflags correctly, but several spots don't.  I grepped
like so:

  grep -rn "-Wl" | grep -v "ldflags"

and fixed all I found.  Similarly for "-Xlinker".

gdb/testsuite/ChangeLog:

	* gdb.base/break-on-linker-gcd-function.exp: Use 'ldflags' instead
	of 'additional_flags' for linker flags.
	* gdb.base/code_elim.exp: Likewise.
	* gdb.base/dump.exp: Likewise.
	* gdb.base/gcore-relro.exp: Likewise.
	* gdb.base/gold-gdb-index.exp: Likewise.
	* gdb.base/index-cache-load-twice: Likewise.
	* gdb.base/index-cache.exp: Likewise.
	* gdb.base/infoline-reloc-main-from-zero.exp: Likewise.
	* gdb.base/skip-solib.exp: Likewise.
	* gdb.btrace/unknown_functions.exp: Likewise.
	* gdb.reverse/solib-precsave.exp: Likewise.
	* gdb.threads/gcore-thread.exp: Likewise.
	* lib/gdb.exp: Likewise.
	* lib/jit-elf-helpers.ex: Likewise.
---
 gdb/testsuite/gdb.base/break-on-linker-gcd-function.exp  | 2 +-
 gdb/testsuite/gdb.base/code_elim.exp                     | 4 ++--
 gdb/testsuite/gdb.base/dump.exp                          | 2 +-
 gdb/testsuite/gdb.base/gcore-relro.exp                   | 2 +-
 gdb/testsuite/gdb.base/gold-gdb-index.exp                | 4 ++--
 gdb/testsuite/gdb.base/index-cache-load-twice.exp        | 2 +-
 gdb/testsuite/gdb.base/index-cache.exp                   | 2 +-
 gdb/testsuite/gdb.base/infoline-reloc-main-from-zero.exp | 2 +-
 gdb/testsuite/gdb.base/skip-solib.exp                    | 6 +++---
 gdb/testsuite/gdb.btrace/unknown_functions.exp           | 2 +-
 gdb/testsuite/gdb.reverse/solib-precsave.exp             | 2 +-
 gdb/testsuite/gdb.threads/gcore-thread.exp               | 2 +-
 gdb/testsuite/lib/gdb.exp                                | 6 +++---
 gdb/testsuite/lib/jit-elf-helpers.exp                    | 4 ++--
 14 files changed, 21 insertions(+), 21 deletions(-)


base-commit: bc545da73fff1e6dfa3493b5dcd73255c20adcf2
-- 
2.14.5

Comments

Tom Tromey Dec. 9, 2020, 8:42 p.m. | #1
>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:


Pedro> gdb/testsuite/ChangeLog:

Pedro> 	* gdb.base/break-on-linker-gcd-function.exp: Use 'ldflags' instead
Pedro> 	of 'additional_flags' for linker flags.
Pedro> 	* gdb.base/code_elim.exp: Likewise.
Pedro> 	* gdb.base/dump.exp: Likewise.
Pedro> 	* gdb.base/gcore-relro.exp: Likewise.
Pedro> 	* gdb.base/gold-gdb-index.exp: Likewise.
Pedro> 	* gdb.base/index-cache-load-twice: Likewise.
Pedro> 	* gdb.base/index-cache.exp: Likewise.
Pedro> 	* gdb.base/infoline-reloc-main-from-zero.exp: Likewise.
Pedro> 	* gdb.base/skip-solib.exp: Likewise.
Pedro> 	* gdb.btrace/unknown_functions.exp: Likewise.
Pedro> 	* gdb.reverse/solib-precsave.exp: Likewise.
Pedro> 	* gdb.threads/gcore-thread.exp: Likewise.
Pedro> 	* lib/gdb.exp: Likewise.
Pedro> 	* lib/jit-elf-helpers.ex: Likewise.

Looks good to me.  Thanks for doing this.

Tom

Patch

diff --git a/gdb/testsuite/gdb.base/break-on-linker-gcd-function.exp b/gdb/testsuite/gdb.base/break-on-linker-gcd-function.exp
index de63441bdd4..aaec85b7773 100644
--- a/gdb/testsuite/gdb.base/break-on-linker-gcd-function.exp
+++ b/gdb/testsuite/gdb.base/break-on-linker-gcd-function.exp
@@ -32,7 +32,7 @@  if [get_compiler_info "c++"] {
 }
 
 if {[build_executable_from_specs $testfile.exp $testfile \
-       {c++ additional_flags=-Wl,--gc-sections} \
+       {c++ ldflags=-Wl,--gc-sections} \
        $srcfile {debug c++ additional_flags=-ffunction-sections}]} {
     untested "failed to compile"
     return -1
diff --git a/gdb/testsuite/gdb.base/code_elim.exp b/gdb/testsuite/gdb.base/code_elim.exp
index 3d49c558ff1..040dba02df2 100644
--- a/gdb/testsuite/gdb.base/code_elim.exp
+++ b/gdb/testsuite/gdb.base/code_elim.exp
@@ -25,8 +25,8 @@  set binfile2 [standard_output_file ${testfile2}]
 set opts [list debug]
 lappend opts "additional_flags=-ffunction-sections"
 lappend opts "additional_flags=-fdata-sections"
-lappend opts "additional_flags=-Wl,-gc-sections"
-lappend opts "additional_flags=-Wl,-e,main"
+lappend opts "ldflags=-Wl,-gc-sections"
+lappend opts "ldflags=-Wl,-e,main"
 
 # Place variables in .data instead of .sdata.
 if {[istarget "riscv*-*-*"]} {
diff --git a/gdb/testsuite/gdb.base/dump.exp b/gdb/testsuite/gdb.base/dump.exp
index 23071ef0ed2..309c4d9ac30 100644
--- a/gdb/testsuite/gdb.base/dump.exp
+++ b/gdb/testsuite/gdb.base/dump.exp
@@ -27,7 +27,7 @@  set endian "auto"
 if [istarget "alpha*-*-*"] then {
     # SREC etc cannot handle 64-bit addresses.  Force the test
     # program into the low 31 bits of the address space.
-    lappend options "additional_flags=-Wl,-taso"
+    lappend options "ldflags=-Wl,-taso"
 }
 
 # Runs the command 'print zero_all ()'.  Uses the PRINT_ZERO_ALL_COUNT
diff --git a/gdb/testsuite/gdb.base/gcore-relro.exp b/gdb/testsuite/gdb.base/gcore-relro.exp
index fa84b781d38..e74016a40aa 100644
--- a/gdb/testsuite/gdb.base/gcore-relro.exp
+++ b/gdb/testsuite/gdb.base/gcore-relro.exp
@@ -29,7 +29,7 @@  set objfile [standard_output_file ${testfile}.o]
       untested "failed to compile"
       return -1
  }
- set opts [list debug shlib=${binfile_lib} additional_flags=-Wl,-z,relro]
+ set opts [list debug shlib=${binfile_lib} ldflags=-Wl,-z,relro]
  if { [gdb_compile ${objfile} ${binfile} executable $opts] != "" } {
       unsupported "-Wl,-z,relro compilation failed"
       return -1
diff --git a/gdb/testsuite/gdb.base/gold-gdb-index.exp b/gdb/testsuite/gdb.base/gold-gdb-index.exp
index 22a733af398..a2ac27aca91 100644
--- a/gdb/testsuite/gdb.base/gold-gdb-index.exp
+++ b/gdb/testsuite/gdb.base/gold-gdb-index.exp
@@ -22,8 +22,8 @@  if { [have_fuse_ld_gold] == 0} {
 }
 
 if {[prepare_for_testing "failed to prepare" $testfile "$srcfile $srcfile2" \
-	 {debug c++ additional_flags=-fuse-ld=gold \
-	      additional_flags=-Wl,--gdb-index \
+	 {debug c++ ldflags=-fuse-ld=gold \
+	      ldflags=-Wl,--gdb-index \
 	      additional_flags=-ggnu-pubnames}]} {
     return -1
 }
diff --git a/gdb/testsuite/gdb.base/index-cache-load-twice.exp b/gdb/testsuite/gdb.base/index-cache-load-twice.exp
index 5646062699d..f4afade4fea 100644
--- a/gdb/testsuite/gdb.base/index-cache-load-twice.exp
+++ b/gdb/testsuite/gdb.base/index-cache-load-twice.exp
@@ -33,7 +33,7 @@  save_vars { GDBFLAGS } {
     set GDBFLAGS "$GDBFLAGS -iex \"set index-cache on\""
 
     if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
-	  {debug additional_flags=-Wl,--build-id}] } {
+	  {debug ldflags=-Wl,--build-id}] } {
 	return
     }
 
diff --git a/gdb/testsuite/gdb.base/index-cache.exp b/gdb/testsuite/gdb.base/index-cache.exp
index 29803902f04..fddac961fec 100644
--- a/gdb/testsuite/gdb.base/index-cache.exp
+++ b/gdb/testsuite/gdb.base/index-cache.exp
@@ -19,7 +19,7 @@ 
 standard_testfile
 
 if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
-	  {debug additional_flags=-Wl,--build-id}] } {
+	  {debug ldflags=-Wl,--build-id}] } {
     return
 }
 
diff --git a/gdb/testsuite/gdb.base/infoline-reloc-main-from-zero.exp b/gdb/testsuite/gdb.base/infoline-reloc-main-from-zero.exp
index 82c5310233f..805cf07b3e0 100644
--- a/gdb/testsuite/gdb.base/infoline-reloc-main-from-zero.exp
+++ b/gdb/testsuite/gdb.base/infoline-reloc-main-from-zero.exp
@@ -29,7 +29,7 @@  if [get_compiler_info] {
 
 # Build executable with stripped startup code and text section starting at zero
 
-set opts {debug "additional_flags=-nostdlib -emain -Wl,-Ttext=0x00 -Wl,-N"}
+set opts {debug "ldflags=-nostdlib -emain -Wl,-Ttext=0x00 -Wl,-N"}
 
 if {[build_executable $testfile.exp $testfile $srcfile $opts] == -1} {
     untested "failed to compile"
diff --git a/gdb/testsuite/gdb.base/skip-solib.exp b/gdb/testsuite/gdb.base/skip-solib.exp
index 528410a0d53..5a4efe44a9a 100644
--- a/gdb/testsuite/gdb.base/skip-solib.exp
+++ b/gdb/testsuite/gdb.base/skip-solib.exp
@@ -39,7 +39,8 @@  set binfile_lib [standard_output_file ${libname}.so]
 # the main program.
 #
 
-if {[gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} [list debug additional_flags=-fPIC -Wl,-soname,${libname}.so]] != ""} {
+if {[gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} \
+	 [list debug additional_flags=-fPIC "ldflags=-Wl,-soname,${libname}.so"]] != ""} {
     return -1
 }
 
@@ -49,8 +50,7 @@  if {[gdb_compile "${srcdir}/${subdir}/${srcfile_main}" "${binfile_main}.o" objec
 
 set testobjdir [standard_output_file {}]
 if {[gdb_compile "${binfile_main}.o" "${binfile_main}" executable \
-                 [list debug "additional_flags=-L$testobjdir -l${test} \
-                                               -Wl,-rpath=$testobjdir"]] != ""} {
+                 [list debug "ldflags=-L$testobjdir -l${test} -Wl,-rpath=$testobjdir"]] != ""} {
     return -1
 }
 
diff --git a/gdb/testsuite/gdb.btrace/unknown_functions.exp b/gdb/testsuite/gdb.btrace/unknown_functions.exp
index 4db9c70f496..1b8c90968ba 100644
--- a/gdb/testsuite/gdb.btrace/unknown_functions.exp
+++ b/gdb/testsuite/gdb.btrace/unknown_functions.exp
@@ -25,7 +25,7 @@  if { [skip_btrace_tests] } {
 standard_testfile
 
 # discard local symbols
-set ldflags "additional_flags=-Wl,-x"
+set ldflags "ldflags=-Wl,-x"
 if [prepare_for_testing "failed to prepare" $testfile $srcfile $ldflags] {
     return -1
 }
diff --git a/gdb/testsuite/gdb.reverse/solib-precsave.exp b/gdb/testsuite/gdb.reverse/solib-precsave.exp
index e396e65066c..b7cd777bd4e 100644
--- a/gdb/testsuite/gdb.reverse/solib-precsave.exp
+++ b/gdb/testsuite/gdb.reverse/solib-precsave.exp
@@ -56,7 +56,7 @@  set exec_opts [list debug shlib=${library1} shlib=${library2}]
 # invalid core file.
 
 if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable \
-		     [concat $exec_opts additional_flags=-Wl,-z,norelro]] != ""
+		     [concat $exec_opts ldflags=-Wl,-z,norelro]] != ""
      && [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $exec_opts] != "" } {
     untested "failed to compile"
     return -1
diff --git a/gdb/testsuite/gdb.threads/gcore-thread.exp b/gdb/testsuite/gdb.threads/gcore-thread.exp
index 942bfb127b8..a5ee15846c7 100644
--- a/gdb/testsuite/gdb.threads/gcore-thread.exp
+++ b/gdb/testsuite/gdb.threads/gcore-thread.exp
@@ -35,7 +35,7 @@  if [istarget "*-*-linux"] then {
 
 set opts [list debug]
 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${objfile}" object $opts] != ""
-    || ([gdb_compile_pthreads "${objfile}" "${binfile}" executable [concat $opts {additional_flags=-Wl,-z,norelro}] ] != ""
+    || ([gdb_compile_pthreads "${objfile}" "${binfile}" executable [concat $opts {ldflags=-Wl,-z,norelro}] ] != ""
         && [gdb_compile_pthreads "${objfile}" "${binfile}" executable $opts] != "") } {
     return -1
 }
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index f2954fd5192..89befa7a076 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -4046,7 +4046,7 @@  proc gdb_compile {source dest type options} {
                 set shlib_found 1
 		if { ([istarget "*-*-mingw*"]
 		      || [istarget *-*-cygwin*]) } {
-		    lappend new_options "additional_flags=-Wl,--enable-auto-import"
+		    lappend new_options "ldflags=-Wl,--enable-auto-import"
 		}
 		if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
 		    # Undo debian's change in the default.
@@ -4350,7 +4350,7 @@  proc gdb_compile_shlib {sources dest options} {
 	    } else {
 		set name ${dest}
 	    }
-	    lappend link_options "additional_flags=-Wl,--out-implib,${name}.a"
+	    lappend link_options "ldflags=-Wl,--out-implib,${name}.a"
 	} else {
 	    # Set the soname of the library.  This causes the linker on ELF
 	    # systems to create the DT_NEEDED entry in the executable referring
@@ -4362,7 +4362,7 @@  proc gdb_compile_shlib {sources dest options} {
 	    # rpath=$ORIGIN value when building the executable, so that it's
 	    # able to find the library in its own directory.
 	    set destbase [file tail $dest]
-	    lappend link_options "additional_flags=-Wl,-soname,$destbase"
+	    lappend link_options "ldflags=-Wl,-soname,$destbase"
 	}
     }
     if {[gdb_compile "${objects}" "${dest}" executable $link_options] != ""} {
diff --git a/gdb/testsuite/lib/jit-elf-helpers.exp b/gdb/testsuite/lib/jit-elf-helpers.exp
index f1e8ad77852..44925ab94d8 100644
--- a/gdb/testsuite/lib/jit-elf-helpers.exp
+++ b/gdb/testsuite/lib/jit-elf-helpers.exp
@@ -94,8 +94,8 @@  proc compile_and_download_n_jit_so {jit_solib_basename jit_solib_srcfile count}
 	# to dynamically execute functions from it without any further adjustments.
 	set options [list \
 	    additional_flags=-DFUNCTION_NAME=[format "jit_function_%04d" $i] \
-	    additional_flags=-Xlinker \
-	    additional_flags=-Ttext-segment=$addr]
+	    ldflags=-Xlinker \
+	    ldflags=-Ttext-segment=$addr]
 	if { [gdb_compile_shlib ${jit_solib_srcfile} ${binfile} \
 		  $options] != "" } {
 	    set f [file tail $binfile]