GCC 6.3 stack increased when using c++ exception compare to 4.9

Asked by Jonathan Dumaresq

Hi,

We try to upgrade our gcc 4.9 to gcc 6.3 and we observed that the stack usage is increased compare to 4.9 Here a small code that represent the problem.

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <stdexcept>

class TContractException: public std::logic_error
{
public:
 TContractException(std::string, unsigned int, std::string, std::string msg) : logic_error(msg.c_str())
 {

 }
 ~TContractException() throw ()
 {
 }
};

class PostconditionException: public TContractException
{
public:
 PostconditionException(std::string a , unsigned int b , std::string c): TContractException(a, b, c, "ERRORPOSTCONDITION")
 {

 }
};

int main(int argc, char* argv[])
{
 (void) argv;
 try
 {
  if(argc == 4) throw "My exception";
  if(argc == 5) throw PostconditionException("test throw contract", 1, "");
 }
 catch(PostconditionException &e)
 {
  printf("exception %s\n", e.what());
 }
 catch(...)
 {
  printf("exception");
 }
}

This is trivial code to show the problem. Compiling this code with 4.9 the first few asm line show that the stack reservation is 36 bytes

:../src/main.cpp **** int main(int argc, char* argv[])
  35:../src/main.cpp **** {
 490 .loc 2 35 0
 491 .cfi_startproc
 492 .cfi_personality 0,__gxx_personality_v0
 493 .cfi_lsda 0,.LLSDA785
 494 @ args = 0, pretend = 0, frame = 32
 495 @ frame_needed = 1, uses_anonymous_args = 0
 496 0000 F0B5 push {r4, r5, r6, r7, lr}
 497 .save {r4, r5, r6, r7, lr}
 498 .cfi_def_cfa_offset 20
 499 .cfi_offset 4, -20
 500 .cfi_offset 5, -16
 501 .cfi_offset 6, -12
 502 .cfi_offset 7, -8
 503 .cfi_offset 14, -4
 504 .pad #36
 505 0002 89B0 sub sp, sp, #36 <--------------------
 506 .cfi_def_cfa_offset 56
 507 .setfp r7, sp, #0
 508 0004 00AF add r7, sp, #0
 509 .cfi_def_cfa_register 7
 510 0006 7860 str r0, [r7, #4]
 511 0008 3960 str r1, [r7]
 512 .LBB7:

But if i compile the same program with gcc 6.3 I got this asm lines

34:../src/main.cpp **** int main(int argc, char* argv[])
  35:../src/main.cpp **** {
 421 .loc 2 35 0
 422 .cfi_startproc
 423 .cfi_personality 0,__gxx_personality_v0
 424 .cfi_lsda 0,.LLSDA893
 425 @ args = 0, pretend = 0, frame = 72
 426 @ frame_needed = 1, uses_anonymous_args = 0
 427 0000 F0B5 push {r4, r5, r6, r7, lr}
 428 .save {r4, r5, r6, r7, lr}
 429 .cfi_def_cfa_offset 20
 430 .cfi_offset 4, -20
 431 .cfi_offset 5, -16
 432 .cfi_offset 6, -12
 433 .cfi_offset 7, -8
 434 .cfi_offset 14, -4
 435 .pad #76
 436 0002 93B0 sub sp, sp, #76 <---------------- More bytes allocated ????
 437 .cfi_def_cfa_offset 96
 438 .setfp r7, sp, #0
 439 0004 00AF add r7, sp, #0
 440 .cfi_def_cfa_register 7
 441 0006 7860 str r0, [r7, #4]
 442 0008 3960 str r1, [r7]

I would like to have an explanation about this. If we have more exception type, the problem is worst.

regards

Jonathan

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Tejas Belagod (belagod-tejas) said :
#1

Hi Jonathan,

Thanks for the reduced test case. Its not immediately obvious why the stack usage has increased. We will investigate and get back to you.

Thanks,
Tejas.

Revision history for this message
Jonathan Dumaresq (jdumaresq) said :
#2

Bump,

Any news on this ?

Jonathan

Can you help with this problem?

Provide an answer of your own, or ask Jonathan Dumaresq for more information if necessary.

To post a message you must log in.