xref: /netbsd-src/external/gpl3/gcc/dist/fixincludes/README (revision 4d5abbe83f525258eb479e5fca29f25cb943f379)
14fee23f9Smrg
24fee23f9SmrgGCC MAINTAINER INFORMATION
34fee23f9Smrg==========================
44fee23f9Smrg
54fee23f9SmrgIf you are having some problem with a system header that is either
64fee23f9Smrgbroken by the manufacturer, or is broken by the fixinclude process,
74fee23f9Smrgthen you will need to alter or add information to the include fix
84fee23f9Smrgdefinitions file, ``inclhack.def''.  Please also send relevant
94fee23f9Smrginformation to gcc-bugs@gcc.gnu.org, gcc-patches@gcc.gnu.org and,
104fee23f9Smrgplease, to me:  bkorb@gnu.org.
114fee23f9Smrg
124fee23f9SmrgTo make your fix, you will need to do several things:
134fee23f9Smrg
144fee23f9Smrg1.  Obtain access to the AutoGen program on some platform.  It does
154fee23f9Smrg    not have to be your build platform, but it is more convenient.
164fee23f9Smrg
174fee23f9Smrg2.  Edit "inclhack.def" to reflect the changes you need to make.
184fee23f9Smrg    See below for information on how to make those changes.
194fee23f9Smrg
204fee23f9Smrg3.  Run the "genfixes" shell script to produce a new copy of
214fee23f9Smrg    the "fixincl.x" file.
224fee23f9Smrg
234fee23f9Smrg4.  Rebuild the compiler and check the header causing the issue.
244fee23f9Smrg    Make sure it is now properly handled.  Add tests to the
254fee23f9Smrg    "test_text" entry(ies) that validate your fix.  This will
264fee23f9Smrg    help ensure that future fixes won't negate your work.
2748fb7bfaSmrg    Do *NOT* specify test text for "wrap" or "replacement" fixes.
2848fb7bfaSmrg    There is no real possibility that these fixes will fail.
2948fb7bfaSmrg    If they do, you will surely know straight away.
304fee23f9Smrg
31*4d5abbe8Smrg    NOTE:  "test_text" is interpreted by the shell as it gets
32*4d5abbe8Smrg    copied into the test header.  THEREFORE you must quote
33*4d5abbe8Smrg    dollar sign characters and back quotes -- unless you mean
34*4d5abbe8Smrg    for them to be interpreted by the shell.
35*4d5abbe8Smrg
36*4d5abbe8Smrg    e.g. the math_huge_val_from_dbl_max test_text needs to
37*4d5abbe8Smrg    put text into both float.h and math.h, so it includes a
38*4d5abbe8Smrg    back-quoted script to add text to float.h.
39*4d5abbe8Smrg
404fee23f9Smrg5.  Go into the fixincludes build directory and type, "make check".
414fee23f9Smrg    You are guaranteed to have issues printed out as a result.
424fee23f9Smrg    Look at the diffs produced.  Make sure you have not clobbered
434fee23f9Smrg    the proper functioning of a different fix.  Make sure your
444fee23f9Smrg    fix is properly tested and it does what it is supposed to do.
454fee23f9Smrg
464fee23f9Smrg6.  Now that you have the right things happening, synchronize the
474fee23f9Smrg    $(srcdir)/tests/base directory with the $(builddir)/tests/res
484fee23f9Smrg    directory.  The output of "make check" will be some diffs that
494fee23f9Smrg    should give you some hints about what to do.
504fee23f9Smrg
514fee23f9Smrg7.  Rerun "make check" and verify that there are no issues left.
524fee23f9Smrg
534fee23f9Smrg
544fee23f9SmrgMAKING CHANGES TO INCLHACK.DEF
554fee23f9Smrg==============================
564fee23f9Smrg
574fee23f9Smrg0.  If you are not the fixincludes maintainer, please send that
584fee23f9Smrg    person email about any changes you may want to make.  Thanks!
594fee23f9Smrg
604fee23f9Smrg1.  Every fix must have a "hackname" that is compatible with C syntax
614fee23f9Smrg    for variable names and is unique without regard to alphabetic case.
624fee23f9Smrg    Please keep them alphabetical by this name.  :-)
634fee23f9Smrg
644fee23f9Smrg2.  If the problem is known to exist only in certain files, then
654fee23f9Smrg    identify the files with "files = " entries.  If you use fnmatch(3C)
664fee23f9Smrg    wild card characters in a "files" entry, be certain that the first
674fee23f9Smrg    "files" entry has no such character.  Otherwise, the "make check"
684fee23f9Smrg    machinery will attempt to create files with those characters in the
694fee23f9Smrg    name.  That is inconvenient.
704fee23f9Smrg
714fee23f9Smrg3.  It is relatively expensive to fire off a process to fix a source
724fee23f9Smrg    file, therefore write apply tests to avoid unnecessary fix
734fee23f9Smrg    processes.  The preferred apply tests are "select", "bypass", "mach"
74*4d5abbe8Smrg    "sum", and "c-test" because they are performed internally:
754fee23f9Smrg
764fee23f9Smrg    * select - Run a regex on the contents of the file being considered.
774fee23f9Smrg               All such regex-es must match.  Matching is done with
784fee23f9Smrg               extended regular expressions.
794fee23f9Smrg
804fee23f9Smrg    * bypass - Run a regex on the contents of the file being considered.
814fee23f9Smrg               No such regex may match.
824fee23f9Smrg
83*4d5abbe8Smrg    * sum    - Select a specific version of a file that has a matching
84*4d5abbe8Smrg               check sum.  The BSD version of checksum ["sum(1BSD)"]
85*4d5abbe8Smrg               is used.  Each "sum" entry should contain exactly three
86*4d5abbe8Smrg               space separated tokens:  the sum, some number and the
87*4d5abbe8Smrg               basename of the file.  The "some number" is ignored.
88*4d5abbe8Smrg               If there are multiple "sum" entries, only one needs to
89*4d5abbe8Smrg               match in order to pass.  For example:
90*4d5abbe8Smrg
91*4d5abbe8Smrg                   sum = '1234 3 foobar.h';
92*4d5abbe8Smrg
93*4d5abbe8Smrg               specifies that the "foobar.h" header in any directory
94*4d5abbe8Smrg               will match if it has the checksum 1234.
95*4d5abbe8Smrg
964fee23f9Smrg    * c_test - call a function in fixtests.c.  See that file.
974fee23f9Smrg
984fee23f9Smrg    * files  - the "fnmatch" pattern of the file(s) to examine for
994fee23f9Smrg               the issue.  There may be several copies of this attribute.
1004fee23f9Smrg               If the header lives in a /usr/include subdirectory, be
1014fee23f9Smrg               sure to include that subdirectory in the name. e.g. net/if.h
1024fee23f9Smrg
1034fee23f9Smrg    * mach   - Match the output of config.guess against a series of fnmatch
1044fee23f9Smrg               patterns.  It must match at least one of the patterns, unless
1054fee23f9Smrg               "not-machine" has also been specified.  In that case, the
1064fee23f9Smrg               config.guess output must not match any of the patterns.
1074fee23f9Smrg
1084fee23f9Smrg    The next test is relatively slow because it must be handled in a
1094fee23f9Smrg    separate shell process.  Some platforms do not support server shells,
1104fee23f9Smrg    so the whole process is even slower and more cumbersome there.
1114fee23f9Smrg
1124fee23f9Smrg    * test   - These should be arguments to the program, "/bin/test".
1134fee23f9Smrg               You may perform multiple commands, if you enclose them
1144fee23f9Smrg               in backquotes and echo out valid test arguments.  For
1154fee23f9Smrg               example, you might echo out '0 -eq 1' if you want a false
1164fee23f9Smrg               result, or '0 -eq 0' for a true result.
1174fee23f9Smrg
1184fee23f9Smrg    These tests are required to:
1194fee23f9Smrg
1204fee23f9Smrg    1.  Be positive for all header files that require the fix.
1214fee23f9Smrg
1224fee23f9Smrg    It is desirable to:
1234fee23f9Smrg
1244fee23f9Smrg    2.  Be negative as often as possible whenever the fix is not
1254fee23f9Smrg        required, avoiding the process overhead.
1264fee23f9Smrg
1274fee23f9Smrg    It is nice if:
1284fee23f9Smrg
1294fee23f9Smrg    3.  The expression is as simple as possible to both
1304fee23f9Smrg        process and understand by people.  :-)
1314fee23f9Smrg
1324fee23f9Smrg        Please take advantage of the fact AutoGen will glue
1334fee23f9Smrg        together string fragments.  It helps.  Also take note
1344fee23f9Smrg        that double quote strings and single quote strings have
1354fee23f9Smrg        different formation rules.  Double quote strings are a
1364fee23f9Smrg        tiny superset of ANSI-C string syntax.  Single quote
1374fee23f9Smrg        strings follow shell single quote string formation
1384fee23f9Smrg        rules, except that the backslash is processed before
1394fee23f9Smrg        '\\', '\'' and '#' characters (using C character syntax).
1404fee23f9Smrg
1414fee23f9Smrg    Each test must pass or the fix is not applied.  For example,
1424fee23f9Smrg    all "select" expressions must be found and not one "bypass"
1434fee23f9Smrg    selection may be found.
1444fee23f9Smrg
1454fee23f9Smrg    Examples of test specifications:
1464fee23f9Smrg
1474fee23f9Smrg      hackname = broken_assert_stdio;
1484fee23f9Smrg      files    = assert.h;
1494fee23f9Smrg      select   = stderr;
1504fee23f9Smrg      bypass   = "include.*stdio.h";
1514fee23f9Smrg
1524fee23f9Smrg    The ``broken_assert_stdio'' fix will be applied only to a file
1534fee23f9Smrg    named "assert.h" if it contains the string "stderr" _and_ it
1544fee23f9Smrg    does _not_ contain the expression "include.*stdio.h".
1554fee23f9Smrg
1564fee23f9Smrg      hackname = no_double_slash;
1574fee23f9Smrg      c_test   = "double_slash";
1584fee23f9Smrg
1594fee23f9Smrg    The ``no_double_slash'' fix will be applied if the
1604fee23f9Smrg    ``double_slash_test()'' function says to.  See ``fixtests.c''
1614fee23f9Smrg    for documentation on how to include new functions into that
1624fee23f9Smrg    module.
1634fee23f9Smrg
1644fee23f9Smrg4.  There are currently four methods of fixing a file:
1654fee23f9Smrg
1664fee23f9Smrg    1.  a series of sed expressions.  Each will be an individual
167*4d5abbe8Smrg        "-e" argument to a single invocation of sed.  Unless you
168*4d5abbe8Smrg        need to use multiple or complex sed expressions, please
169*4d5abbe8Smrg        use the "replacement text" method instead.
1704fee23f9Smrg
1714fee23f9Smrg    2.  a shell script.  These scripts are _required_ to read all
1724fee23f9Smrg        of stdin in order to avoid pipe stalls.  They may choose to
1734fee23f9Smrg        discard the input.
1744fee23f9Smrg
1754fee23f9Smrg    3.  Replacement text.  If the replacement is empty, then no
1764fee23f9Smrg        fix is applied.  Otherwise, the replacement text is
1774fee23f9Smrg        written to the output file and no further fixes are
1784fee23f9Smrg        applied.  If you really want a no-op file, replace the
1794fee23f9Smrg        file with a comment.
1804fee23f9Smrg
1814fee23f9Smrg        Replacement text "fixes" must be first in this file!!
1824fee23f9Smrg
1834fee23f9Smrg    4.  A C language subroutine method for both tests and fixes.
1844fee23f9Smrg        See ``fixtests.c'' for instructions on writing C-language
1854fee23f9Smrg        applicability tests and ``fixfixes.c'' for C-language fixing.
1864fee23f9Smrg        These files also contain tables that describe the currently
1874fee23f9Smrg        implemented fixes and tests.
1884fee23f9Smrg
1894fee23f9Smrg    If at all possible, you should try to use one of the C language
1904fee23f9Smrg    fixes as it is far more efficient.  There are currently five
1914fee23f9Smrg    such fixes, three of which are very special purpose:
1924fee23f9Smrg
1934fee23f9Smrg    i) char_macro_def - This function repairs the definition of an
1944fee23f9Smrg        ioctl macro that presumes CPP macro substitution within
1954fee23f9Smrg        pairs of single quote characters.
1964fee23f9Smrg
1974fee23f9Smrg    ii) char_macro_use - This function repairs the usage of ioctl
1984fee23f9Smrg        macros that no longer can wrap an argument with single quotes.
1994fee23f9Smrg
2004fee23f9Smrg    iii) machine_name - This function will look at "#if", "#ifdef",
2014fee23f9Smrg        "#ifndef" and "#elif" directive lines and replace the first
2024fee23f9Smrg        occurrence of a non-reserved name that is traditionally
2034fee23f9Smrg        pre-defined by the native compiler.
2044fee23f9Smrg
2054fee23f9Smrg    The next two are for general use:
2064fee23f9Smrg
2074fee23f9Smrg    iv) wrap - wraps the entire file with "#ifndef", "#define" and
2084fee23f9Smrg        "#endif" self-exclusionary text.  It also, optionally, inserts
2094fee23f9Smrg        a prolog after the "#define" and an epilog just before the
2104fee23f9Smrg        "#endif".  You can use this for a fix as follows:
2114fee23f9Smrg
2124fee23f9Smrg            c_fix     = wrap;
2134fee23f9Smrg            c_fix_arg = "/* prolog text */";
2144fee23f9Smrg            c_fix_arg = "/* epilog text */";
2154fee23f9Smrg
2164fee23f9Smrg        If you want an epilog without a prolog, set the first "c_fix_arg"
2174fee23f9Smrg        to the empty string.  Both or the second "c_fix_arg"s may be
2184fee23f9Smrg        omitted and the file will still be wrapped.
2194fee23f9Smrg
2204fee23f9Smrg	THERE IS A SPECIAL EXCEPTION TO THIS, HOWEVER:
2214fee23f9Smrg
2224fee23f9Smrg	If the regular expression '#if.*__need' is found, then it is
2234fee23f9Smrg	assumed that the file needs to be read and interpreted more
2244fee23f9Smrg	than once.  However, the prolog and epilog text (if any) will
2254fee23f9Smrg	be inserted.
2264fee23f9Smrg
2274fee23f9Smrg    v) format - Replaces text selected with a regular expression with
2284fee23f9Smrg        a specialized formating string.  The formatting works as follows:
2294fee23f9Smrg        The format text is copied to the output until a '%' character
2304fee23f9Smrg        is found.  If the character after the '%' is another '%', then
2314fee23f9Smrg        one '%' is output and processing continues.  If the following
2324fee23f9Smrg        character is not a digit, then the '%' and that character are
2334fee23f9Smrg        copied and processing continues.  Finally, if the '%' *is*
2344fee23f9Smrg        followed by a digit, that digit is used as an index into the
2354fee23f9Smrg        regmatch_t array to replace the two characters with the matched
2364fee23f9Smrg        text.  i.e.: "%0" is replaced by the full matching text, "%1"
2374fee23f9Smrg        is the first matching sub-expression, etc.
2384fee23f9Smrg
2394fee23f9Smrg        This is used as follows:
2404fee23f9Smrg
2414fee23f9Smrg            c_fix     = format;
2424fee23f9Smrg            c_fix_arg = "#ifndef %1\n%0\n#endif";
2434fee23f9Smrg            c_fix_arg = "#define[ \t]+([A-Z][A-Z0-9a-z_]*).*";
2444fee23f9Smrg
2454fee23f9Smrg        This would wrap a one line #define inside of a "#ifndef"/"#endif"
2464fee23f9Smrg        pair.  The second "c_fix_arg" may be omitted *IF* there is at least
2474fee23f9Smrg        one select clause and the first one identifies the text you wish to
2484fee23f9Smrg        reformat.  It will then be used as the second "c_fix_arg".  You may
2494fee23f9Smrg        delete the selected text by supplying an empty string for the
2504fee23f9Smrg        replacement format (the first "c_fix_arg").
2514fee23f9Smrg
2524fee23f9Smrg	Note: In general, a format c_fix may be used in place of one
2534fee23f9Smrg	sed expression.  However, it will need to be rewritten by
2544fee23f9Smrg	hand.  For example:
2554fee23f9Smrg
2564fee23f9Smrg	sed = 's@^#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7$'
2574fee23f9Smrg	       '@& || __GNUC__ >= 3@';
2584fee23f9Smrg
2594fee23f9Smrg	may be rewritten using a format c_fix as:
2604fee23f9Smrg
2614fee23f9Smrg	c_fix     = format;
2624fee23f9Smrg	c_fix_arg = '%0 || __GNUC__ >= 3';
2634fee23f9Smrg	c_fix_arg = '^#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7$';
2644fee23f9Smrg
2654fee23f9Smrg	Multiple sed substitution expressions probably ought to remain sed
2664fee23f9Smrg	expressions in order to maintain clarity.  Also note that if the
2674fee23f9Smrg	second sed expression is the same as the first select expression,
2684fee23f9Smrg	then you may omit the second c_fix_arg.  The select expression will
2694fee23f9Smrg	be picked up and used in its absence.
2704fee23f9Smrg
2714fee23f9SmrgEXAMPLES OF FIXES:
2724fee23f9Smrg==================
2734fee23f9Smrg
2744fee23f9Smrg      hackname = AAA_ki_iface;
2754fee23f9Smrg      replace; /* empty replacement -> no fixing the file */
2764fee23f9Smrg
2774fee23f9Smrg    When this ``fix'' is invoked, it will prevent any fixes
2784fee23f9Smrg    from being applied.
2794fee23f9Smrg
2804fee23f9Smrg    ------------------
2814fee23f9Smrg
2824fee23f9Smrg      hackname = AAB_svr4_no_varargs;
2834fee23f9Smrg      replace  = "/* This file was generated by fixincludes.  */\n"
2844fee23f9Smrg                 "#ifndef _SYS_VARARGS_H\n"
2854fee23f9Smrg                 "#define _SYS_VARARGS_H\n\n"
2864fee23f9Smrg
2874fee23f9Smrg                 "#ifdef __STDC__\n"
2884fee23f9Smrg                 "#include <stdarg.h>\n"
2894fee23f9Smrg                 "#else\n"
2904fee23f9Smrg                 "#include <varargs.h>\n"
2914fee23f9Smrg                 "#endif\n\n"
2924fee23f9Smrg
2934fee23f9Smrg                 "#endif  /* _SYS_VARARGS_H */\n";
2944fee23f9Smrg
2954fee23f9Smrg    When this ``fix'' is invoked, the replacement text will be
2964fee23f9Smrg    emitted into the replacement include file.  No further fixes
2974fee23f9Smrg    will be applied.
2984fee23f9Smrg
2994fee23f9Smrg    ------------------
3004fee23f9Smrg
3014fee23f9Smrg        hackname  = hpux11_fabsf;
3024fee23f9Smrg        files     = math.h;
3034fee23f9Smrg        select    = "^[ \t]*#[ \t]*define[ \t]+fabsf\\(.*";
3044fee23f9Smrg        bypass    = "__cplusplus";
3054fee23f9Smrg
3064fee23f9Smrg        c_fix     = format;
3074fee23f9Smrg        c_fix_arg = "#ifndef __cplusplus\n%0\n#endif";
3084fee23f9Smrg
3094fee23f9Smrg        test_text =
3104fee23f9Smrg        "#  define fabsf(x) ((float)fabs((double)(float)(x)))\n";
3114fee23f9Smrg
3124fee23f9Smrg    This fix will ensure that the #define for fabs is wrapped
3134fee23f9Smrg    with C++ protection, providing the header is not already
3144fee23f9Smrg    C++ aware.
3154fee23f9Smrg
3164fee23f9Smrg    ------------------
3174fee23f9Smrg
3184fee23f9Smrg5.  Testing fixes.
3194fee23f9Smrg
3204fee23f9Smrg    The brute force method is, of course, to configure and build
3214fee23f9Smrg    GCC.  But you can also:
3224fee23f9Smrg
3234fee23f9Smrg        cd ${top_builddir}/gcc
32448fb7bfaSmrg        rm -rf include-fixed/ stmp-fixinc
3254fee23f9Smrg        make stmp-fixinc
3264fee23f9Smrg
3274fee23f9Smrg    I would really recommend, however:
3284fee23f9Smrg
3294fee23f9Smrg        cd ${top_builddir}/fixincludes
3304fee23f9Smrg        make check
3314fee23f9Smrg
3324fee23f9Smrg    To do this, you *must* have autogen installed on your system.
3334fee23f9Smrg    The "check" step will proceed to construct a shell script that
3344fee23f9Smrg    will exercise all the fixes, using the sample test_text
3354fee23f9Smrg    provided with each fix.  Once done, the changes made will
3364fee23f9Smrg    be compared against the changes saved in the source directory.
3374fee23f9Smrg    If you are changing the tests or fixes, the change will likely
3384fee23f9Smrg    be highlighted.
339