add-64-bit-flag-for-ELF64-entries.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. From 9d62544090b08849218cd1fc52a36cdd5d90363e Mon Sep 17 00:00:00 2001
  2. From: Yuanjie Huang <yuanjie.huang@windriver.com>
  3. Date: Fri, 24 Apr 2015 03:29:31 +0000
  4. Subject: [PATCH] Add 64-bit flag for ELF64 entries.
  5. ldconfig-native was grepped from an old version of glibc, and its output
  6. lacks neccessary 64bit flag in entries.
  7. Due to this defect, ctypes.util.find_library() python function fails to
  8. detect any library due to the old file format that ldconfig-native
  9. creates. This fix sets architecture-dependent 64bit flags for 64-bit ELF.
  10. Upstream-Status: Inappropriate [embedded specific]
  11. Signed-off-by: Yuanjie Huang <yuanjie.huang@windriver.com>
  12. ---
  13. cache.c | 4 ++++
  14. ldconfig.h | 4 ++++
  15. readelflib.c | 34 ++++++++++++++++++++++++++++++++++
  16. 3 files changed, 42 insertions(+)
  17. diff --git a/cache.c b/cache.c
  18. index a904d44..c4f5411 100644
  19. --- a/cache.c
  20. +++ b/cache.c
  21. @@ -121,6 +121,10 @@ print_entry (const char *lib, int flag, unsigned int osversion,
  22. break;
  23. case FLAG_MIPS64_LIBN64:
  24. fputs (",64bit", stdout);
  25. + break;
  26. + case FLAG_AARCH64_LIB64:
  27. + fputs (",AArch64", stdout);
  28. + break;
  29. case 0:
  30. break;
  31. default:
  32. diff --git a/ldconfig.h b/ldconfig.h
  33. index fadd5ec..6a8a750 100644
  34. --- a/ldconfig.h
  35. +++ b/ldconfig.h
  36. @@ -34,6 +34,10 @@
  37. #define FLAG_POWERPC_LIB64 0x0500
  38. #define FLAG_MIPS64_LIBN32 0x0600
  39. #define FLAG_MIPS64_LIBN64 0x0700
  40. +#define FLAG_X8664_LIBX32 0x0800
  41. +#define FLAG_ARM_LIBHF 0x0900
  42. +#define FLAG_AARCH64_LIB64 0x0a00
  43. +#define FLAG_ARM_LIBSF 0x0b00
  44. /* Name of auxiliary cache. */
  45. #define _PATH_LDCONFIG_AUX_CACHE "/var/cache/ldconfig/aux-cache"
  46. diff --git a/readelflib.c b/readelflib.c
  47. index 0bf0de3..6e87afc 100644
  48. --- a/readelflib.c
  49. +++ b/readelflib.c
  50. @@ -28,6 +28,11 @@
  51. #include "endian_extra.h"
  52. +/* Work-around for old host that does not have AArch64 defined in elf.h. */
  53. +#ifndef EM_AARCH64
  54. +#define EM_AARCH64 183 /* ARM AARCH64 */
  55. +#endif
  56. +
  57. #undef check_ptr
  58. #define check_ptr(ptr) \
  59. do \
  60. @@ -290,6 +295,48 @@ process_elf_file64 (const char *file_name, const char *lib, int *flag,
  61. libc5/libc6. */
  62. *flag = FLAG_ELF;
  63. + /* Set flags according to information in ELF header to align with target
  64. + ldconfig */
  65. + switch (elf_header->e_machine)
  66. + {
  67. + case EM_IA_64:
  68. + /* Intel 64bit libraries are always libc.so.6+. */
  69. + /* see sysdeps/unix/sysv/linux/ia64/readelflib.c */
  70. + *flag |= FLAG_IA64_LIB64|FLAG_ELF_LIBC6;
  71. + break;
  72. + case EM_X86_64:
  73. + /* X86-64 64bit libraries are always libc.so.6+. */
  74. + /* see sysdeps/unix/sysv/linux/i386/readelflib.c */
  75. + *flag |= FLAG_X8664_LIB64|FLAG_ELF_LIBC6;
  76. + break;
  77. + case EM_S390:
  78. + /* S/390 64bit libraries are always libc.so.6+. */
  79. + /* see sysdeps/unix/sysv/linux/s390/readelflib.c */
  80. + *flag |= FLAG_S390_LIB64|FLAG_ELF_LIBC6;
  81. + break;
  82. + case EM_PPC64:
  83. + /* PowerPC 64bit libraries are always libc.so.6+. */
  84. + /* see sysdeps/unix/sysv/linux/powerpc/readelflib.c */
  85. + *flag |= FLAG_POWERPC_LIB64|FLAG_ELF_LIBC6;
  86. + break;
  87. + case EM_MIPS:
  88. + case EM_MIPS_RS3_LE:
  89. + /* n64 libraries are always libc.so.6+. */
  90. + /* NOTE: This does not correctly distinguish NAN2008 binaries and is possibly broken */
  91. + /* see sysdeps/unix/sysv/linux/mips/readelflib.c */
  92. + *flag |= FLAG_MIPS64_LIBN64|FLAG_ELF_LIBC6;
  93. + break;
  94. + case EM_AARCH64:
  95. + /* AArch64 libraries are always libc.so.6+. */
  96. + /* see sysdeps/unix/sysv/linux/arm/readelflib.c */
  97. + *flag |= FLAG_AARCH64_LIB64|FLAG_ELF_LIBC6;
  98. + break;
  99. + default:
  100. + error(0, 0, "%s is a 64-bit ELF for unknown machine %lx\n",
  101. + file_name, (long)elf_header->e_machine);
  102. + break;
  103. + }
  104. +
  105. loadaddr = -1;
  106. dynamic_addr = 0;
  107. dynamic_size = 0;
  108. --