0001-ld-elf2flt-behave-properly-when-called-with-a-name-d.patch 3.2 KB

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