From f2c5d2cf28d92c77a729054d12053f433fad9e1c Mon Sep 17 00:00:00 2001
From: Jari Vetoniemi <mailroxas@gmail.com>
Date: Thu, 19 Apr 2018 15:16:05 +0300
Subject: linker/libc: don't wrap variable symbols

This is why the bionic_file_to_glibc_file did not work with just
pointers. The input is actually pointer to our wrapper, doh.
---
 src/libc-stdio.h    | 9 +++------
 src/linker/linker.c | 4 +++-
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/libc-stdio.h b/src/libc-stdio.h
index 9e4f72a..9dacd21 100644
--- a/src/libc-stdio.h
+++ b/src/libc-stdio.h
@@ -21,14 +21,11 @@ const struct bionic___sFILE bionic___sF[3] = {
 static inline FILE*
 bionic_file_to_glibc_file(FILE *f)
 {
-   // Can't compare just memory addresses because GNU libstdc++ copies the FILE struct...
-   // Maybe there could be a cleaner solution, this may in practice break if standard streams
-   // are opened with different flags in C++.
-   if (memcmp(f, "stdin", sizeof("stdin")))
+   if (f == (void*)&bionic___sF[0])
       return stdin;
-   else if (memcmp(f, "stdout", sizeof("stdout")))
+   else if (f == (void*)&bionic___sF[1])
       return stdout;
-   else if (memcmp(f, "stderr", sizeof("stderr")))
+   else if (f == (void*)&bionic___sF[2])
       return stderr;
    return f;
 }
diff --git a/src/linker/linker.c b/src/linker/linker.c
index 12a3521..058baa5 100644
--- a/src/linker/linker.c
+++ b/src/linker/linker.c
@@ -1384,7 +1384,9 @@ static int apkenv_reloc_library(soinfo *si, Elf32_Rel *rel, unsigned count)
             }
             if(sym_addr != 0)
             {
-                sym_addr = (unsigned)wrapper_create(sym_name, (void*)sym_addr);
+                if(ELF32_ST_TYPE(((Elf32_Sym*)(intptr_t)sym_addr)->st_info) == STT_FUNC) {
+                    sym_addr = (unsigned)wrapper_create(sym_name, (void*)sym_addr);
+                }
             } else
             if(s == NULL) {
                 /* We only allow an undefined symbol if this is a weak
-- 
cgit v1.2.3-70-g09d2