3 # This script handles linking the tool executables on Linux for L4Re,
4 # statically and at an alternative load address.
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.
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.
18 # What we get passed here is:
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
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.
30 # Linux/L4Re specific complications:
32 # - need to support both old GNU ld and gold: use -Ttext= to
33 # set the text segment address.
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
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
48 # So: what we actually do:
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.
57 # expect at least: alt-load-address gcc -o foo bar.o
58 die "Not enough arguments"
59 if (($#ARGV + 1) < 5);
63 # check for plausible-ish alt load address
64 die "Bogus alt-load address"
65 if (length($ala) < 3 || index($ala, "0x") != 0);
67 my $linkscript = $ENV{"L4_LDS_stat_bin"};
69 my $cmdadd = " -static -Wl,--defsym=__executable_start=$ala -Wl,-T$linkscript";
71 # Add the rest of the parameters
72 foreach my $n (1 .. $#ARGV) {
73 $cmdline = "$cmdline $ARGV[$n]";
78 print "link_tool_exe_l4re: $cmdline\n";
81 # Execute the command:
82 my $r = system("$cmdline");