public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/3056: gcc 2.95.3 -- atexit not catching exit() call following longjmp
@ 2001-06-05 10:16 doug.hackworth
  0 siblings, 0 replies; 4+ messages in thread
From: doug.hackworth @ 2001-06-05 10:16 UTC (permalink / raw)
  To: gcc-gnats; +Cc: wjtomer

>Number:         3056
>Category:       c++
>Synopsis:       gcc 2.95.3 -- atexit not catching exit() call following longjmp
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 05 10:16:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Doug Hackworth
>Release:        gcc version 2.95.3 20010315 (release)
>Organization:
>Environment:
i386-pc-solaris2.6
uname -a .... SunOS corvus2s 5.6 Generic_105182-19 i86pc i386 i86pc
>Description:

GCC does not generate an error message.  The code compiles and
runs, but seems to run incorrectly.  

All code is in the attached file, TestTerminate.cpp.  There 
are no include files.

A function (here called "Terminate()") is specified by 
atexit() to be executed when exit() is called.  Also, setjmp() 
is used to specify a stack-restoration point.  When exit() 
is called once, the function Terminate() executes.  

Within Terminate, atexit() is used again to re-register 
Terminate as the function to be executed upon exiting (it 
is re-registered because, since it's been called once, it 
has been removed from the stack); atexit returns 0, and 
thus appears to be working correctly.  Following this, 
there is a longjmp() call, and this sends control back to 
the setjmp point in main().  

When program execution resumes from this point, exit() is 
called a second time.  However, instead of calling 
Terminate as it should do, the program exits.  

>How-To-Repeat:
// ALSO IN ATTACHED FILE (from gnatsweb)

extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
//#include <sys/param.h>
//#include <sys/types.h>
//#include <sys/stat.h>
}

jmp_buf envJmp;

//================================

void Terminate(void)
{
		fflush(stdout);
		printf("SETTING FOR TERMINATION\n");
		int i = atexit(Terminate); 
		printf("SETTING AFTER TERMINATION %d\n",i);
		longjmp(envJmp, 1); 
}

//================================

