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