summaryrefslogtreecommitdiff
path: root/debian/patches/dyson-ld_altexec.patch
blob: 7b3ed751d73ad291fbbafa74f4acd2bd6cf921a9 (plain)
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
Index: binutils.git/ld/ldmain.c
===================================================================
--- binutils.git.orig/ld/ldmain.c
+++ binutils.git/ld/ldmain.c
@@ -49,6 +49,7 @@
 #endif
 
 #include <string.h>
+#include <errno.h>
 
 #ifndef TARGET_SYSTEM_ROOT
 #define TARGET_SYSTEM_ROOT ""
@@ -187,9 +188,35 @@ ld_bfd_error_handler (const char *fmt, v
   (*default_bfd_error_handler) (fmt, ap);
 }
 
+static void
+maybe_altexec(char **argv)
+{
+  char *LD_ALTEXEC;
+
+  /* If LD_ALTEXEC is not set or is empty, just return */
+  LD_ALTEXEC = getenv("LD_ALTEXEC");
+  if (LD_ALTEXEC == NULL)
+    return;
+
+  if (*LD_ALTEXEC == '\0')
+    return;
+
+  /* Unset LD_ALTEXEC for case when it points to this program itself ;-) */
+  if (unsetenv("LD_ALTEXEC"))
+    exit(errno);
+
+  argv[0] = LD_ALTEXEC;
+  execvp(LD_ALTEXEC, argv);
+
+  /* We are here only if execvp() failed */
+  exit(errno);
+}
+
 int
 main (int argc, char **argv)
 {
+  maybe_altexec(argv);
+
   char *emulation;
   long start_time = get_run_time ();
 
Index: binutils.git/ld/ld.info
===================================================================
--- binutils.git.orig/ld/ld.info
+++ binutils.git/ld/ld.info
@@ -2546,7 +2546,7 @@ File: ld.info,  Node: Environment,  Prev
 =========================
 
 You can change the behaviour of 'ld' with the environment variables
-'GNUTARGET', 'LDEMULATION' and 'COLLECT_NO_DEMANGLE'.
+'GNUTARGET', 'LDEMULATION', 'COLLECT_NO_DEMANGLE', and 'LD_ALTEXEC'.
 
    'GNUTARGET' determines the input-file object format if you don't use
 '-b' (or its synonym '--format').  Its value should be one of the BFD
@@ -2574,6 +2574,11 @@ not demangling symbols.  This environmen
 fashion by the 'gcc' linker wrapper program.  The default may be
 overridden by the '--demangle' and '--no-demangle' options.
 
+   'LD_ALTEXEC' sets alternative linker. The linker executes,
+and passes control to this alternative linker. For instance one
+can set 'LD_ALTEXEC=echo' to debug linker command line.
+
+
 
 File: ld.info,  Node: Scripts,  Next: Machine Dependent,  Prev: Invocation,  Up: Top