Here's a hack:
// hack.c
int last_exit;
// hack.h
extern int last_exit;
#define exit(x) (exit)(last_exit = (x))
Won't work for return, but, hey, it's portable!
On a more maintainer-friendly note, you may want to consider writing some form of wrapper to do something similar to this for you. Hacking around how GCC implements exit() sounds like a maintenance nightmare. Better to write a few helper functions that exit for you, and maybe even mask them with macros if you're into that kind of thing. With a macro you might even be able to replace return calls, if you always call return with parenthesis. Though this sounds like even more of a maintenance nightmare.