~ubuntu-branches/ubuntu/karmic/hardening-wrapper/karmic

« back to all changes in this revision

Viewing changes to builder-ld

  • 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
    $debug =         defined($ENV{'DEB_BUILD_HARDENING_DEBUG'}) ?
 
10
                            $ENV{'DEB_BUILD_HARDENING_DEBUG'} : 0;
 
11
 
 
12
    # Enable RELRO by default
 
13
    my $use_relro = defined($ENV{'DEB_BUILD_HARDENING_RELRO'}) ?
 
14
                        $ENV{'DEB_BUILD_HARDENING_RELRO'} : 1;
 
15
    if ($use_relro) {
 
16
        push(@args,'-z relro');
 
17
    }
 
18
 
 
19
    # Enable PIE by default
 
20
    my $use_PIE = defined($ENV{'DEB_BUILD_HARDENING_PIE'}) ?
 
21
                        $ENV{'DEB_BUILD_HARDENING_PIE'} : 1;
 
22
    foreach my $arg (@ARGV) {
 
23
        if ($arg eq "-nopie" ||
 
24
            $arg eq "-fno-PIE" ||
 
25
            $arg eq "-fno-pie" ||
 
26
            $arg eq "-static" ||
 
27
            $arg eq "-shared" ||
 
28
            $arg eq "-nostdlib" ||
 
29
            $arg eq "-nostartfiles")
 
30
        {
 
31
            $use_PIE = 0;
 
32
        }
 
33
    }
 
34
    if ($use_PIE) {
 
35
        push(@args,'-pie');
 
36
    }
 
37
}
 
38
 
 
39
my @target = ("ld.real", @args, @ARGV);
 
40
 
 
41
print STDERR join(" ",@target),"\n" if ($debug);
 
42
 
 
43
exec @target or die "Unable to exec $target[0]: $!\n";