Index: binutils.git/ld/ldmain.c =================================================================== --- binutils.git.orig/ld/ldmain.c +++ binutils.git/ld/ldmain.c @@ -49,6 +49,7 @@ #endif #include +#include #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