Don't pass empty options to GCC
authorLuis Machado <luis.machado@linaro.org>
Wed, 24 Mar 2021 14:12:46 +0000 (11:12 -0300)
committerLuis Machado <luis.machado@linaro.org>
Mon, 29 Mar 2021 14:59:50 +0000 (11:59 -0300)
On aarch64-linux, I noticed the compile command didn't work at all.  It
always gave the following error:

aarch64-linux-gnu-g++: error: : No such file or directory

Turns out we're passing an empty argv entry to GCC (because aarch64 doesn't
have a -m64 option), and GCC's behavior is to think that is a file it needs
to open.  One can reproduce it like so:

gcc "" "" "" ""
gcc: error: : No such file or directory
gcc: error: : No such file or directory
gcc: error: : No such file or directory
gcc: error: : No such file or directory
gcc: fatal error: no input files
compilation terminated.

The solution is to check for an empty string and skip adding that to argv.

Regression tested on aarch64-linux/Ubuntu 18.04/20.04.

gdb/ChangeLog:

2021-03-29  Luis Machado  <luis.machado@linaro.org>

* compile/compile.c (get_args): Don't add empty argv entries.

gdb/ChangeLog
gdb/compile/compile.c

index 3e353b399a29f8441ce5f1c4b564cf9777776860..938b0ac43fb39d52c2e77e523840210a8c9597c4 100644 (file)
@@ -1,3 +1,7 @@
+2021-03-29  Luis Machado  <luis.machado@linaro.org>
+
+       * compile/compile.c (get_args): Don't add empty argv entries.
+
 2021-03-29  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
 
        gdb:
index d9c99bf432830b646a4d96cb7ce628fb3b511a75..5c5d51782c902e05a0bd33412089bfa7b290f9c2 100644 (file)
@@ -600,8 +600,14 @@ static gdb_argv
 get_args (const compile_instance *compiler, struct gdbarch *gdbarch)
 {
   const char *cs_producer_options;
+  gdb_argv result;
 
-  gdb_argv result (gdbarch_gcc_target_options (gdbarch).c_str ());
+  std::string gcc_options = gdbarch_gcc_target_options (gdbarch);
+
+  /* Make sure we have a non-empty set of options, otherwise GCC will
+     error out trying to look for a filename that is an empty string.  */
+  if (!gcc_options.empty ())
+    result = gdb_argv (gcc_options.c_str ());
 
   cs_producer_options = get_selected_pc_producer_options ();
   if (cs_producer_options != NULL)
This page took 0.027267 seconds and 4 git commands to generate.