Print this page
11972 resync smatch

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/cgcc
          +++ new/usr/src/tools/smatch/src/cgcc
   1    1  #!/usr/bin/perl -w
   2    2  # -----------------------------------------------------------------------------
   3    3  
        4 +use strict;
        5 +use warnings;
        6 +
   4    7  my $cc = $ENV{'REAL_CC'} || 'cc';
   5    8  my $check = $ENV{'CHECK'} || 'sparse';
   6    9  my $ccom = $cc;
   7   10  
   8   11  my $m32 = 0;
   9   12  my $m64 = 0;
  10   13  my $has_specs = 0;
  11   14  my $gendeps = 0;
  12   15  my $do_check = 0;
  13   16  my $do_compile = 1;
  14   17  my $gcc_base_dir;
  15   18  my $multiarch_dir;
  16   19  my $verbose = 0;
       20 +my $nargs = 0;
  17   21  
  18   22  while (@ARGV) {
  19   23      $_ = shift(@ARGV);
       24 +
       25 +    if ($nargs) {
       26 +        $nargs--;
       27 +        goto add_option;
       28 +    }
       29 +
  20   30      # Look for a .c file.  We don't want to run the checker on .o or .so files
  21      -    # in the link run.  (This simplistic check knows nothing about options
  22      -    # with arguments, but it seems to do the job.)
       31 +    # in the link run.
  23   32      $do_check = 1 if /^[^-].*\.c$/;
  24   33  
  25   34      # Ditto for stdin.
  26   35      $do_check = 1 if $_ eq '-';
  27   36  
       37 +    if (/^-(o|MF|MT|MQ)$/) {
       38 +        # Need to be checked explicitly since otherwise
       39 +        # the argument would be processed as a
       40 +        # (non-existant) source file or as an option.
       41 +        die ("$0: missing argument for $_") if !@ARGV;
       42 +        $nargs = 1;
       43 +    }
       44 +
       45 +    # Ignore the extension if '-x c' is given.
       46 +    if ($_ eq '-x') {
       47 +        die ("$0: missing argument for $_") if !@ARGV;
       48 +        die ("$0: invalid argument for $_") if $ARGV[0] ne 'c';
       49 +        $do_check = 1;
       50 +        $nargs = 1;
       51 +    }
       52 +
  28   53      $m32 = 1 if /^-m32$/;
  29   54      $m64 = 1 if /^-m64$/;
  30      -    $gendeps = 1 if /^-M$/;
       55 +    $gendeps = 1 if /^-(M|MM|MD|MMD)$/;
  31   56  
  32   57      if (/^-target=(.*)$/) {
  33   58          $check .= &add_specs ($1);
  34   59          $has_specs = 1;
  35   60          next;
  36   61      }
  37   62  
  38   63      if ($_ eq '-no-compile') {
  39   64          $do_compile = 0;
  40   65          next;
↓ open down ↓ 9 lines elided ↑ open up ↑
  50   75          $multiarch_dir = shift @ARGV;
  51   76          die ("$0: missing argument for -multiarch-dir option") if !$multiarch_dir;
  52   77          next;
  53   78      }
  54   79  
  55   80      # If someone adds "-E", don't pre-process twice.
  56   81      $do_compile = 0 if $_ eq '-E';
  57   82  
  58   83      $verbose = 1 if $_ eq '-v';
  59   84  
       85 +add_option:
  60   86      my $this_arg = ' ' . &quote_arg ($_);
  61   87      $cc .= $this_arg unless &check_only_option ($_);
  62   88      $check .= $this_arg;
  63   89  }
  64   90  
  65   91  if ($gendeps) {
  66   92      $do_compile = 1;
  67   93      $do_check = 0;
  68   94  }
  69   95  
