engine: platform: android: move dlsym-weak hack from C++ to C

This commit is contained in:
Alibek Omarov 2025-01-30 17:49:39 +03:00
parent faf0b32a94
commit f076d84975
2 changed files with 11 additions and 22 deletions

View file

@ -32,7 +32,7 @@
#include <android/log.h> #include <android/log.h>
#include "linker.h" #include "linker.h"
static const Elf_Sym *soinfo_elf_lookup( const soinfo *si, unsigned hash, const char *name ) static const Elf_Sym *soinfo_elf_lookup( const struct soinfo *si, unsigned hash, const char *name )
{ {
const Elf_Sym *symtab = si->symtab; const Elf_Sym *symtab = si->symtab;
const char *strtab = si->strtab; const char *strtab = si->strtab;
@ -87,14 +87,14 @@ static unsigned elfhash( const unsigned char *name )
Binary Interface) where in Chapter 5 it discuss resolving "Shared Binary Interface) where in Chapter 5 it discuss resolving "Shared
Object Dependencies" in breadth first search order. Object Dependencies" in breadth first search order.
*/ */
static const Elf_Sym *dlsym_handle_lookup( const soinfo *si, const char *name ) static const Elf_Sym *dlsym_handle_lookup( const struct soinfo *si, const char *name )
{ {
return soinfo_elf_lookup( si, elfhash((const unsigned char *)name ), name ); return soinfo_elf_lookup( si, elfhash((const unsigned char *)name ), name );
} }
extern "C" void *dlsym_weak( void *handle, const char *symbol ) void *dlsym_weak( void *handle, const char *symbol )
{ {
const soinfo *found = (soinfo *)handle; const struct soinfo *found = (struct soinfo *)handle;
const Elf_Sym *sym = dlsym_handle_lookup( found, symbol ); const Elf_Sym *sym = dlsym_handle_lookup( found, symbol );
if( sym != NULL ) if( sym != NULL )

View file

@ -31,10 +31,8 @@
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
// #include <elf.h> #include <stdbool.h>
#include <linux/elf.h> #include <linux/elf.h>
// #include <sys/exec_elf.h>
// #include <link.h>
// a1ba: we don't really need custom linker on Android 64, because // a1ba: we don't really need custom linker on Android 64, because
// it's only intended to workaround bug which persist on Android < 4.4 // it's only intended to workaround bug which persist on Android < 4.4
@ -69,8 +67,8 @@ struct link_map_t {
uintptr_t l_addr; uintptr_t l_addr;
char *l_name; char *l_name;
uintptr_t l_ld; uintptr_t l_ld;
link_map_t *l_next; struct link_map_t *l_next;
link_map_t *l_prev; struct link_map_t *l_prev;
}; };
// Values for r_debug->state // Values for r_debug->state
@ -85,7 +83,7 @@ enum {
#define SOINFO_NAME_LEN 128 #define SOINFO_NAME_LEN 128
typedef void (*linker_function_t)(); typedef void (*linker_function_t)( void );
// Android uses REL for 32-bit but only uses RELA for 64-bit. // Android uses REL for 32-bit but only uses RELA for 64-bit.
#if defined( __LP64__ ) #if defined( __LP64__ )
@ -93,7 +91,6 @@ typedef void (*linker_function_t)();
#endif #endif
struct soinfo { struct soinfo {
public:
char name[SOINFO_NAME_LEN]; char name[SOINFO_NAME_LEN];
const Elf_Phdr *phdr; const Elf_Phdr *phdr;
size_t phnum; size_t phnum;
@ -112,7 +109,7 @@ public:
uint32_t unused3; // DO NOT USE, maintained for compatibility uint32_t unused3; // DO NOT USE, maintained for compatibility
#endif #endif
soinfo *next; struct soinfo *next;
unsigned flags; unsigned flags;
const char *strtab; const char *strtab;
@ -165,7 +162,7 @@ public:
#endif #endif
size_t ref_count; size_t ref_count;
link_map_t link_map; struct link_map_t link_map;
bool constructors_called; bool constructors_called;
@ -177,14 +174,6 @@ public:
bool has_text_relocations; bool has_text_relocations;
#endif #endif
bool has_DT_SYMBOLIC; bool has_DT_SYMBOLIC;
void CallConstructors();
void CallDestructors();
void CallPreInitConstructors();
private:
void CallArray( const char *array_name, linker_function_t *functions, size_t count, bool reverse );
void CallFunction( const char *function_name, linker_function_t function );
}; };
#endif #endif