1*4882a593SmuzhiyunFrom b31e9b1bff6832063816b972395179859d1d4619 Mon Sep 17 00:00:00 2001 2*4882a593SmuzhiyunFrom: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> 3*4882a593SmuzhiyunDate: Sun, 13 Aug 2017 16:03:20 +0200 4*4882a593SmuzhiyunSubject: [PATCH] ld-elf2flt: behave properly when called with a name different 5*4882a593Smuzhiyun from TARGET_ALIAS 6*4882a593Smuzhiyun 7*4882a593Smuzhiyunld-elf2flt currently handles two cases: 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun 1 It is called as the wrapper for <TARGET_ALIAS>-ld, generally 10*4882a593Smuzhiyun installed in the bin/ directory of a toolchain. 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun 2 It is called as the wrapper for "ld", generally installed in the 13*4882a593Smuzhiyun TARGET_ALIAS/bin/ directory of a toolchain. 14*4882a593Smuzhiyun 15*4882a593SmuzhiyunUnfortunately, if for some reason it gets called using a FOOBAR-ld 16*4882a593Smuzhiyunname that is different from <TARGET_ALIAS>-ld, it assumes it is in 17*4882a593Smuzhiyuncase (2), while it really is in case (1). Due to this, the path 18*4882a593Smuzhiyunmangling logic doesn't work, and it doesn't find ld.real. 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunThis happens for example when the binary program in bin/ is named 21*4882a593Smuzhiyunarm-buildroot-uclinux-uclibcgnueabi-ld, but also has a simpler symlink 22*4882a593Smuzhiyunnamed arm-linux-ld. In this case, 23*4882a593Smuzhiyunarm-buildroot-uclinux-uclibcgnueabi-ld is recognized by ld-elf2flt as 24*4882a593Smuzhiyuncontaining TARGET_ALIAS, and therefore the proper logic to find 25*4882a593Smuzhiyunld.real is applied. However, when arm-linux-ld is used, ld-elf2flt 26*4882a593Smuzhiyundoesn't find TARGET_ALIAS, and therefore assumes we're being called as 27*4882a593SmuzhiyunTARGET_ALIAS/bin/ld.. and searches for a program called ld.real in 28*4882a593Smuzhiyunbin/, which doesn't exist. 29*4882a593Smuzhiyun 30*4882a593SmuzhiyunSee: 31*4882a593Smuzhiyun 32*4882a593Smuzhiyun$ ./output/host/bin/arm-buildroot-uclinux-uclibcgnueabi-ld 33*4882a593Smuzhiyun/home/thomas/buildroot/buildroot/output/host/bin/../arm-buildroot-uclinux-uclibcgnueabi/bin/ld.real: no input files 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun$ ./output/host/bin/arm-linux-ld 36*4882a593Smuzhiyunarm-linux-ld (ld-elf2flt): error trying to exec '/home/thomas/buildroot/buildroot/output/host/bin/ld.real': execvp: No such file or directory 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun$ ./output/host/arm-buildroot-uclinux-uclibcgnueabi/bin/ld 39*4882a593Smuzhiyun/home/thomas/buildroot/buildroot/output/host/arm-buildroot-uclinux-uclibcgnueabi/bin/ld.real: no input files 40*4882a593Smuzhiyun 41*4882a593SmuzhiyunThis commit fixes that by inverting the logic: if we're being called 42*4882a593Smuzhiyunas just "ld", then we assume it's the program in 43*4882a593SmuzhiyunTARGET_ALIAS/bin/. Otherwise, we're called through some variant of 44*4882a593SmuzhiyunTARGET-ld. 45*4882a593Smuzhiyun 46*4882a593SmuzhiyunSigned-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> 47*4882a593SmuzhiyunSubmitted-upstream: https://github.com/uclinux-dev/elf2flt/pull/8 48*4882a593Smuzhiyun--- 49*4882a593Smuzhiyun ld-elf2flt.c | 10 +++++----- 50*4882a593Smuzhiyun 1 file changed, 5 insertions(+), 5 deletions(-) 51*4882a593Smuzhiyun 52*4882a593Smuzhiyundiff --git a/ld-elf2flt.c b/ld-elf2flt.c 53*4882a593Smuzhiyunindex de39fe0..c187c2e 100644 54*4882a593Smuzhiyun--- a/ld-elf2flt.c 55*4882a593Smuzhiyun+++ b/ld-elf2flt.c 56*4882a593Smuzhiyun@@ -506,15 +506,15 @@ int main(int argc, char *argv[]) 57*4882a593Smuzhiyun the host while those in <TARGET_ALIAS>/lib are for the target. 58*4882a593Smuzhiyun Make bindir point to the bin dir for bin/<TARGET_ALIAS>-foo. 59*4882a593Smuzhiyun Make tooldir point to the bin dir for <TARGET_ALIAS>/bin/foo. */ 60*4882a593Smuzhiyun- if (streqn(elf2flt_progname, TARGET_ALIAS)) { 61*4882a593Smuzhiyun- tmp = concat(argv0_dir, "../" TARGET_ALIAS "/bin", NULL); 62*4882a593Smuzhiyun+ if (streqn(elf2flt_progname, "ld")) { 63*4882a593Smuzhiyun+ tmp = concat(argv0_dir, "../../bin", NULL); 64*4882a593Smuzhiyun if (stat(tmp, &buf) == 0 && S_ISDIR(buf.st_mode)) { 65*4882a593Smuzhiyun- tooldir = concat(tmp, "/", NULL); 66*4882a593Smuzhiyun+ bindir = concat(tmp, "/", NULL); 67*4882a593Smuzhiyun } 68*4882a593Smuzhiyun } else { 69*4882a593Smuzhiyun- tmp = concat(argv0_dir, "../../bin", NULL); 70*4882a593Smuzhiyun+ tmp = concat(argv0_dir, "../" TARGET_ALIAS "/bin", NULL); 71*4882a593Smuzhiyun if (stat(tmp, &buf) == 0 && S_ISDIR(buf.st_mode)) { 72*4882a593Smuzhiyun- bindir = concat(tmp, "/", NULL); 73*4882a593Smuzhiyun+ tooldir = concat(tmp, "/", NULL); 74*4882a593Smuzhiyun } 75*4882a593Smuzhiyun } 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun-- 78*4882a593Smuzhiyun2.9.4 79*4882a593Smuzhiyun 80