↓ open down ↓ 24 lines elided ↑ open up ↑
  94  120      exec ($cc);
  95  121  }
  96  122  
  97  123  exit 0;
  98  124  
  99  125  # -----------------------------------------------------------------------------
 100  126  # Check if an option is for "check" only.
 101  127  
 102  128  sub check_only_option {
 103  129      my ($arg) = @_;
 104      -    return 1 if $arg =~ /^-W(no-?)?(address-space|bitwise|cast-to-as|cast-truncate|context|decl|default-bitfield-sign|designated-init|do-while|enum-mismatch|external-function-has-definition|init-cstring|memcpy-max-count|non-ansi-function-declaration|non-pointer-null|old-initializer|one-bit-signed-bitfield|override-init-all|paren-string|ptr-subtraction-blows|return-void|sizeof-bool|sparse-all|sparse-error|transparent-union|typesign|undef|unknown-attribute)$/;
      130 +    return 1 if $arg =~ /^-W(no-?)?(address-space|bitwise|cast-to-as|cast-truncate|constant-suffix|context|decl|default-bitfield-sign|designated-init|do-while|enum-mismatch|external-function-has-definition|init-cstring|memcpy-max-count|non-pointer-null|old-initializer|one-bit-signed-bitfield|override-init-all|paren-string|ptr-subtraction-blows|return-void|sizeof-bool|sparse-all|sparse-error|transparent-union|typesign|undef|unknown-attribute)$/;
 105  131      return 1 if $arg =~ /^-v(no-?)?(entry|dead)$/;
 106      -    return 1 if $arg =~ /^-f(dump-linearize|memcpy-max-count)(=\S*)?$/;
      132 +    return 1 if $arg =~ /^-f(dump-ir|memcpy-max-count|diagnostic-prefix)(=\S*)?$/;
      133 +    return 1 if $arg =~ /^-f(mem2reg|optim)(-enable|-disable|=last)?$/;
 107  134      return 0;
 108  135  }
 109  136  
 110  137  # -----------------------------------------------------------------------------
 111  138  # Simple arg-quoting function.  Just adds backslashes when needed.
 112  139  
 113  140  sub quote_arg {
 114  141      my ($arg) = @_;
 115  142      return "''" if $arg eq '';
 116  143      return join ('',
↓ open down ↓ 117 lines elided ↑ open up ↑
 234  261              ' -DNULL="((void *)0)"';
 235  262      } elsif ($spec eq 'linux') {
 236  263          return &add_specs ('unix') .
 237  264              ' -D__linux__=1 -D__linux=1 -Dlinux=linux';
 238  265      } elsif ($spec eq 'gnu/kfreebsd') {
 239  266          return &add_specs ('unix') .
 240  267              ' -D__FreeBSD_kernel__=1';
 241  268      } elsif ($spec eq 'openbsd') {
 242  269          return &add_specs ('unix') .
 243  270              ' -D__OpenBSD__=1';
      271 +    } elsif ($spec eq 'freebsd') {
      272 +        return &add_specs ('unix') .
      273 +            ' -D__FreeBSD__=1';
      274 +    } elsif ($spec eq 'netbsd') {
      275 +        return &add_specs ('unix') .
      276 +            ' -D__NetBSD__=1';
 244  277      } elsif ($spec eq 'darwin') {
 245  278          return
 246      -            ' -D__APPLE__=1 -D__MACH__=1';
      279 +            ' -D__APPLE__=1 -D__APPLE_CC__=1 -D__MACH__=1';
      280 +    } elsif ($spec eq 'gnu') {          # Hurd
      281 +        return &add_specs ('unix') .    # So, GNU is Unix, uh?
      282 +            ' -D__GNU__=1 -D__gnu_hurd__=1 -D__MACH__=1';
 247  283      } elsif ($spec eq 'unix') {
 248  284          return ' -Dunix=1 -D__unix=1 -D__unix__=1';
 249  285      } elsif ( $spec =~ /^cygwin/) {
 250  286          return &add_specs ('unix') .
 251  287              ' -D__CYGWIN__=1 -D__CYGWIN32__=1' .
 252  288              " -D'_cdecl=__attribute__((__cdecl__))'" .
 253  289              " -D'__cdecl=__attribute__((__cdecl__))'" .
 254  290              " -D'_stdcall=__attribute__((__stdcall__))'" .
 255  291              " -D'__stdcall=__attribute__((__stdcall__))'" .
 256  292              " -D'_fastcall=__attribute__((__fastcall__))'" .
 257  293              " -D'__fastcall=__attribute__((__fastcall__))'" .
 258  294              " -D'__declspec(x)=__attribute__((x))'";
 259      -    } elsif ($spec eq 'i86') {
 260      -        return (' -D__i386=1 -D__i386__=1' .
 261      -                &integer_types (8, 16, 32, $m64 ? 64 : 32, 64) .
 262      -                &float_types (1, 1, 21, [24,8], [53,11], [64,15]) .
 263      -                &define_size_t ($m64 ? "long unsigned int" : "unsigned int") .
 264      -                ' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4'));
      295 +    } elsif ($spec eq 'i386') {
      296 +        return (
      297 +                &float_types (1, 1, 21, [24,8], [53,11], [64,15]));
 265  298      } elsif ($spec eq 'sparc') {
 266      -        return (' -D__sparc=1 -D__sparc__=1' .
      299 +        return (
 267  300                  &integer_types (8, 16, 32, $m64 ? 64 : 32, 64) .
 268  301                  &float_types (1, 1, 33, [24,8], [53,11], [113,15]) .
 269  302                  &define_size_t ($m64 ? "long unsigned int" : "unsigned int") .
 270  303                  ' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4'));
 271  304      } elsif ($spec eq 'sparc64') {
 272      -        return (' -D__sparc=1 -D__sparc__=1 -D__sparcv9__=1 -D__sparc64__=1 -D__arch64__=1 -D__LP64__=1' .
      305 +        return (
 273  306                  &integer_types (8, 16, 32, 64, 64, 128) .
 274  307                  &float_types (1, 1, 33, [24,8], [53,11], [113,15]) .
 275  308                  &define_size_t ("long unsigned int") .
 276  309                  ' -D__SIZEOF_POINTER__=8');
 277  310      } elsif ($spec eq 'x86_64') {
 278      -        return (' -D__x86_64=1 -D__x86_64__=1' . ($m32 ? '' : ' -D__LP64__=1') .
 279      -                &integer_types (8, 16, 32, $m32 ? 32 : 64, 64, 128) .
 280      -                &float_types (1, 1, 33, [24,8], [53,11], [113,15]) .
 281      -                &define_size_t ($m32 ? "unsigned int" : "long unsigned int") .
 282      -                ' -D__SIZEOF_POINTER__=' . ($m32 ? '4' : '8'));
      311 +        return &float_types (1, 1, 33, [24,8], [53,11], [113,15]);
 283  312      } elsif ($spec eq 'ppc') {
 284      -        return (' -D__powerpc__=1 -D_BIG_ENDIAN -D_STRING_ARCH_unaligned=1' .
      313 +        return (' -D_BIG_ENDIAN -D_STRING_ARCH_unaligned=1' .
 285  314                  &integer_types (8, 16, 32, $m64 ? 64 : 32, 64) .
 286  315                  &float_types (1, 1, 21, [24,8], [53,11], [113,15]) .
 287  316                  &define_size_t ($m64 ? "long unsigned int" : "unsigned int") .
 288  317                  ' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4'));
 289  318      } elsif ($spec eq 'ppc64') {
 290      -        return (' -D__powerpc__=1 -D__PPC__=1 -D_STRING_ARCH_unaligned=1' .
 291      -                ' -D__powerpc64__=1 -D__PPC64__=1' .
 292      -                ' -m64' .
      319 +        return (' -D_STRING_ARCH_unaligned=1 -m64' .
 293  320                  &float_types (1, 1, 21, [24,8], [53,11], [113,15]));
      321 +    } elsif ($spec eq 'ppc64+be') {
      322 +        return &add_specs ('ppc64') . ' -mbig-endian -D_CALL_ELF=1';
      323 +    } elsif ($spec eq 'ppc64+le') {
      324 +        return &add_specs ('ppc64') . ' -mlittle-endian -D_CALL_ELF=2';
 294  325      } elsif ($spec eq 's390x') {
 295      -        return (' -D__s390x__ -D__s390__ -D_BIG_ENDIAN' .
      326 +        return (' -D_BIG_ENDIAN' .
 296  327                  &integer_types (8, 16, 32, $m64 ? 64 : 32, 64) .
 297  328                  &float_types (1, 1, 36, [24,8], [53,11], [113,15]) .
 298  329                  &define_size_t ("long unsigned int") .
 299  330                  ' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4'));
 300  331      } elsif ($spec eq 'arm') {
 301      -        chomp (my $gccmachine = `$cc -dumpmachine`);
 302      -        my $cppsymbols = ' -D__arm__=1 -m32';
 303      -
 304      -        if ($gccmachine eq 'arm-linux-gnueabihf') {
 305      -            $cppsymbols .= ' -D__ARM_PCS_VFP=1';
 306      -        }
 307      -
 308      -        return ($cppsymbols .
      332 +        return (' -m32' .
 309  333                  &float_types (1, 1, 36, [24,8], [53,11], [53, 11]));
      334 +    } elsif ($spec eq 'arm+hf') {
      335 +        return &add_specs ('arm') . ' -D__ARM_PCS_VFP=1';
 310  336      } elsif ($spec eq 'aarch64') {
 311      -        return (' -D__aarch64__=1 -m64' .
      337 +        return (' -m64' .
 312  338                  &float_types (1, 1, 36, [24,8], [53,11], [113,15]));
 313  339      } elsif ($spec eq 'host_os_specs') {
 314  340          my $os = `uname -s`;
 315  341          chomp $os;
 316  342          return &add_specs (lc $os);
 317  343      } elsif ($spec eq 'host_arch_specs') {
 318      -        my $arch = `uname -m`;
      344 +        my $gccmachine;
      345 +        my $arch;
      346 +
      347 +        $gccmachine = `$ccom -dumpmachine`;
      348 +        chomp $gccmachine;
      349 +
      350 +        if ($gccmachine =~ '^aarch64-') {
      351 +            return &add_specs ('aarch64');
      352 +        } elsif ($gccmachine =~ '^arm-.*eabihf$') {
      353 +            return &add_specs ('arm+hf');
      354 +        } elsif ($gccmachine =~ '^arm-') {
      355 +            return &add_specs ('arm');
      356 +        } elsif ($gccmachine =~ '^i[23456]86-') {
      357 +            return &add_specs ('i386');
      358 +        } elsif ($gccmachine =~ '^(powerpc|ppc)64le-') {
      359 +            return &add_specs ('ppc64+le');
      360 +        } elsif ($gccmachine =~ '^s390x-') {
      361 +            return &add_specs ('s390x');
      362 +        } elsif ($gccmachine eq 'x86_64-linux-gnux32') {
      363 +            return &add_specs ('x86_64') . ' -mx32';
      364 +        } elsif ($gccmachine =~ '^x86_64-') {
      365 +            return &add_specs ('x86_64');
      366 +        }
      367 +
      368 +        # fall back to uname -m to determine the specifics.
      369 +        # Note: this is only meaningful when using natively
      370 +        #       since information about the host is used to
      371 +        #       guess characteristics of the target.
      372 +
      373 +        $arch = `uname -m`;
 319  374          chomp $arch;
 320  375          if ($arch =~ /^(i.?86|athlon)$/i) {
 321      -            return &add_specs ('i86');
      376 +            return &add_specs ('i386');
 322  377          } elsif ($arch =~ /^(sun4u)$/i) {
 323  378              return &add_specs ('sparc');
 324  379          } elsif ($arch =~ /^(x86_64)$/i) {
 325  380              return &add_specs ('x86_64');
 326  381          } elsif ($arch =~ /^(ppc)$/i) {
 327  382              return &add_specs ('ppc');
 328  383          } elsif ($arch =~ /^(ppc64)$/i) {
 329      -            return &add_specs ('ppc64') . ' -mbig-endian -D_CALL_ELF=1';
      384 +            return &add_specs ('ppc64+be');
 330  385          } elsif ($arch =~ /^(ppc64le)$/i) {
 331      -            return &add_specs ('ppc64') . ' -mlittle-endian -D_CALL_ELF=2';
      386 +            return &add_specs ('ppc64+le');
 332  387          } elsif ($arch =~ /^(s390x)$/i) {
 333  388              return &add_specs ('s390x');
 334  389          } elsif ($arch =~ /^(sparc64)$/i) {
 335  390              return &add_specs ('sparc64');
 336  391          } elsif ($arch =~ /^arm(?:v[78]l)?$/i) {
 337  392              return &add_specs ('arm');
 338  393          } elsif ($arch =~ /^(aarch64)$/i) {
 339  394              return &add_specs ('aarch64');
 340  395          }
 341  396      } else {
 342  397          die "$0: invalid specs: $spec\n";
 343  398      }
 344  399  }
 345  400  
 346  401  # -----------------------------------------------------------------------------
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX