* [PATCH] [compile] Don't pass empty options to GCC
@ 2021-03-24 14:59 Luis Machado
2021-03-24 18:53 ` Andrew Burgess
0 siblings, 1 reply; 4+ messages in thread
From: Luis Machado @ 2021-03-24 14:59 UTC (permalink / raw)
To: gdb-patches
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:
YYYY-MM-DD Luis Machado <luis.machado@linaro.org>
* compile/compile.c (get_args): Don't add empty argv entries.
---
gdb/compile/compile.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index d9c99bf4328..32f522a7aba 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -600,8 +600,12 @@ 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 ());
+ /* 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 (!gdbarch_gcc_target_options (gdbarch).empty ())
+ result.append (gdb_argv (gdbarch_gcc_target_options (gdbarch).c_str ()));
cs_producer_options = get_selected_pc_producer_options ();
if (cs_producer_options != NULL)
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] [compile] Don't pass empty options to GCC
2021-03-24 14:59 [PATCH] [compile] Don't pass empty options to GCC Luis Machado
@ 2021-03-24 18:53 ` Andrew Burgess
2021-03-26 11:41 ` Luis Machado
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Burgess @ 2021-03-24 18:53 UTC (permalink / raw)
To: Luis Machado; +Cc: gdb-patches
* Luis Machado via Gdb-patches <gdb-patches@sourceware.org> [2021-03-24 11:59: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:
>
> YYYY-MM-DD Luis Machado <luis.machado@linaro.org>
>
> * compile/compile.c (get_args): Don't add empty argv entries.
> ---
> gdb/compile/compile.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
> index d9c99bf4328..32f522a7aba 100644
> --- a/gdb/compile/compile.c
> +++ b/gdb/compile/compile.c
> @@ -600,8 +600,12 @@ 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 ());
> + /* 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 (!gdbarch_gcc_target_options (gdbarch).empty ())
> + result.append (gdb_argv (gdbarch_gcc_target_options (gdbarch).c_str ()));
It might be nicer to place the return value of
gdbarch_gcc_target_options into a temporary, rather than calling the
function twice.
Otherwise, looks good to me.
Thanks,
Andrew
>
> cs_producer_options = get_selected_pc_producer_options ();
> if (cs_producer_options != NULL)
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] [compile] Don't pass empty options to GCC
2021-03-24 18:53 ` Andrew Burgess
@ 2021-03-26 11:41 ` Luis Machado
2021-03-29 15:01 ` Luis Machado
0 siblings, 1 reply; 4+ messages in thread
From: Luis Machado @ 2021-03-26 11:41 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches
Hi Andrew,
On 3/24/21 3:53 PM, Andrew Burgess wrote:
> * Luis Machado via Gdb-patches <gdb-patches@sourceware.org> [2021-03-24 11:59: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:
>>
>> YYYY-MM-DD Luis Machado <luis.machado@linaro.org>
>>
>> * compile/compile.c (get_args): Don't add empty argv entries.
>> ---
>> gdb/compile/compile.c | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
>> index d9c99bf4328..32f522a7aba 100644
>> --- a/gdb/compile/compile.c
>> +++ b/gdb/compile/compile.c
>> @@ -600,8 +600,12 @@ 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 ());
>> + /* 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 (!gdbarch_gcc_target_options (gdbarch).empty ())
>> + result.append (gdb_argv (gdbarch_gcc_target_options (gdbarch).c_str ()));
>
> It might be nicer to place the return value of
> gdbarch_gcc_target_options into a temporary, rather than calling the
> function twice.
Indeed. I've made that change and will push this later. Thanks!
>
> Otherwise, looks good to me.
>
> Thanks,
> Andrew
>
>>
>> cs_producer_options = get_selected_pc_producer_options ();
>> if (cs_producer_options != NULL)
>> --
>> 2.25.1
>>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] [compile] Don't pass empty options to GCC
2021-03-26 11:41 ` Luis Machado
@ 2021-03-29 15:01 ` Luis Machado
0 siblings, 0 replies; 4+ messages in thread
From: Luis Machado @ 2021-03-29 15:01 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches
On 3/26/21 8:41 AM, Luis Machado wrote:
> Hi Andrew,
>
> On 3/24/21 3:53 PM, Andrew Burgess wrote:
>> * Luis Machado via Gdb-patches <gdb-patches@sourceware.org>
>> [2021-03-24 11:59: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:
>>>
>>> YYYY-MM-DD Luis Machado <luis.machado@linaro.org>
>>>
>>> * compile/compile.c (get_args): Don't add empty argv entries.
>>> ---
>>> gdb/compile/compile.c | 6 +++++-
>>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
>>> index d9c99bf4328..32f522a7aba 100644
>>> --- a/gdb/compile/compile.c
>>> +++ b/gdb/compile/compile.c
>>> @@ -600,8 +600,12 @@ 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 ());
>>> + /* 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 (!gdbarch_gcc_target_options (gdbarch).empty ())
>>> + result.append (gdb_argv (gdbarch_gcc_target_options
>>> (gdbarch).c_str ()));
>>
>> It might be nicer to place the return value of
>> gdbarch_gcc_target_options into a temporary, rather than calling the
>> function twice.
>
> Indeed. I've made that change and will push this later. Thanks!
>
Pushed now.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-03-29 15:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24 14:59 [PATCH] [compile] Don't pass empty options to GCC Luis Machado
2021-03-24 18:53 ` Andrew Burgess
2021-03-26 11:41 ` Luis Machado
2021-03-29 15:01 ` Luis Machado
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).