From a6e4ee919ae3259692833d24ef8ed02b462d7bb1 Mon Sep 17 00:00:00 2001
From: Ivan Maidanski <ivmai@mail.ru>
Date: Sat, 9 Nov 2013 11:56:35 +0400
Subject: [PATCH] Fix dyn_load.c compilation for Android 4.3

* dyn_load.c (struct link_map, r_debug): Define explicitly (matching
that of Android 4.2 Bionic) instead of include linker.h (only if
PLATFORM_ANDROID); remove workaround enabled by
BIONIC_ELFDATA_REDEF_BUG regarding ELF_DATA redefinition (as linker.h
is not included); update comment.
---
 dyn_load.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/dyn_load.c b/dyn_load.c
index 215967e9..866d73f6 100644
--- a/dyn_load.c
+++ b/dyn_load.c
@@ -96,22 +96,27 @@ STATIC GC_has_static_roots_func GC_has_static_roots = 0;
     /* Exclude Android because linker.h below includes its own version. */
 #   include <elf.h>
 # endif
-# ifdef PLATFORM_ANDROID
-    /* The header file is in "bionic/linker" folder of Android sources. */
+# include <link.h>
+# if defined(PLATFORM_ANDROID) && !defined(GC_DONT_DEFINE_LINK_MAP)
     /* If you don't need the "dynamic loading" feature, you may build   */
     /* the collector with -D IGNORE_DYNAMIC_LOADING.                    */
-#   ifdef BIONIC_ELFDATA_REDEF_BUG
-      /* Workaround a problem in Android 4.1 (and 4.2) Bionic which has */
-      /* mismatching ELF_DATA definitions in sys/exec_elf.h and         */
-      /* asm/elf.h included from linker.h file (similar to EM_ALPHA).   */
-#     include <asm/elf.h>
-#     include <linux/elf-em.h>
-#     undef ELF_DATA
-#     undef EM_ALPHA
-#   endif
-#   include <linker.h>
-# else
-#   include <link.h>
+    /* Otherwise, link_map and r_debug should be defined explicitly,    */
+    /* as only bionic/linker/linker.h defines them but the header       */
+    /* itself is a C++ one starting from Android 4.3.                   */
+    struct link_map {
+      uintptr_t l_addr;
+      char* l_name;
+      uintptr_t l_ld;
+      struct link_map* l_next;
+      struct link_map* l_prev;
+    };
+    struct r_debug {
+      int32_t r_version;
+      struct link_map* r_map;
+      void (*r_brk)(void);
+      int32_t r_state;
+      uintptr_t r_ldbase;
+    };
 # endif
 #endif
 
-- 
2.40.0