This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Modifying GCC's emitted assembly code
- From: Ian Lance Taylor <iant at google dot com>
- To: Amittai Aviram <amittai dot aviram at yale dot edu>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sat, 19 Nov 2011 22:55:24 -0800
- Subject: Re: Modifying GCC's emitted assembly code
- References: <E7F6D5E6-D95D-47A0-92BA-377ADA35C1A6@yale.edu>
Amittai Aviram <amittai.aviram@yale.edu> writes:
> I have been creating a modified version of GCC's libgomp library to support a special version of OpenMP. In order for it to work properly, at the end of the main function in an OpenMP program, I have to insert a call to a special clean-up function (say, "clean_up()"), just before the "return" statement. (I define my clean_up function in my version of libgomp.) I would like to modify GCC so that it inserts the call to clean_u automatically, just before the code representing the return statement, such as the RET instruction in x86 assembly code. How might I go about this?
>
> Alternatively, it might work if GCC inserted the function call into the boilerplate code of __exit. How might I enable GCC to do that?
Would it work to just use atexit? If that works, perhaps you could just
add a global constructor which calls atexit with your cleanup function.
Ian