]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/valgrind/src/valgrind-3.6.0-svn/coregrind/link_tool_exe_l4re.in
update
[l4.git] / l4 / pkg / valgrind / src / valgrind-3.6.0-svn / coregrind / link_tool_exe_l4re.in
1 #! @PERL@
2
3 # This script handles linking the tool executables on Linux for L4Re,
4 # statically and at an alternative load address.
5 #
6 # Linking statically sidesteps all sorts of complications to do with
7 # having two copies of the dynamic linker (valgrind's and the
8 # client's) coexisting in the same process.  The alternative load
9 # address is needed because Valgrind itself will load the client at
10 # whatever address it specifies, which is almost invariably the
11 # default load address.  Hence we can't allow Valgrind itself (viz,
12 # the tool executable) to be loaded at that address.
13 #
14 # Unfortunately there's no standard way to do 'static link at
15 # alternative address', so these link_tool_exe_*.in scripts handle
16 # the per-platform hoop-jumping.
17 #
18 # What we get passed here is:
19 #   first arg
20 #      the alternative load address
21 #   all the rest of the args
22 #      the gcc invokation to do the final link, that
23 #      the build system would have done, left to itself
24 #
25 # We just let the script 'die' if something is wrong, rather than do
26 # proper error reporting.  We don't expect the users to run this 
27 # directly.  It is only run as part of the build process, with 
28 # carefully constrained inputs.
29 #
30 # Linux/L4Re specific complications:
31 #
32 # - need to support both old GNU ld and gold: use -Ttext= to
33 #   set the text segment address.
34 #
35 # - need to pass --build-id=none (that is, -Wl,--build-id=none to
36 #   gcc) if it accepts it, to ensure the linker doesn't add a
37 #   notes section which ends up at the default load address and
38 #   so defeats our attempts to keep that address clear for the
39 #   client.  However, older linkers don't support this flag, so it
40 #   is tested for by configure.in and is shipped to us as part of
41 #   argv[2 ..].
42 #
43 # - need to specify a custom L4Re linker script: this is passed
44 #   by the L4Re build system through an environment variable and
45 #   we just need to read this out
46 #
47 #
48 # So: what we actually do:
49
50 #   pass the specified command to the linker as-is, except, add
51 #   "-static" and "-Ttext=<argv[1]>" and "-T$ENV["L4_LDS_stat_bin"]" to it.
52 #
53
54 use warnings;
55 use strict;
56
57 # expect at least: alt-load-address gcc -o foo bar.o
58 die "Not enough arguments"
59     if (($#ARGV + 1) < 5);
60
61 my $ala = $ARGV[0];
62
63 # check for plausible-ish alt load address
64 die "Bogus alt-load address"
65     if (length($ala) < 3 || index($ala, "0x") != 0);
66
67 my $linkscript = $ENV{"L4_LDS_stat_bin"};
68 my $cmdline = "";
69 my $cmdadd  = " -static -Wl,--defsym=__executable_start=$ala -Wl,-T$linkscript";
70
71 # Add the rest of the parameters
72 foreach my $n (1 .. $#ARGV) {
73    $cmdline = "$cmdline $ARGV[$n]";
74 }
75
76 $cmdline .= $cmdadd;
77
78 print "link_tool_exe_l4re: $cmdline\n";
79
80
81 # Execute the command:
82 my $r = system("$cmdline");
83
84 if ($r == 0) {
85     exit 0;
86 } else {
87     exit 1;
88 }