~ubuntu-branches/ubuntu/saucy/hardening-wrapper/saucy-proposed

« back to all changes in this revision

Viewing changes to builder-c++

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2008-01-08 16:00:58 UTC
  • Revision ID: james.westby@ubuntu.com-20080108160058-sfilpglt31x7124g
Tags: 1.1
Initial release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/perl
 
2
use strict;
 
3
use warnings;
 
4
 
 
5
my @args = ();
 
6
my $debug = 0;
 
7
 
 
8
if (defined($ENV{'DEB_BUILD_HARDENING'}) && $ENV{'DEB_BUILD_HARDENING'}!='0') {
 
9
    # Scan arguments
 
10
    my $use_stack =   defined($ENV{'DEB_BUILD_HARDENING_STACKPROTECTOR'}) ?
 
11
                            $ENV{'DEB_BUILD_HARDENING_STACKPROTECTOR'} : 1;
 
12
    my $use_format =  defined($ENV{'DEB_BUILD_HARDENING_FORMAT'}) ?
 
13
                            $ENV{'DEB_BUILD_HARDENING_FORMAT'} : 1;
 
14
    my $use_PIE =     defined($ENV{'DEB_BUILD_HARDENING_PIE'}) ?
 
15
                            $ENV{'DEB_BUILD_HARDENING_PIE'} : 1;
 
16
    my $use_fortify = defined($ENV{'DEB_BUILD_HARDENING_FORTIFY'}) ?
 
17
                            $ENV{'DEB_BUILD_HARDENING_FORTIFY'} : 1;
 
18
    $debug =         defined($ENV{'DEB_BUILD_HARDENING_DEBUG'}) ?
 
19
                            $ENV{'DEB_BUILD_HARDENING_DEBUG'} : 0;
 
20
 
 
21
    my $use_linker = 1;
 
22
    foreach my $arg (@ARGV) {
 
23
        if ($arg eq "-fPIC" ||
 
24
            $arg eq "-fpic" ||
 
25
            $arg eq "-fno-PIC" ||
 
26
            $arg eq "-fno-pic" ||
 
27
            $arg eq "-fno-PIE" ||
 
28
            $arg eq "-fno-pie" ||
 
29
            $arg eq "-nopie" ||
 
30
            $arg eq "-static" ||
 
31
            $arg eq "-shared" ||
 
32
            $arg eq "-D__KERNEL__" ||
 
33
            $arg eq "-nostdlib" ||
 
34
            $arg eq "-nostartfiles")
 
35
        {
 
36
            $use_PIE = 0;
 
37
        }
 
38
        if ($arg eq "-c") {
 
39
            $use_linker = 0;
 
40
        }
 
41
        if ($arg =~ /^-D_FORTIFY_SOURCE(=|$)/) {
 
42
            $use_fortify = 0;
 
43
        }
 
44
    }
 
45
 
 
46
    # Enable SSP by default (disable with -fno-stack-protector)
 
47
    if ($use_stack) {
 
48
        push(@args,'-fstack-protector');
 
49
    }
 
50
 
 
51
    # Enable -fPIE by default (disable with -nopie)
 
52
    if ($use_PIE) {
 
53
        push(@args, '-fPIE');
 
54
        if ($use_linker) {
 
55
            push(@args, '-pie');
 
56
        }
 
57
    }
 
58
 
 
59
    # Enable glibc protections by default (-02 should already be defined...)
 
60
    # (disable with -D_FORTIFY_SOURCE=0)
 
61
    if ($use_fortify) {
 
62
        push(@args,'-D_FORTIFY_SOURCE=2');
 
63
    }
 
64
 
 
65
    # Enable format string checking (disable with -Wno-format)
 
66
    if ($use_format) {
 
67
        push(@args,'-Wformat','-Wformat=security');
 
68
    }
 
69
}
 
70
 
 
71
my @target = ("g++.real", @args, @ARGV);
 
72
 
 
73
print STDERR join(" ",@target),"\n" if ($debug);
 
74
 
 
75
exec @target or die "Unable to exec $target[0]: $!\n";