File: link_tool_exe_linux.in

package info (click to toggle)
valgrind 1%3A3.7.0-6
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 58,060 kB
  • sloc: ansic: 396,820; xml: 18,453; cpp: 6,698; asm: 5,584; perl: 5,008; sh: 4,852; makefile: 3,965; exp: 625; haskell: 195
file content (88 lines) | stat: -rw-r--r-- 2,606 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#! @PERL@

# This script handles linking the tool executables on Linux,
# statically and at an alternative load address.
#
# Linking statically sidesteps all sorts of complications to do with
# having two copies of the dynamic linker (valgrind's and the
# client's) coexisting in the same process.  The alternative load
# address is needed because Valgrind itself will load the client at
# whatever address it specifies, which is almost invariably the
# default load address.  Hence we can't allow Valgrind itself (viz,
# the tool executable) to be loaded at that address.
#
# Unfortunately there's no standard way to do 'static link at
# alternative address', so these link_tool_exe_*.in scripts handle
# the per-platform hoop-jumping.
#
# What we get passed here is:
#   first arg
#      the alternative load address
#   all the rest of the args
#      the gcc invokation to do the final link, that
#      the build system would have done, left to itself
#
# We just let the script 'die' if something is wrong, rather than do
# proper error reporting.  We don't expect the users to run this 
# directly.  It is only run as part of the build process, with 
# carefully constrained inputs.
#
# Linux specific complications:
#
# - need to support both old GNU ld and gold: use -Ttext= to
#   set the text segment address.
#
# - need to pass --build-id=none (that is, -Wl,--build-id=none to
#   gcc) if it accepts it, to ensure the linker doesn't add a
#   notes section which ends up at the default load address and
#   so defeats our attempts to keep that address clear for the
#   client.  However, older linkers don't support this flag, so it
#   is tested for by configure.in and is shipped to us as part of
#   argv[2 ..].
#
#
# So: what we actually do:
# 
#   pass the specified command to the linker as-is, except, add
#   "-static" and "-Ttext=<argv[1]>" to it.
#

use warnings;
use strict;

# expect at least: alt-load-address gcc -o foo bar.o
die "Not enough arguments"
    if (($#ARGV + 1) < 5);

my $ala = $ARGV[0];

# check for plausible-ish alt load address
die "Bogus alt-load address"
    if (length($ala) < 3 || index($ala, "0x") != 0);

# The cc invokation to do the final link
my $cc = $ARGV[1];

# and the 'restargs' are argv[2 ..]

# so, build up the complete command here:
# 'cc' -static -Ttext='ala' 'restargs'

my $cmd="$cc -static -Wl,-Ttext=$ala";

# Add the rest of the parameters
foreach my $n (2 .. $#ARGV) {
   $cmd = "$cmd $ARGV[$n]";
}

#print "link_tool_exe_linux: $cmd\n";


# Execute the command:
my $r = system("$cmd");

if ($r == 0) {
    exit 0;
} else {
    exit 1;
}