This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: a question about fix-header.c


Kenneth Zadeck wrote:
> 
> I would like to modify fix includes so that it adds the attribute
> "pointer-no-escape" onto the function definition of free in stdlib.h
> (and possibly some other fuctions as well).
> 
> I am having trouble figuring  out how to do this.
> 
> Dan Berlin said that you might be able to point me in the correct direction.
> 
> kenny

Assuming that you've read this:

http://gcc.gnu.org/cgi-bin/cvsweb.cgi/~checkout~/gcc/fixincludes/README?rev=1.1.34.1&content-type=text/plain

the easiest way is to find an entry in inclhack.def that does something
similar to what you are trying to do.  Specifically, you are trying to
locate some text (declaration of "free(3C)") and add some text nearby
(viz., "__attribute__(pointer-no-escape)").  So, I just searched the
file looking for such a thing and stumbled quickly into this:

> /*
>  *  Fix hpux 11.00 broken snprintf declaration
>  *  (third argument is char *, needs to be const char * to prevent
>  *  spurious warnings with -Wwrite-strings or in C++).
>  */
> fix = {
>     hackname = hpux11_snprintf;
>     files    = stdio.h;
>     select   = '(extern int snprintf *\(char *\*, *(|__|_hpux_)size_t,)'
>                                     ' *(char *\*, *\.\.\.\);)';
>     c_fix     = format;
>     c_fix_arg = '%1 const %3';
> 
>     test_text = "extern int snprintf(char *, size_t, char *, ...);\n"
>                 "extern int snprintf(char *, __size_t, char *, ...);\n"
>                 "extern int snprintf(char *, _hpux_size_t, char *, ...);";
> };

So, using that as a template:

1.  Change the hackname to something appropriate
2.  Change the "files" to specify just the file you have
3.  change the "select" clause to identify declarations of "free(3C)"
    that do *not* already have the proper attribute and separate
    the regex where you need to insert the new text.
    (You may add a "bypass" clause, if that makes it easier.)
4.  use a c_fix_arg along the lines of:
       "%1 __attribute__("pointer-no-escape") %2"
5.  provide a "test_text" that will require fixing.
6.  regenerate fixincl.x
7.  after rebuilding, run "make check" in the fixincludes directory.
8.  verify that your test text was fixed correctly and that
    your /usr/include/stdlib.h was correctly fixed and installed
    in the GCC private include directory.
9.  commit the changes to inclhack.def, fixincl.x and
    fixincludes/tests/base/stdlib.h (by replacing it with
    the one generated in the make check run.  Just be certain
    it is correct before you do this.)
10. Let me know where the README fell down for you so *it*
    can be fixed, too.  :)

Regards, Bruce


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]