From: Simon Marchi <simon.marchi@polymtl.ca>
To: Christian Biesinger <cbiesinger@google.com>
Cc: gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH] gdb: use std::vector instead of alloca in core_target::get_core_register_section
Date: Mon, 13 Jan 2020 04:29:00 -0000 [thread overview]
Message-ID: <2131f829-e84a-c45b-06b5-e3ec79a3344c@polymtl.ca> (raw)
In-Reply-To: <CAPTJ0XEekeX_GAmjbFugZKsLyORiObTEeTxoL=Xj7DtEUW3A-A@mail.gmail.com>
On 2020-01-12 6:20 p.m., Christian Biesinger via gdb-patches wrote:
> On Sun, Jan 12, 2020, 15:17 Simon Marchi <simon.marchi@polymtl.ca> wrote:
>
>> As I was trying to compile gdb for an m68k host, I got this error:
>>
>> CXX corelow.o
>> In file included from /binutils-gdb/gdb/gdbsupport/common-defs.h:120,
>> from /binutils-gdb/gdb/defs.h:28,
>> from /binutils-gdb/gdb/corelow.c:20:
>> /binutils-gdb/gdb/corelow.c: In member function 'void
>> core_target::get_core_register_section(regcache*, const regset*, const
>> char*, int, int, const char*, bool)':
>> /binutils-gdb/gdb/../include/libiberty.h:727:36: error: 'alloca' bound is
>> unknown [-Werror=alloca-larger-than=]
>> 727 | # define alloca(x) __builtin_alloca(x)
>> | ~~~~~~~~~~~~~~~~^~~
>> /binutils-gdb/gdb/corelow.c:625:23: note: in expansion of macro 'alloca'
>> 625 | contents = (char *) alloca (size);
>> | ^~~~~~
>>
>> We are using alloca to hold the contents of a the core register
>> sections. These sections are typically fairly small, but there is no
>> realy guarantee, so I think it would be more reasonable to just use
>> dynamic allocation here.
>>
>
> This seems to be in a common file, why did it only fail on m68k?
Hmm, I don't really know. I presumed that it's just that this warning was enabled in gcc
by default on m68k, and not on other architectures, because it's especially important
for architectures with small amounts of memory like m68k. I tried to look in the gcc source
and documentation for this, but didn't find anything related to this (I don't know the gcc
internals thoug, so I probably didn't look at the right place).
When I add -Walloca-larger-than=16 to my x86-64 build, I get the same error. However, note
that I only get it when building with -O2 as well.
>> gdb/ChangeLog:
>>
>> * corelow.c (core_target::get_core_register_section): Use
>> std::vector instead of alloca.
>> ---
>> gdb/corelow.c | 9 ++++-----
>> 1 file changed, 4 insertions(+), 5 deletions(-)
>>
>> diff --git a/gdb/corelow.c b/gdb/corelow.c
>> index c53bf1df8fd8..e7efa652d62a 100644
>> --- a/gdb/corelow.c
>> +++ b/gdb/corelow.c
>> @@ -594,7 +594,6 @@ core_target::get_core_register_section (struct
>> regcache *regcache,
>> {
>> struct bfd_section *section;
>> bfd_size_type size;
>> - char *contents;
>> bool variable_size_section = (regset != NULL
>> && regset->flags & REGSET_VARIABLE_SIZE);
>>
>> @@ -622,8 +621,8 @@ core_target::get_core_register_section (struct
>> regcache *regcache,
>> section_name.c_str ());
>> }
>>
>> - contents = (char *) alloca (size);
>> - if (! bfd_get_section_contents (core_bfd, section, contents,
>> + std::vector<char> contents (size);
>> + if (! bfd_get_section_contents (core_bfd, section, contents.data (),
>>
>
> Since you're touching this, isn't usual style not to have a space after the
> ! ?
I see it it some spots here and there, but no I don't think it's part of the style
we follow. I've removed the space in my local version of the patch, thanks for
noticing.
Simon
next prev parent reply other threads:[~2020-01-13 3:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-12 20:22 Simon Marchi
2020-01-13 3:30 ` Christian Biesinger via gdb-patches
2020-01-13 4:29 ` Simon Marchi [this message]
2020-01-13 10:45 ` Andreas Schwab
2020-01-13 17:03 ` Simon Marchi
2020-01-13 17:33 ` Tom Tromey
2020-01-13 19:36 ` Simon Marchi
2020-01-13 19:45 ` Pedro Alves
2020-01-13 20:20 ` Simon Marchi
2020-01-13 23:13 ` Pedro Alves
2020-01-13 23:21 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2131f829-e84a-c45b-06b5-e3ec79a3344c@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=cbiesinger@google.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox