Bug 439685 compiler warning in callgrind/main.c
[valgrind.git] / coregrind / link_tool_exe_freebsd.in
blobb4df4622c1bfb9c32f3643ee41610b69951761df
1 #! @PERL@
3 # This script handles linking the tool executables on FreeBSD,
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:
19 #   first arg
20 #      the alternative load address
21 #   all the rest of the args
22 #      the compiler invocation 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 # FreeBSD specific complications:
32 # - in the initial version of this file, the linker(s) it was targeted
33 #   at supported only -Ttext to load the code at an alternative address,
34 #   and did not require removing the build notes in order to function
35 #   correctly, so the work done by configure to determine what should go
36 #   into the FLAG_T_TEXT was ignored.
38 # - LLVM's ld.lld, for at least versions 8.0 (shipping with FreeBSD 12.1)
39 #   and 9.0 support the -Ttext option and behave as desired.  As of
40 #   LLVM ld.lld version 10.0 a breaking change made -Ttext unusable,
41 #   however the --image-base option has the desired semantics.
42 #   It turns out that ld.lld has supported --image-base since at least
43 #   as far back as version 8.0.
45 # So: what we actually do:
47 #   pass the specified command to the linker as-is, except, add
48 #   "-static" and the value of FLAG_T_TEXT as determined by configure.
49 #   Previously we did this by adding these options after the first
50 #   word of the rest of the arguments, which works in the common case
51 #   when it's something like "gcc". But the linker invocation itself
52 #   might be multiple words, say if it's "ccache gcc". So we now put
53 #   the new options at the end instead.
56 use warnings;
57 use strict;
59 # expect at least: alt-load-address gcc -o foo bar.o
60 die "Not enough arguments"
61     if (($#ARGV + 1) < 5);
63 my $ala = $ARGV[0];
64 shift; # Remove $ala from @ARGV
66 # check for plausible-ish alt load address
67 die "Bogus alt-load address"
68     if (length($ala) < 3 || index($ala, "0x") != 0);
70 my $cmd = join(" ", @ARGV, "-static -Wl,@FLAG_T_TEXT@=$ala");
72 #print "link_tool_exe_freebsd: $cmd\n";
75 # Execute the command:
76 my $r = system("$cmd");
78 if ($r == 0) {
79     exit 0;
80 } else {
81     exit 1;