2015-01-22 01:42:02 +01:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
#
|
|
|
|
# Copyright (C) 2015 The Android Open Source Project
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the 'License');
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an 'AS IS' BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
# pylint: disable=bad-indentation,bad-continuation
|
2014-05-16 23:44:38 +02:00
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
2015-01-22 01:42:02 +01:00
|
|
|
import symbols
|
|
|
|
|
2014-08-13 22:04:28 +02:00
|
|
|
only_unwanted = False
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
if sys.argv[1] in ('-u', '--unwanted'):
|
|
|
|
only_unwanted = True
|
|
|
|
|
2014-05-16 23:44:38 +02:00
|
|
|
toolchain = os.environ['ANDROID_TOOLCHAIN']
|
|
|
|
arch = re.sub(r'.*/linux-x86/([^/]+)/.*', r'\1', toolchain)
|
2014-08-13 22:04:28 +02:00
|
|
|
if arch == 'aarch64':
|
|
|
|
arch = 'arm64'
|
2014-05-16 23:44:38 +02:00
|
|
|
|
2014-06-13 20:50:07 +02:00
|
|
|
def MangleGlibcNameToBionic(name):
|
|
|
|
if name in glibc_to_bionic_names:
|
|
|
|
return glibc_to_bionic_names[name]
|
|
|
|
return name
|
|
|
|
|
2015-01-22 01:42:02 +01:00
|
|
|
def GetNdkIgnored(arch): # pylint: disable=redefined-outer-name
|
|
|
|
ignored_symbols = set()
|
2014-08-13 22:04:28 +02:00
|
|
|
files = glob.glob('%s/ndk/build/tools/unwanted-symbols/%s/*' %
|
|
|
|
(os.getenv('ANDROID_BUILD_TOP'), arch))
|
|
|
|
for f in files:
|
2015-01-22 01:42:02 +01:00
|
|
|
ignored_symbols |= set(open(f, 'r').read().splitlines())
|
|
|
|
return ignored_symbols
|
2014-08-13 22:04:28 +02:00
|
|
|
|
2014-06-13 20:50:07 +02:00
|
|
|
glibc_to_bionic_names = {
|
|
|
|
'__res_init': 'res_init',
|
|
|
|
'__res_mkquery': 'res_mkquery',
|
|
|
|
'__res_query': 'res_query',
|
|
|
|
'__res_search': 'res_search',
|
2014-08-21 20:36:07 +02:00
|
|
|
'__xpg_basename': '__gnu_basename',
|
2014-06-13 20:50:07 +02:00
|
|
|
}
|
|
|
|
|
2015-01-22 01:42:02 +01:00
|
|
|
glibc = symbols.GetFromSystemSo([
|
|
|
|
'libc.so.*',
|
|
|
|
'librt.so.*',
|
|
|
|
'libpthread.so.*',
|
|
|
|
'libresolv.so.*',
|
|
|
|
'libm.so.*',
|
|
|
|
'libutil.so.*',
|
|
|
|
])
|
|
|
|
|
|
|
|
bionic = symbols.GetFromAndroidSo(['libc.so', 'libm.so'])
|
|
|
|
this_dir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
posix = symbols.GetFromTxt(os.path.join(this_dir, 'posix-2013.txt'))
|
|
|
|
ndk_ignored = GetNdkIgnored(arch)
|
2014-05-16 23:44:38 +02:00
|
|
|
|
2014-12-04 20:24:48 +01:00
|
|
|
glibc = set(map(MangleGlibcNameToBionic, glibc))
|
2014-06-13 20:50:07 +02:00
|
|
|
|
2014-05-16 23:44:38 +02:00
|
|
|
# bionic includes various BSD symbols to ease porting other BSD-licensed code.
|
|
|
|
bsd_stuff = set([
|
2016-01-16 04:54:31 +01:00
|
|
|
'arc4random',
|
|
|
|
'arc4random_buf',
|
|
|
|
'arc4random_uniform',
|
2014-05-23 03:53:21 +02:00
|
|
|
'basename_r',
|
|
|
|
'dirname_r',
|
|
|
|
'fgetln',
|
|
|
|
'fpurge',
|
|
|
|
'funopen',
|
2016-02-03 20:24:28 +01:00
|
|
|
'funopen64',
|
2014-05-23 03:53:21 +02:00
|
|
|
'gamma_r',
|
|
|
|
'gammaf_r',
|
2014-05-16 23:44:38 +02:00
|
|
|
'getprogname',
|
|
|
|
'setprogname',
|
|
|
|
'strlcat',
|
|
|
|
'strlcpy',
|
2014-05-23 03:53:21 +02:00
|
|
|
'sys_signame',
|
2014-05-16 23:44:38 +02:00
|
|
|
'wcslcat',
|
2016-05-07 00:44:26 +02:00
|
|
|
'wcslcpy',
|
2014-05-16 23:44:38 +02:00
|
|
|
])
|
|
|
|
# Some symbols are part of the FORTIFY implementation.
|
|
|
|
FORTIFY_stuff = set([
|
|
|
|
'__FD_CLR_chk',
|
|
|
|
'__FD_ISSET_chk',
|
|
|
|
'__FD_SET_chk',
|
2016-01-16 04:54:31 +01:00
|
|
|
'__fwrite_chk',
|
|
|
|
'__memchr_chk',
|
|
|
|
'__memrchr_chk',
|
|
|
|
'__pwrite64_chk',
|
|
|
|
'__pwrite_chk',
|
2017-08-28 18:18:34 +02:00
|
|
|
'__sendto_chk',
|
2014-05-16 23:44:38 +02:00
|
|
|
'__stack_chk_guard',
|
|
|
|
'__stpncpy_chk2',
|
|
|
|
'__strchr_chk',
|
|
|
|
'__strlcat_chk',
|
|
|
|
'__strlcpy_chk',
|
|
|
|
'__strlen_chk',
|
|
|
|
'__strncpy_chk2',
|
|
|
|
'__strrchr_chk',
|
2016-05-06 23:43:50 +02:00
|
|
|
'__umask_chk',
|
2016-01-16 04:54:31 +01:00
|
|
|
'__write_chk',
|
2014-05-16 23:44:38 +02:00
|
|
|
])
|
2016-05-06 23:43:50 +02:00
|
|
|
# Some symbols are used to implement public functions/macros.
|
2014-05-21 05:37:56 +02:00
|
|
|
macro_stuff = set([
|
|
|
|
'__assert2',
|
|
|
|
'__errno',
|
|
|
|
'__fe_dfl_env',
|
|
|
|
'__get_h_errno',
|
2016-05-06 23:43:50 +02:00
|
|
|
'__gnu_strerror_r',
|
2014-08-13 22:04:28 +02:00
|
|
|
'__fpclassifyd',
|
|
|
|
'__isfinite',
|
|
|
|
'__isfinitef',
|
|
|
|
'__isfinitel',
|
|
|
|
'__isnormal',
|
|
|
|
'__isnormalf',
|
|
|
|
'__isnormall',
|
|
|
|
'__sF',
|
|
|
|
'__pthread_cleanup_pop',
|
|
|
|
'__pthread_cleanup_push',
|
2014-05-21 05:37:56 +02:00
|
|
|
])
|
2014-05-16 23:44:38 +02:00
|
|
|
# bionic exposes various Linux features that glibc doesn't.
|
|
|
|
linux_stuff = set([
|
|
|
|
'getauxval',
|
|
|
|
'gettid',
|
2016-05-06 23:43:50 +02:00
|
|
|
'pthread_gettid_np',
|
|
|
|
'tgkill',
|
2014-05-16 23:44:38 +02:00
|
|
|
])
|
|
|
|
# Some standard stuff isn't yet in the versions of glibc we're using.
|
|
|
|
std_stuff = set([
|
2014-06-07 00:20:50 +02:00
|
|
|
'at_quick_exit',
|
|
|
|
'c16rtomb',
|
|
|
|
'c32rtomb',
|
|
|
|
'mbrtoc16',
|
|
|
|
'mbrtoc32',
|
2014-05-16 23:44:38 +02:00
|
|
|
])
|
|
|
|
# These have mangled names in glibc, with a macro taking the "obvious" name.
|
|
|
|
weird_stuff = set([
|
|
|
|
'fstat',
|
|
|
|
'fstat64',
|
|
|
|
'fstatat',
|
|
|
|
'fstatat64',
|
|
|
|
'isfinite',
|
|
|
|
'isfinitef',
|
|
|
|
'isfinitel',
|
|
|
|
'isnormal',
|
|
|
|
'isnormalf',
|
|
|
|
'isnormall',
|
|
|
|
'lstat',
|
|
|
|
'lstat64',
|
|
|
|
'mknod',
|
|
|
|
'mknodat',
|
|
|
|
'stat',
|
|
|
|
'stat64',
|
2014-08-13 22:04:28 +02:00
|
|
|
'optreset',
|
|
|
|
'sigsetjmp',
|
|
|
|
])
|
|
|
|
# These exist in glibc, but under slightly different names (generally one extra
|
|
|
|
# or one fewer _). TODO: check against glibc names.
|
|
|
|
libresolv_stuff = set([
|
|
|
|
'__res_send_setqhook',
|
|
|
|
'__res_send_setrhook',
|
2016-05-06 23:43:50 +02:00
|
|
|
'_resolv_delete_cache_for_net',
|
2014-08-13 22:04:28 +02:00
|
|
|
'_resolv_flush_cache_for_net',
|
|
|
|
'_resolv_set_nameservers_for_net',
|
|
|
|
'dn_expand',
|
|
|
|
'nsdispatch',
|
|
|
|
])
|
|
|
|
# Implementation details we know we export (and can't get away from).
|
|
|
|
known = set([
|
|
|
|
'_ctype_',
|
|
|
|
'__libc_init',
|
2014-05-16 23:44:38 +02:00
|
|
|
])
|
2016-04-06 22:29:22 +02:00
|
|
|
# POSIX has some stuff that's too stupid for words (a64l) or not actually
|
|
|
|
# implemented in glibc unless you count always failing with ENOSYS as
|
2017-10-18 23:00:13 +02:00
|
|
|
# being implemented (fattach). Other stuff (fmtmsg) isn't used in any
|
|
|
|
# codebase I have access to, internal or external.
|
2017-08-28 18:18:34 +02:00
|
|
|
in_posix_and_glibc_but_dead_or_useless = set([
|
|
|
|
'a64l', # obsolete
|
|
|
|
'confstr', # obsolete
|
2017-10-13 05:32:22 +02:00
|
|
|
'endutxent', # no utmp on Android
|
2017-10-20 06:52:51 +02:00
|
|
|
'fattach', # <stropts.h> marked obsolescent
|
|
|
|
'fdetach', # <stropts.h> marked obsolescent
|
2017-10-18 23:00:13 +02:00
|
|
|
'fmtmsg', # unused
|
|
|
|
'getdate', # unused
|
|
|
|
'getdate_err', # unused
|
2017-08-28 18:18:34 +02:00
|
|
|
'gethostid', # obsolete
|
2017-10-20 06:52:51 +02:00
|
|
|
'getmsg', # <stropts.h> marked obsolescent
|
|
|
|
'getpmsg', # <stropts.h> marked obsolescent
|
2017-08-28 18:18:34 +02:00
|
|
|
'getutxent', # no utmp on Android
|
|
|
|
'getutxid', # no utmp on Android
|
|
|
|
'getutxline', # no utmp on Android
|
2017-10-20 06:52:51 +02:00
|
|
|
'isastream', # <stropts.h> marked obsolescent
|
2017-08-28 18:18:34 +02:00
|
|
|
'l64a', # obsolete
|
|
|
|
'mq_close', # disallowed by SELinux
|
|
|
|
'mq_getattr', # disallowed by SELinux
|
|
|
|
'mq_notify', # disallowed by SELinux
|
|
|
|
'mq_open', # disallowed by SELinux
|
|
|
|
'mq_receive', # disallowed by SELinux
|
|
|
|
'mq_send', # disallowed by SELinux
|
|
|
|
'mq_setattr', # disallowed by SELinux
|
|
|
|
'mq_timedreceive', # disallowed by SELinux
|
|
|
|
'mq_timedsend', # disallowed by SELinux
|
|
|
|
'mq_unlink', # disallowed by SELinux
|
2017-10-13 19:21:37 +02:00
|
|
|
'pthread_getconcurrency', # marked obsolescent
|
|
|
|
'pthread_setconcurrency', # marked obsolescent
|
2017-10-20 06:52:51 +02:00
|
|
|
'putmsg', # <stropts.h> marked obsolescent
|
|
|
|
'putpmsg', # <stropts.h> marked obsolescent
|
2017-08-28 18:18:34 +02:00
|
|
|
'pututxline', # no utmp on Android
|
|
|
|
'shm_open', # disallowed by SELinux
|
|
|
|
'shm_unlink', # disallowed by SELinux
|
|
|
|
'setutxent', # no utmp on Android
|
2017-10-19 23:54:05 +02:00
|
|
|
'sockatmark', # obsolete (https://tools.ietf.org/html/rfc6093)
|
2017-08-28 18:18:34 +02:00
|
|
|
'strfmon', # icu4c
|
|
|
|
'strfmon_l', # icu4c
|
2017-10-20 06:52:51 +02:00
|
|
|
'ulimit', # <ulimit.h> marked obsolescent
|
2016-04-06 22:29:22 +02:00
|
|
|
])
|
|
|
|
|
2017-08-28 18:18:34 +02:00
|
|
|
posix = posix - in_posix_and_glibc_but_dead_or_useless
|
|
|
|
glibc = glibc - in_posix_and_glibc_but_dead_or_useless
|
2014-05-16 23:44:38 +02:00
|
|
|
|
2014-08-13 22:04:28 +02:00
|
|
|
if not only_unwanted:
|
2014-12-04 20:24:48 +01:00
|
|
|
#print 'glibc:'
|
|
|
|
#for symbol in sorted(glibc):
|
|
|
|
# print symbol
|
|
|
|
#print
|
|
|
|
|
|
|
|
#print 'bionic:'
|
|
|
|
#for symbol in sorted(bionic):
|
|
|
|
# print symbol
|
|
|
|
#print
|
|
|
|
|
|
|
|
print 'in glibc (but not posix) but not bionic:'
|
|
|
|
for symbol in sorted((glibc - posix).difference(bionic)):
|
2014-08-13 22:04:28 +02:00
|
|
|
print symbol
|
|
|
|
print
|
|
|
|
|
2014-12-04 20:24:48 +01:00
|
|
|
print 'in posix (and implemented in glibc) but not bionic:'
|
|
|
|
for symbol in sorted((posix.intersection(glibc)).difference(bionic)):
|
2014-11-06 01:22:26 +01:00
|
|
|
print symbol
|
2014-08-13 22:04:28 +02:00
|
|
|
print
|
2014-12-04 20:24:48 +01:00
|
|
|
|
2014-08-13 22:04:28 +02:00
|
|
|
print 'in bionic but not glibc:'
|
2014-05-16 23:44:38 +02:00
|
|
|
|
2014-08-13 22:04:28 +02:00
|
|
|
allowed_stuff = (bsd_stuff | FORTIFY_stuff | linux_stuff | macro_stuff |
|
2014-08-15 23:20:04 +02:00
|
|
|
std_stuff | weird_stuff | libresolv_stuff | known)
|
2014-05-21 05:37:56 +02:00
|
|
|
for symbol in sorted((bionic - allowed_stuff).difference(glibc)):
|
2014-08-13 22:04:28 +02:00
|
|
|
if symbol in ndk_ignored:
|
|
|
|
symbol += '*'
|
2014-05-16 23:44:38 +02:00
|
|
|
print symbol
|
|
|
|
|
|
|
|
sys.exit(0)
|