int main(void)
{
  atexit(Terminate);


  if (setjmp(envJmp) == 0)
	  {
		printf("Try One\n");
		exit(1);
	  }

  if (setjmp(envJmp) == 0)
	  {
		printf("Try Two\n");
	    exit(2);
	  }  

  printf("Exiting...\n");

  exit(0);
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="TestTerminate.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="TestTerminate.cpp"

Ly8jaW5jbHVkZSA8dW5pc3RkLmg+DQovLyNpbmNsdWRlIDxlcnJuby5oPg0KLy8jaW5jbHVkZSA8
c3lzL2Vycm5vLmg+DQovLyNpbmNsdWRlIDxzeXMvcGFyYW0uaD4NCi8vI2luY2x1ZGUgPHN5cy9z
dGF0Lmg+DQoNCmV4dGVybiAiQyIgew0KI2luY2x1ZGUgPHN0ZGlvLmg+DQojaW5jbHVkZSA8c3Rk
bGliLmg+DQojaW5jbHVkZSA8c3RyaW5nLmg+DQojaW5jbHVkZSA8c2V0am1wLmg+DQovLyNpbmNs
dWRlIDxzeXMvcGFyYW0uaD4NCi8vI2luY2x1ZGUgPHN5cy90eXBlcy5oPg0KLy8jaW5jbHVkZSA8
c3lzL3N0YXQuaD4NCn0NCg0Kam1wX2J1ZiBlbnZKbXA7DQoNCi8vPT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT0NCg0Kdm9pZCBUZXJtaW5hdGUodm9pZCkNCnsNCgkJZmZsdXNoKHN0ZG91
dCk7DQoJCXByaW50ZigiU0VUVElORyBGT1IgVEVSTUlOQVRJT05cbiIpOw0KCQlpbnQgaSA9IGF0
ZXhpdChUZXJtaW5hdGUpOyANCgkJcHJpbnRmKCJTRVRUSU5HIEFGVEVSIFRFUk1JTkFUSU9OICVk
XG4iLGkpOw0KCQlsb25nam1wKGVudkptcCwgMSk7IA0KfQ0KDQovLz09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09DQoNCmludCBtYWluKHZvaWQpDQp7DQogIGF0ZXhpdChUZXJtaW5hdGUp
Ow0KDQoNCiAgaWYgKHNldGptcChlbnZKbXApID09IDApDQoJICB7DQoJCXByaW50ZigiVHJ5IE9u
ZVxuIik7DQoJCWV4aXQoMSk7DQoJICB9DQoNCiAgaWYgKHNldGptcChlbnZKbXApID09IDApDQoJ
ICB7DQoJCXByaW50ZigiVHJ5IFR3b1xuIik7DQoJICAgIGV4aXQoMik7DQoJICB9ICANCg0KICBw
cmludGYoIkV4aXRpbmcuLi5cbiIpOw0KDQogIGV4aXQoMCk7DQp9DQo=


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++/3056: gcc 2.95.3 -- atexit not catching exit() call following longjmp
@ 2001-12-02 17:36 rodrigc
  0 siblings, 0 replies; 4+ messages in thread
From: rodrigc @ 2001-12-02 17:36 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/3056; it has been noted by GNATS.

From: rodrigc@gcc.gnu.org
To: doug.hackworth@nomos.com, gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org,
  gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, rodrigc@gcc.gnu.org,
  wjtomer@nomos.com
Cc:  
Subject: Re: c++/3056: gcc 2.95.3 -- atexit not catching exit() call following longjmp
Date: 3 Dec 2001 01:25:58 -0000

 Synopsis: gcc 2.95.3 -- atexit not catching exit() call following longjmp
 
 State-Changed-From-To: feedback->closed
 State-Changed-By: rodrigc
 State-Changed-When: Sun Dec  2 17:25:58 2001
 State-Changed-Why:
     No feedback.
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&pr=3056&database=gcc


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++/3056: gcc 2.95.3 -- atexit not catching exit() call following longjmp
@ 2001-12-02 17:25 rodrigc
  0 siblings, 0 replies; 4+ messages in thread
From: rodrigc @ 2001-12-02 17:25 UTC (permalink / raw)
  To: doug.hackworth, gcc-bugs, gcc-gnats, gcc-prs, nobody, rodrigc, wjtomer

Synopsis: gcc 2.95.3 -- atexit not catching exit() call following longjmp

State-Changed-From-To: feedback->closed
State-Changed-By: rodrigc
State-Changed-When: Sun Dec  2 17:25:58 2001
State-Changed-Why:
    No feedback.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&pr=3056&database=gcc


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++/3056: gcc 2.95.3 -- atexit not catching exit() call following longjmp
@ 2001-09-07 21:47 rodrigc
  0 siblings, 0 replies; 4+ messages in thread
From: rodrigc @ 2001-09-07 21:47 UTC (permalink / raw)
  To: rodrigc, doug.hackworth, gcc-bugs, gcc-prs, nobody, wjtomer

Synopsis: gcc 2.95.3 -- atexit not catching exit() call following longjmp

State-Changed-From-To: open->feedback
State-Changed-By: rodrigc
State-Changed-When: Fri Sep  7 21:47:52 2001
State-Changed-Why:
    I cannot reproduce your problem with gcc 3.0.1 under Linux.
    
    When I compile your testcase, the program never exits,
    it just keeps looping (which I think is the correct behavior):
    
    Try One
    SETTING FOR TERMINATION
    SETTING AFTER TERMINATION 0
    Try Two
    SETTING FOR TERMINATION
    SETTING AFTER TERMINATION 0
    Exiting...
    SETTING FOR TERMINATION
    SETTING AFTER TERMINATION 0
    Exiting...
    SETTING FOR TERMINATION
    SETTING AFTER TERMINATION 0
    Exiting...
    
    Can you try gcc 3.0.1 under Solaris and see if the
    bug is still there?

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=3056&database=gcc


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-12-03  1:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-05 10:16 c++/3056: gcc 2.95.3 -- atexit not catching exit() call following longjmp doug.hackworth
2001-09-07 21:47 rodrigc
2001-12-02 17:25 rodrigc
2001-12-02 17:36 rodrigc

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).