Changeset bf61d3a in mainline for tools/autotool.py


Ignore:
Timestamp:
2010-11-26T01:34:21Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
273b958
Parents:
4b9a410 (diff), 7e752b2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge compile-time printf() argument checking, fixes of actual printf() arguments and related modifications

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/autotool.py

    r4b9a410 rbf61d3a  
    5353
    5454COMPILER_FAIL = "The compiler is probably not capable to compile HelenOS."
     55COMPILER_WARNING = "The compilation of HelenOS might fail."
    5556
    5657PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, tag, name, strc, conc, value) \\
     
    6162        )
    6263
     64#define STRING(arg)      STRING_ARG(arg)
     65#define STRING_ARG(arg)  #arg
     66
     67#define DECLARE_BUILTIN_TYPE(tag, type) \\
     68        AUTOTOOL_DECLARE("builtin", "", tag, STRING(type), "", "", sizeof(type));
     69
    6370#define DECLARE_INTSIZE(tag, type, strc, conc) \\
    6471        AUTOTOOL_DECLARE("intsize", "unsigned", tag, #type, strc, conc, sizeof(unsigned type)); \\
     
    6774int main(int argc, char *argv[])
    6875{
     76#ifdef __SIZE_TYPE__
     77        DECLARE_BUILTIN_TYPE("size", __SIZE_TYPE__);
     78#endif
     79#ifdef __WCHAR_TYPE__
     80        DECLARE_BUILTIN_TYPE("wchar", __WCHAR_TYPE__);
     81#endif
     82#ifdef __WINT_TYPE__
     83        DECLARE_BUILTIN_TYPE("wint", __WINT_TYPE__);
     84#endif
    6985"""
    7086
     
    96112       
    97113        sys.exit(1)
     114
     115def print_warning(msg):
     116        "Print a bold error message"
     117       
     118        sys.stderr.write("\n")
     119        sys.stderr.write("######################################################################\n")
     120        sys.stderr.write("HelenOS build sanity check warning:\n")
     121        sys.stderr.write("\n")
     122        sys.stderr.write("%s\n" % "\n".join(msg))
     123        sys.stderr.write("######################################################################\n")
     124        sys.stderr.write("\n")
     125       
     126        time.sleep(5)
    98127
    99128def sandbox_enter():
     
    186215        check_app([common['STRIP'], "--version"], "GNU strip", details)
    187216
     217def decode_value(value):
     218        "Decode integer value"
     219       
     220        base = 10
     221       
     222        if ((value.startswith('$')) or (value.startswith('#'))):
     223                value = value[1:]
     224       
     225        if (value.startswith('0x')):
     226                value = value[2:]
     227                base = 16
     228       
     229        return int(value, base)
     230
    188231def probe_compiler(common, sizes):
    189232        "Generate, compile and parse probing source"
     
    237280        signed_concs = {}
    238281       
     282        builtins = {}
     283       
    239284        for j in range(len(lines)):
    240285                tokens = lines[j].strip().split("\t")
     
    254299                               
    255300                                if (category == "intsize"):
    256                                         base = 10
    257                                        
    258                                         if ((value.startswith('$')) or (value.startswith('#'))):
    259                                                 value = value[1:]
    260                                        
    261                                         if (value.startswith('0x')):
    262                                                 value = value[2:]
    263                                                 base = 16
    264                                        
    265301                                        try:
    266                                                 value_int = int(value, base)
     302                                                value_int = decode_value(value)
    267303                                        except:
    268304                                                print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
    269305                                       
    270306                                        if (subcategory == "unsigned"):
    271                                                 unsigned_sizes[name] = value_int
     307                                                unsigned_sizes[value_int] = name
    272308                                                unsigned_tags[tag] = value_int
    273                                                 unsigned_strcs[strc] = value_int
    274                                                 unsigned_concs[conc] = value_int
     309                                                unsigned_strcs[value_int] = strc
     310                                                unsigned_concs[value_int] = conc
    275311                                        elif (subcategory == "signed"):
    276                                                 signed_sizes[name] = value_int
     312                                                signed_sizes[value_int] = name
    277313                                                signed_tags[tag] = value_int
    278                                                 signed_strcs[strc] = value_int
    279                                                 signed_concs[conc] = value_int
     314                                                signed_strcs[value_int] = strc
     315                                                signed_concs[value_int] = conc
    280316                                        else:
    281317                                                print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL])
    282        
    283         return {'unsigned_sizes': unsigned_sizes, 'signed_sizes': signed_sizes, 'unsigned_tags': unsigned_tags, 'signed_tags': signed_tags, 'unsigned_strcs': unsigned_strcs, 'signed_strcs': signed_strcs, 'unsigned_concs': unsigned_concs, 'signed_concs': signed_concs}
    284 
    285 def detect_uints(probe, bytes):
     318                               
     319                                if (category == "builtin"):
     320                                        try:
     321                                                value_int = decode_value(value)
     322                                        except:
     323                                                print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
     324                                       
     325                                        builtins[tag] = {'name': name, 'value': value_int}
     326       
     327        return {'unsigned_sizes': unsigned_sizes, 'signed_sizes': signed_sizes, 'unsigned_tags': unsigned_tags, 'signed_tags': signed_tags, 'unsigned_strcs': unsigned_strcs, 'signed_strcs': signed_strcs, 'unsigned_concs': unsigned_concs, 'signed_concs': signed_concs, 'builtins': builtins}
     328
     329def detect_uints(probe, bytes, tags):
    286330        "Detect correct types for fixed-size integer types"
    287331       
     
    290334       
    291335        for b in bytes:
     336                if (not b in probe['unsigned_sizes']):
     337                        print_error(['Unable to find appropriate unsigned integer type for %u bytes' % b,
     338                                     COMPILER_FAIL])
     339               
     340                if (not b in probe['signed_sizes']):
     341                        print_error(['Unable to find appropriate signed integer type for %u bytes' % b,
     342                                     COMPILER_FAIL])
     343               
     344                if (not b in probe['unsigned_strcs']):
     345                        print_error(['Unable to find appropriate unsigned printf formatter for %u bytes' % b,
     346                                     COMPILER_FAIL])
     347               
     348                if (not b in probe['signed_strcs']):
     349                        print_error(['Unable to find appropriate signed printf formatter for %u bytes' % b,
     350                                     COMPILER_FAIL])
     351               
     352                if (not b in probe['unsigned_concs']):
     353                        print_error(['Unable to find appropriate unsigned literal macro for %u bytes' % b,
     354                                     COMPILER_FAIL])
     355               
     356                if (not b in probe['signed_concs']):
     357                        print_error(['Unable to find appropriate signed literal macro for %u bytes' % b,
     358                                     COMPILER_FAIL])
     359               
     360                typedefs.append({'oldtype': "unsigned %s" % probe['unsigned_sizes'][b], 'newtype': "uint%u_t" % (b * 8)})
     361                typedefs.append({'oldtype': "signed %s" % probe['signed_sizes'][b], 'newtype': "int%u_t" % (b * 8)})
     362               
     363                macros.append({'oldmacro': "\"%so\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIo%u" % (b * 8)})
     364                macros.append({'oldmacro': "\"%su\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIu%u" % (b * 8)})
     365                macros.append({'oldmacro': "\"%sx\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIx%u" % (b * 8)})
     366                macros.append({'oldmacro': "\"%sX\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIX%u" % (b * 8)})
     367                macros.append({'oldmacro': "\"%sd\"" % probe['signed_strcs'][b], 'newmacro': "PRId%u" % (b * 8)})
     368               
     369                name = probe['unsigned_concs'][b]
     370                if ((name.startswith('@')) or (name == "")):
     371                        macros.append({'oldmacro': "c ## U", 'newmacro': "UINT%u_C(c)" % (b * 8)})
     372                else:
     373                        macros.append({'oldmacro': "c ## U%s" % name, 'newmacro': "UINT%u_C(c)" % (b * 8)})
     374               
     375                name = probe['unsigned_concs'][b]
     376                if ((name.startswith('@')) or (name == "")):
     377                        macros.append({'oldmacro': "c", 'newmacro': "INT%u_C(c)" % (b * 8)})
     378                else:
     379                        macros.append({'oldmacro': "c ## %s" % name, 'newmacro': "INT%u_C(c)" % (b * 8)})
     380       
     381        for tag in tags:
     382                newmacro = "U%s" % tag
     383                if (not tag in probe['unsigned_tags']):
     384                        print_error(['Unable to find appropriate size macro for %s' % newmacro,
     385                                     COMPILER_FAIL])
     386               
     387                oldmacro = "UINT%s" % (probe['unsigned_tags'][tag] * 8)
     388                macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
     389                macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
     390               
     391                newmacro = tag
     392                if (not tag in probe['unsigned_tags']):
     393                        print_error(['Unable to find appropriate size macro for %s' % newmacro,
     394                                     COMPILER_FAIL])
     395               
     396                oldmacro = "INT%s" % (probe['signed_tags'][tag] * 8)
     397                macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
     398                macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
     399       
     400        fnd = True
     401       
     402        if (not 'wchar' in probe['builtins']):
     403                print_warning(['The compiler does not provide the macro __WCHAR_TYPE__',
     404                               'for defining the compiler-native type wchar_t. We are',
     405                               'forced to define wchar_t as a hardwired type int32_t.',
     406                               COMPILER_WARNING])
    292407                fnd = False
    293                 for name, value in probe['unsigned_sizes'].items():
    294                         if (value == b):
    295                                 typedefs.append({'oldtype': "unsigned %s" % name, 'newtype': "uint%u_t" % (b * 8)})
    296                                 fnd = True
    297                                 break
    298                
    299                 if (not fnd):
    300                         print_error(['Unable to find appropriate unsigned integer type for %u bytes' % b,
    301                                      COMPILER_FAIL])
    302                
    303                
     408       
     409        if (probe['builtins']['wchar']['value'] != 4):
     410                print_warning(['The compiler provided macro __WCHAR_TYPE__ for defining',
     411                               'the compiler-native type wchar_t is not compliant with',
     412                               'HelenOS. We are forced to define wchar_t as a hardwired',
     413                               'type int32_t.',
     414                               COMPILER_WARNING])
    304415                fnd = False
    305                 for name, value in probe['signed_sizes'].items():
    306                         if (value == b):
    307                                 typedefs.append({'oldtype': "signed %s" % name, 'newtype': "int%u_t" % (b * 8)})
    308                                 fnd = True
    309                                 break
    310                
    311                 if (not fnd):
    312                         print_error(['Unable to find appropriate signed integer type for %u bytes' % b,
    313                                      COMPILER_FAIL])
    314                
    315                
     416       
     417        if (not fnd):
     418                macros.append({'oldmacro': "int32_t", 'newmacro': "wchar_t"})
     419        else:
     420                macros.append({'oldmacro': "__WCHAR_TYPE__", 'newmacro': "wchar_t"})
     421       
     422        fnd = True
     423       
     424        if (not 'wint' in probe['builtins']):
     425                print_warning(['The compiler does not provide the macro __WINT_TYPE__',
     426                               'for defining the compiler-native type wint_t. We are',
     427                               'forced to define wint_t as a hardwired type int32_t.',
     428                               COMPILER_WARNING])
    316429                fnd = False
    317                 for name, value in probe['unsigned_strcs'].items():
    318                         if (value == b):
    319                                 macros.append({'oldmacro': "\"%so\"" % name, 'newmacro': "PRIo%u" % (b * 8)})
    320                                 macros.append({'oldmacro': "\"%su\"" % name, 'newmacro': "PRIu%u" % (b * 8)})
    321                                 macros.append({'oldmacro': "\"%sx\"" % name, 'newmacro': "PRIx%u" % (b * 8)})
    322                                 macros.append({'oldmacro': "\"%sX\"" % name, 'newmacro': "PRIX%u" % (b * 8)})
    323                                 fnd = True
    324                                 break
    325                
    326                 if (not fnd):
    327                         print_error(['Unable to find appropriate unsigned printf formatter for %u bytes' % b,
    328                                      COMPILER_FAIL])
    329                
    330                
     430       
     431        if (probe['builtins']['wint']['value'] != 4):
     432                print_warning(['The compiler provided macro __WINT_TYPE__ for defining',
     433                               'the compiler-native type wint_t is not compliant with',
     434                               'HelenOS. We are forced to define wint_t as a hardwired',
     435                               'type int32_t.',
     436                               COMPILER_WARNING])
    331437                fnd = False
    332                 for name, value in probe['signed_strcs'].items():
    333                         if (value == b):
    334                                 macros.append({'oldmacro': "\"%sd\"" % name, 'newmacro': "PRId%u" % (b * 8)})
    335                                 fnd = True
    336                                 break
    337                
    338                 if (not fnd):
    339                         print_error(['Unable to find appropriate signed printf formatter for %u bytes' % b,
    340                                      COMPILER_FAIL])
    341                
    342                
    343                 fnd = False
    344                 for name, value in probe['unsigned_concs'].items():
    345                         if (value == b):
    346                                 if ((name.startswith('@')) or (name == "")):
    347                                         macros.append({'oldmacro': "c ## U", 'newmacro': "UINT%u_C(c)" % (b * 8)})
    348                                 else:
    349                                         macros.append({'oldmacro': "c ## U%s" % name, 'newmacro': "UINT%u_C(c)" % (b * 8)})
    350                                 fnd = True
    351                                 break
    352                
    353                 if (not fnd):
    354                         print_error(['Unable to find appropriate unsigned literal macro for %u bytes' % b,
    355                                      COMPILER_FAIL])
    356                
    357                
    358                 fnd = False
    359                 for name, value in probe['signed_concs'].items():
    360                         if (value == b):
    361                                 if ((name.startswith('@')) or (name == "")):
    362                                         macros.append({'oldmacro': "c", 'newmacro': "INT%u_C(c)" % (b * 8)})
    363                                 else:
    364                                         macros.append({'oldmacro': "c ## %s" % name, 'newmacro': "INT%u_C(c)" % (b * 8)})
    365                                 fnd = True
    366                                 break
    367                
    368                 if (not fnd):
    369                         print_error(['Unable to find appropriate unsigned literal macro for %u bytes' % b,
    370                                      COMPILER_FAIL])
    371        
    372         for tag in ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG']:
    373                 fnd = False;
    374                 newmacro = "U%s" % tag
    375                
    376                 for name, value in probe['unsigned_tags'].items():
    377                         if (name == tag):
    378                                 oldmacro = "UINT%s" % (value * 8)
    379                                 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
    380                                 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
    381                                 fnd = True
    382                                 break
    383                
    384                 if (not fnd):
    385                         print_error(['Unable to find appropriate size macro for %s' % newmacro,
    386                                      COMPILER_FAIL])
    387                
    388                 fnd = False;
    389                 newmacro = tag
    390                
    391                 for name, value in probe['signed_tags'].items():
    392                         if (name == tag):
    393                                 oldmacro = "INT%s" % (value * 8)
    394                                 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
    395                                 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
    396                                 fnd = True
    397                                 break
    398                
    399                 if (not fnd):
    400                         print_error(['Unable to find appropriate size macro for %s' % newmacro,
    401                                      COMPILER_FAIL])
     438       
     439        if (not fnd):
     440                macros.append({'oldmacro': "int32_t", 'newmacro': "wint_t"})
     441        else:
     442                macros.append({'oldmacro': "__WINT_TYPE__", 'newmacro': "wint_t"})
    402443       
    403444        return {'macros': macros, 'typedefs': typedefs}
     
    571612                probe = probe_compiler(common,
    572613                        [
    573                                 {'type': 'char', 'tag': 'CHAR', 'strc': '"hh"', 'conc': '"@@"'},
     614                                {'type': 'long long int', 'tag': 'LLONG', 'strc': '"ll"', 'conc': '"LL"'},
     615                                {'type': 'long int', 'tag': 'LONG', 'strc': '"l"', 'conc': '"L"'},
     616                                {'type': 'int', 'tag': 'INT', 'strc': '""', 'conc': '""'},
    574617                                {'type': 'short int', 'tag': 'SHORT', 'strc': '"h"', 'conc': '"@"'},
    575                                 {'type': 'int', 'tag': 'INT', 'strc': '""', 'conc': '""'},
    576                                 {'type': 'long int', 'tag': 'LONG', 'strc': '"l"', 'conc': '"L"'},
    577                                 {'type': 'long long int', 'tag': 'LLONG', 'strc': '"ll"', 'conc': '"LL"'}
     618                                {'type': 'char', 'tag': 'CHAR', 'strc': '"hh"', 'conc': '"@@"'}
    578619                        ]
    579620                )
    580621               
    581                 maps = detect_uints(probe, [1, 2, 4, 8])
     622                maps = detect_uints(probe, [1, 2, 4, 8], ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG'])
    582623               
    583624        finally:
Note: See TracChangeset for help on using the changeset viewer.