From: Xi Ruoyao <xry111@mengyan1223.wang>
To: Jonny Grant <jg@jguk.org>, Florian Weimer <fw@deneb.enyo.de>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Recursive SIGSEGV question
Date: Mon, 25 Mar 2019 14:01:00 -0000 [thread overview]
Message-ID: <d3e73ef74c12829b7c827434bdebd8cfe0247c60.camel@mengyan1223.wang> (raw)
In-Reply-To: <835d09ce-752a-c0f7-e5cf-210e855df2ab@jguk.org>
On 2019-03-25 13:06 +0000, Jonny Grant wrote:
>
> I built & ran with the Sanitizer, it seems it's also stack overflow
> within the operator new()
>
> I had thoughts GCC would generate code that monitored the stack size and
> aborted with a clear message when the stack size was exceeded. Looked
> online, and it doesn't seem to be the case.
Impossible. We can't distinguish "stack overflow" with other segmentation
faults. For example
int foo() {volatile char p[10000000]; p[0] = 1;}
and
int foo() {
volatile char a;
(&a)[-9999999] = 1;
}
may be compiled to exactly same machine code. Now which one is a stack
overflow?
> AddressSanitizer:DEADLYSIGNAL
> =================================================================
> ==16598==ERROR: AddressSanitizer: stack-overflow on address
> 0x7ffe4b0e7fc0 (pc 0x7f85c609293a bp 0x7ffe4b0e88d0 sp 0x7ffe4b0e7fb0 T0)
> #0 0x7f85c6092939 (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x28939)
> #1 0x7f85c6091217 (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x27217)
> #2 0x7f85c615974e in operator new(unsigned long)
> (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xef74e)
> #3 0x563e23701a4a in void std::__cxx11::basic_string<char,
> std::char_traits<char>, std::allocator<char> >::_M_construct<char
> const*>(char const*, char const*, std::forward_iterator_tag)
> /usr/include/c++/8/bits/basic_string.tcc:219
> #4 0x563e23947131 in void std::__cxx11::basic_string<char,
> std::char_traits<char>, std::allocator<char> >::_M_construct_aux<char
> const*>(char const*, char const*, std::__false_type)
> /usr/include/c++/8/bits/basic_string.h:236
> #5 0x563e23947131 in void std::__cxx11::basic_string<char,
> std::char_traits<char>, std::allocator<char> >::_M_construct<char
> const*>(char const*, char const*) /usr/include/c++/8/bits/basic_string.h:255
> #6 0x563e23947131 in std::__cxx11::basic_string<char,
> std::char_traits<char>, std::allocator<char> >::basic_string(char
> const*, std::allocator<char> const&)
> /usr/include/c++/8/bits/basic_string.h:516
If you consume too much stack, stack overflow may happens in any functions. For
example:
int x()
{
int a[100];
malloc(1);
return x();
}
int main()
{
return x();
}
> Sanitizer says the same. There isn't really anything that can be done
> when stack is exceeded! There isn't a StackOverflowException
This is gcc-help, not java-help or python-help. But actually you can do
something here:
0. Do not consume so much stack. Throw large things into the heap.
1. Set a signal handler for SIGSEGV. And you will need sigaltstack so the
signal handler can run in an alternative stack.
2. Use ulimit -s or setrlimit to increase stack limit, if you really need more
stack.
3. Use -fsplit-stack to automatically "increase" stack size when it overflows,
if you really need this feature.
If you don't like all of these suggestions, go to use Java.
--
Xi Ruoyao <xry111@mengyan1223.wang>
School of Aerospace Science and Technology, Xidian University
next prev parent reply other threads:[~2019-03-25 13:56 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-19 22:05 Jonny Grant
2019-03-20 4:02 ` Florian Weimer
2019-03-20 8:11 ` Jonny Grant
2019-03-25 13:23 ` Jonny Grant
2019-03-25 13:27 ` Jonathan Wakely
2019-03-25 13:56 ` Florian Weimer
2019-03-25 14:01 ` Xi Ruoyao [this message]
2019-03-25 15:47 ` Florian Weimer
2019-03-25 16:10 ` Andrew Haley
2019-03-25 16:13 ` Jonny Grant
2019-03-25 16:23 ` Jonathan Wakely
2019-03-25 18:51 ` Florian Weimer
2019-03-25 20:39 ` Jonny Grant
2019-03-26 6:50 ` Xi Ruoyao
2019-03-27 0:29 ` Jonathan Wakely
2019-03-27 21:34 ` Jonny Grant
2019-03-27 23:43 ` Jonathan Wakely
2019-03-27 23:51 ` Jonny Grant
2019-03-28 8:26 ` Xi Ruoyao
2019-03-28 11:52 ` Jonathan Wakely
2019-03-29 2:24 ` Jonny Grant
2019-03-30 17:32 ` Jonny Grant
2023-02-19 21:21 ` Jonny Grant
2023-02-19 21:34 ` Jonny Grant
2019-03-28 13:55 ` Jonathan Wakely
2019-03-28 14:39 ` Jonny Grant
2019-03-28 14:39 ` Jonathan Wakely
2019-03-25 20:28 ` Segher Boessenkool
2019-03-25 18:56 ` Segher Boessenkool
2019-03-25 22:05 ` Jonny Grant
2019-03-26 10:20 ` Xi Ruoyao
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=d3e73ef74c12829b7c827434bdebd8cfe0247c60.camel@mengyan1223.wang \
--to=xry111@mengyan1223.wang \
--cc=fw@deneb.enyo.de \
--cc=gcc-help@gcc.gnu.org \
--cc=jg@jguk.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).