From 197f30ec9abbfc29d60a5238037f6f2e4f04228c Mon Sep 17 00:00:00 2001 From: Joakim Date: Sun, 31 Jan 2016 13:41:59 +0530 Subject: [PATCH 1/2] Replace all uses of predefined version Android with CRuntime_Bionic or linux, and use CRuntime_Glibc where appropriate. --- src/core/sys/posix/arpa/inet.d | 4 ++-- src/core/sys/posix/grp.d | 4 ++-- src/core/sys/posix/netinet/in_.d | 4 ++-- src/core/sys/posix/netinet/tcp.d | 4 ++-- src/core/sys/posix/pthread.d | 4 ++-- src/core/sys/posix/sched.d | 4 ++-- src/core/sys/posix/semaphore.d | 4 ++-- src/core/sys/posix/signal.d | 4 ++-- src/core/sys/posix/stdlib.d | 4 ++-- src/core/sys/posix/sys/mman.d | 8 ++++---- src/core/sys/posix/time.d | 4 ++-- src/core/sys/posix/unistd.d | 4 ++-- src/core/sys/posix/utime.d | 4 ++-- 13 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/core/sys/posix/arpa/inet.d b/src/core/sys/posix/arpa/inet.d index 394dc5c532..6763df249b 100644 --- a/src/core/sys/posix/arpa/inet.d +++ b/src/core/sys/posix/arpa/inet.d @@ -199,7 +199,7 @@ NOTE: The following must must be defined in core.sys.posix.arpa.inet to break INET6_ADDRSTRLEN // from core.sys.posix.netinet.in_ */ -version( linux ) +version( CRuntime_Glibc ) { enum INET6_ADDRSTRLEN = 46; } @@ -215,7 +215,7 @@ else version( Solaris ) { enum INET6_ADDRSTRLEN = 46; } -else version( Android ) +else version( CRuntime_Bionic ) { enum INET6_ADDRSTRLEN = 46; } diff --git a/src/core/sys/posix/grp.d b/src/core/sys/posix/grp.d index d96e292499..d930242775 100644 --- a/src/core/sys/posix/grp.d +++ b/src/core/sys/posix/grp.d @@ -38,7 +38,7 @@ group* getgrnam(in char*); group* getgrgid(gid_t); */ -version( linux ) +version( CRuntime_Glibc ) { struct group { @@ -78,7 +78,7 @@ else version( Solaris ) char** gr_mem; } } -else version( Android ) +else version( CRuntime_Bionic ) { struct group { diff --git a/src/core/sys/posix/netinet/in_.d b/src/core/sys/posix/netinet/in_.d index 330244c5ff..b8d54f15ba 100644 --- a/src/core/sys/posix/netinet/in_.d +++ b/src/core/sys/posix/netinet/in_.d @@ -976,7 +976,7 @@ else version( CRuntime_Bionic ) IPPROTO_RAW */ -version( linux ) +version( CRuntime_Glibc ) { enum uint IPPROTO_RAW = 255; } @@ -992,7 +992,7 @@ else version( Solaris ) { enum uint IPPROTO_RAW = 255; } -else version( Android ) +else version( linux ) { enum uint IPPROTO_RAW = 255; } diff --git a/src/core/sys/posix/netinet/tcp.d b/src/core/sys/posix/netinet/tcp.d index 13a9ee8dca..5c40915f45 100644 --- a/src/core/sys/posix/netinet/tcp.d +++ b/src/core/sys/posix/netinet/tcp.d @@ -26,7 +26,7 @@ extern (C): TCP_NODELAY */ -version( linux ) +version( CRuntime_Glibc ) { enum TCP_NODELAY = 1; } @@ -42,7 +42,7 @@ else version( Solaris ) { enum TCP_NODELAY = 1; } -else version( Android ) +else version( linux ) { enum TCP_NODELAY = 1; } diff --git a/src/core/sys/posix/pthread.d b/src/core/sys/posix/pthread.d index 3a9e7e9c21..074bd5cca9 100644 --- a/src/core/sys/posix/pthread.d +++ b/src/core/sys/posix/pthread.d @@ -988,7 +988,7 @@ int pthread_rwlockattr_getpshared(in pthread_rwlockattr_t*, int*); int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int); */ -version (linux) +version (CRuntime_Glibc) { int pthread_condattr_getpshared(in pthread_condattr_t*, int*); int pthread_condattr_setpshared(pthread_condattr_t*, int); @@ -1024,7 +1024,7 @@ else version (Solaris) int pthread_rwlockattr_getpshared(in pthread_rwlockattr_t*, int*); int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int); } -else version (Android) +else version (CRuntime_Bionic) { int pthread_condattr_getpshared(pthread_condattr_t*, int*); int pthread_condattr_setpshared(pthread_condattr_t*, int); diff --git a/src/core/sys/posix/sched.d b/src/core/sys/posix/sched.d index 3a2309aa7a..4d7639d4da 100644 --- a/src/core/sys/posix/sched.d +++ b/src/core/sys/posix/sched.d @@ -132,7 +132,7 @@ int sched_setscheduler(pid_t, int, in sched_param*); int sched_yield(); */ -version( linux ) +version( CRuntime_Glibc ) { int sched_yield(); } @@ -148,7 +148,7 @@ else version (Solaris) { int sched_yield(); } -else version (Android) +else version (CRuntime_Bionic) { int sched_yield(); } diff --git a/src/core/sys/posix/semaphore.d b/src/core/sys/posix/semaphore.d index b9bf5fb15b..2ce8f30f2c 100644 --- a/src/core/sys/posix/semaphore.d +++ b/src/core/sys/posix/semaphore.d @@ -125,7 +125,7 @@ int sem_wait(sem_t*); int sem_timedwait(sem_t*, in timespec*); */ -version( linux ) +version( CRuntime_Glibc ) { int sem_timedwait(sem_t*, in timespec*); } @@ -141,7 +141,7 @@ else version (Solaris) { int sem_timedwait(sem_t*, in timespec*); } -else version( Android ) +else version( CRuntime_Bionic ) { int sem_timedwait(sem_t*, in timespec*); } diff --git a/src/core/sys/posix/signal.d b/src/core/sys/posix/signal.d index aea2143e94..bdd66ce3be 100644 --- a/src/core/sys/posix/signal.d +++ b/src/core/sys/posix/signal.d @@ -2112,7 +2112,7 @@ int pthread_kill(pthread_t, int); int pthread_sigmask(int, in sigset_t*, sigset_t*); */ -version( linux ) +version( CRuntime_Glibc ) { int pthread_kill(pthread_t, int); int pthread_sigmask(int, in sigset_t*, sigset_t*); @@ -2132,7 +2132,7 @@ else version (Solaris) int pthread_kill(pthread_t, int); int pthread_sigmask(int, in sigset_t*, sigset_t*); } -else version( Android ) +else version( CRuntime_Bionic ) { int pthread_kill(pthread_t, int); int pthread_sigmask(int, in sigset_t*, sigset_t*); diff --git a/src/core/sys/posix/stdlib.d b/src/core/sys/posix/stdlib.d index 0ba223b7c6..189cef6dd1 100644 --- a/src/core/sys/posix/stdlib.d +++ b/src/core/sys/posix/stdlib.d @@ -104,7 +104,7 @@ int setenv(in char*, in char*, int); int unsetenv(in char*); */ -version( linux ) +version( CRuntime_Glibc ) { int setenv(in char*, in char*, int); int unsetenv(in char*); @@ -125,7 +125,7 @@ else version( FreeBSD ) void* valloc(size_t); // LEGACY non-standard } -else version( Android ) +else version( CRuntime_Bionic ) { int setenv(in char*, in char*, int); int unsetenv(in char*); diff --git a/src/core/sys/posix/sys/mman.d b/src/core/sys/posix/sys/mman.d index 783919da18..94a84eebcc 100644 --- a/src/core/sys/posix/sys/mman.d +++ b/src/core/sys/posix/sys/mman.d @@ -97,7 +97,7 @@ PROT_EXEC PROT_NONE */ -version( linux ) +version( CRuntime_Glibc ) { enum PROT_NONE = 0x0; enum PROT_READ = 0x1; @@ -125,7 +125,7 @@ else version (Solaris) enum PROT_WRITE = 0x02; enum PROT_EXEC = 0x04; } -else version (Android) +else version (CRuntime_Bionic) { enum PROT_NONE = 0x00; enum PROT_READ = 0x01; @@ -458,7 +458,7 @@ int mlock(in void*, size_t); int munlock(in void*, size_t); */ -version( linux ) +version( CRuntime_Glibc ) { int mlock(in void*, size_t); int munlock(in void*, size_t); @@ -478,7 +478,7 @@ else version (Solaris) int mlock(in void*, size_t); int munlock(in void*, size_t); } -else version (Android) +else version (CRuntime_Bionic) { int mlock(in void*, size_t); int munlock(in void*, size_t); diff --git a/src/core/sys/posix/time.d b/src/core/sys/posix/time.d index 41fa358a62..bd54f610fe 100644 --- a/src/core/sys/posix/time.d +++ b/src/core/sys/posix/time.d @@ -317,7 +317,7 @@ tm* gmtime_r(in time_t*, tm*); tm* localtime_r(in time_t*, tm*); */ -version( linux ) +version( CRuntime_Glibc ) { char* asctime_r(in tm*, char*); char* ctime_r(in time_t*, char*); @@ -345,7 +345,7 @@ else version (Solaris) tm* gmtime_r(in time_t*, tm*); tm* localtime_r(in time_t*, tm*); } -else version (Android) +else version (CRuntime_Bionic) { char* asctime_r(in tm*, char*); char* ctime_r(in time_t*, char*); diff --git a/src/core/sys/posix/unistd.d b/src/core/sys/posix/unistd.d index 98e4a6e9cc..221c1c10e6 100644 --- a/src/core/sys/posix/unistd.d +++ b/src/core/sys/posix/unistd.d @@ -1094,7 +1094,7 @@ else version( Solaris ) int fsync(int); */ -version( linux ) +version( CRuntime_Glibc ) { int fsync(int) @trusted; } @@ -1106,7 +1106,7 @@ else version( FreeBSD ) { int fsync(int) @trusted; } -else version( Android ) +else version( CRuntime_Bionic ) { int fsync(int) @trusted; } diff --git a/src/core/sys/posix/utime.d b/src/core/sys/posix/utime.d index 441ec5d66e..7a05d415a5 100644 --- a/src/core/sys/posix/utime.d +++ b/src/core/sys/posix/utime.d @@ -35,7 +35,7 @@ struct utimbuf int utime(in char*, in utimbuf*); */ -version( linux ) +version( CRuntime_Glibc ) { struct utimbuf { @@ -75,7 +75,7 @@ else version( Solaris ) int utime(in char*, in utimbuf*); } -else version( Android ) +else version( CRuntime_Bionic ) { struct utimbuf { From 054a95192afe5e880cb6987db69fc16abf645566 Mon Sep 17 00:00:00 2001 From: Joakim Date: Sun, 31 Jan 2016 13:49:12 +0530 Subject: [PATCH 2/2] For Android, pull in some functions and constants from bionic, exclude some Glibc definitions, and add __tls_get_addr for ARM. --- src/core/stdc/math.d | 6 +++-- src/core/sys/linux/config.d | 3 +++ src/core/sys/posix/netinet/in_.d | 1 + src/core/sys/posix/signal.d | 2 +- src/rt/backtrace/dwarf.d | 2 +- src/rt/sections_android.d | 38 +++++++++++++++++++++++--------- 6 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/core/stdc/math.d b/src/core/stdc/math.d index 9908749359..f8bdb95f57 100644 --- a/src/core/stdc/math.d +++ b/src/core/stdc/math.d @@ -1967,7 +1967,8 @@ else version(CRuntime_Bionic) double ldexp(double x, int exp); /// float ldexpf(float x, int exp); - // alias for double: real ldexpl(real x, int exp); + /// + real ldexpl(real x, int exp); /// double log(double x); @@ -2009,7 +2010,8 @@ else version(CRuntime_Bionic) double scalbn(double x, int n); /// float scalbnf(float x, int n); - // alias for double: real scalbnl(real x, int n); + /// + real scalbnl(real x, int n); /// double scalbln(double x, c_long n); diff --git a/src/core/sys/linux/config.d b/src/core/sys/linux/config.d index 3e04009cf7..e867ecaf3b 100644 --- a/src/core/sys/linux/config.d +++ b/src/core/sys/linux/config.d @@ -23,3 +23,6 @@ enum __USE_BSD = _BSD_SOURCE; enum __USE_SVID = _SVID_SOURCE; enum __USE_ATFILE = _ATFILE_SOURCE; enum __USE_GNU = _GNU_SOURCE; + +// Available in bionic from API 21 +version(CRuntime_Bionic) enum __WORDSIZE = 32; diff --git a/src/core/sys/posix/netinet/in_.d b/src/core/sys/posix/netinet/in_.d index b8d54f15ba..e145eb8a4c 100644 --- a/src/core/sys/posix/netinet/in_.d +++ b/src/core/sys/posix/netinet/in_.d @@ -265,6 +265,7 @@ else version( linux ) { INADDR_ANY = 0x00000000, INADDR_BROADCAST = 0xffffffff, + INADDR_LOOPBACK = 0x7f000001, INADDR_NONE = 0xFFFFFFFF } } diff --git a/src/core/sys/posix/signal.d b/src/core/sys/posix/signal.d index bdd66ce3be..4495c77d53 100644 --- a/src/core/sys/posix/signal.d +++ b/src/core/sys/posix/signal.d @@ -125,7 +125,7 @@ version( Solaris ) return sig; } } -else version( linux ) +else version( CRuntime_Glibc ) { private extern (C) nothrow @nogc { diff --git a/src/rt/backtrace/dwarf.d b/src/rt/backtrace/dwarf.d index 3bbbbb071c..11074faeb6 100644 --- a/src/rt/backtrace/dwarf.d +++ b/src/rt/backtrace/dwarf.d @@ -12,7 +12,7 @@ module rt.backtrace.dwarf; -version(linux) version = linux_or_freebsd; +version(CRuntime_Glibc) version = linux_or_freebsd; else version(FreeBSD) version = linux_or_freebsd; version(linux_or_freebsd): diff --git a/src/rt/sections_android.d b/src/rt/sections_android.d index 2c76fe59cc..090a95ab18 100644 --- a/src/rt/sections_android.d +++ b/src/rt/sections_android.d @@ -67,8 +67,8 @@ void initSections() auto mend = cast(immutable ModuleInfo**)&__stop_minfo; _sections.moduleGroup = ModuleGroup(mbeg[0 .. mend - mbeg]); - auto pbeg = cast(void*)&etext; - auto pend = cast(void*)&_end; + auto pbeg = cast(void*)&_tls_end; + auto pend = cast(void*)&__bss_end__; _sections._gcRanges[0] = pbeg[0 .. pend - pbeg]; } @@ -105,15 +105,32 @@ void scanTLSRanges(void[]* rng, scope void delegate(void* pbeg, void* pend) noth * the corresponding address in the TLS dynamic per-thread data. */ -// NB: the compiler mangles this function as '___tls_get_addr' even though it is extern(D) -extern(D) void* ___tls_get_addr( void* p ) +version(X86) { - debug(PRINTF) printf(" ___tls_get_addr input - %p\n", p); - immutable offset = cast(size_t)(p - cast(void*)&_tlsstart); - auto tls = getTLSBlockAlloc(); - assert(offset < tls.length); - return tls.ptr + offset; + // NB: the compiler mangles this function as '___tls_get_addr' + // even though it is extern(D) + extern(D) void* ___tls_get_addr( void* p ) + { + debug(PRINTF) printf(" ___tls_get_addr input - %p\n", p); + immutable offset = cast(size_t)(p - cast(void*)&_tlsstart); + auto tls = getTLSBlockAlloc(); + assert(offset < tls.length); + return tls.ptr + offset; + } +} +else version(ARM) +{ + extern(C) void* __tls_get_addr( void** p ) + { + debug(PRINTF) printf(" __tls_get_addr input - %p\n", *p); + immutable offset = cast(size_t)(*p - cast(void*)&_tlsstart); + auto tls = getTLSBlockAlloc(); + assert(offset < tls.length); + return tls.ptr + offset; + } } +else + static assert( false, "Android architecture not supported." ); private: @@ -163,8 +180,7 @@ extern(C) void* __start_minfo; void* __stop_minfo; - size_t etext; - size_t _end; + size_t __bss_end__; void* _tlsstart; void* _tlsend;