Movatterモバイル変換


[0]ホーム

URL:


Google Git
Sign in
android /platform /bionic /refs/heads/main /. /libc /tools /symbols.py
blob: 145753421ade68ebeb6ad031e5f14fd5e0646002 [file] [log] [blame]
Dan Albert169eb662015-01-21 16:42:02 -0800[diff] [blame]1#
2# Copyright (C) 2015 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the 'License');
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an 'AS IS' BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16import glob
17import os
18import re
19import subprocess
20
21
22defGetFromTxt(txt_file):
23 symbols= set()
24 f= open(txt_file,'r')
25for linein f.read().splitlines():
26 symbols.add(line)
27 f.close()
28return symbols
29
30
Dan Albert9c3fd592015-01-21 17:50:29 -0800[diff] [blame]31defGetFromElf(elf_file, sym_type='--dyn-syms'):
Dan Albert169eb662015-01-21 16:42:02 -0800[diff] [blame]32# pylint: disable=line-too-long
33# Example readelf output:
34# 264: 0001623c 4 FUNC GLOBAL DEFAULT 8 cabsf
35# 266: 00016244 4 FUNC GLOBAL DEFAULT 8 dremf
36# 267: 00019018 4 OBJECT GLOBAL DEFAULT 11 __fe_dfl_env
37# 268: 00000000 0 FUNC GLOBAL DEFAULT UND __aeabi_dcmplt
38
39 r= re.compile(
40 r' +\d+: [0-9a-f]+ +\d+ (I?FUNC|OBJECT) +\S+ +\S+ +\d+ (\S+)')
41
42 symbols= set()
43
Elliott Hughes6b586e72021-04-15 13:39:08 -0700[diff] [blame]44 output= subprocess.check_output(['readelf', sym_type,'-W', elf_file],
45 text=True)
Dan Albert169eb662015-01-21 16:42:02 -0800[diff] [blame]46for linein output.split('\n'):
47if' HIDDEN 'in lineor' UND 'in line:
48continue
49 m= r.match(line)
50if m:
51 symbol= m.group(2)
52 symbol= re.sub('@.*','', symbol)
53 symbols.add(symbol)
54
55return symbols
56
57
Dan Albert9c3fd592015-01-21 17:50:29 -0800[diff] [blame]58defGetFromAndroidStaticLib(files):
59 out_dir= os.environ['ANDROID_PRODUCT_OUT']
60 lib_dir= os.path.join(out_dir,'obj')
61
62 results= set()
63for fin files:
64 static_lib_dir= os.path.join(
65 lib_dir,
66'STATIC_LIBRARIES',
67'{}_intermediates'.format(os.path.splitext(f)[0]))
68 results|=GetFromElf(
69 os.path.join(static_lib_dir, f),
70 sym_type='--syms')
71return results
72
73
Dan Albert169eb662015-01-21 16:42:02 -0800[diff] [blame]74defGetFromAndroidSo(files):
75 out_dir= os.environ['ANDROID_PRODUCT_OUT']
76 lib_dir= os.path.join(out_dir,'system/lib64')
77ifnot os.path.isdir(lib_dir):
78 lib_dir= os.path.join(out_dir,'system/lib')
79
Elliott Hughes6b586e72021-04-15 13:39:08 -0700[diff] [blame]80 lib_dir= os.path.join(out_dir,'apex/com.android.runtime/lib64/bionic/')
81ifnot os.path.isdir(lib_dir):
82 lib_dir= os.path.join(out_dir,'apex/com.android.runtime/lib/bionic/')
83
Dan Albert169eb662015-01-21 16:42:02 -0800[diff] [blame]84 results= set()
85for fin files:
Dan Albert9c3fd592015-01-21 17:50:29 -0800[diff] [blame]86 results|=GetFromElf(os.path.join(lib_dir, f))
Dan Albert169eb662015-01-21 16:42:02 -0800[diff] [blame]87return results
88
89
90defGetFromSystemSo(files):
91 lib_dir='/lib/x86_64-linux-gnu'
92 results= set()
93for fin files:
Dan Albert9c3fd592015-01-21 17:50:29 -0800[diff] [blame]94 results|=GetFromElf(glob.glob(os.path.join(lib_dir, f))[-1])
Dan Albert169eb662015-01-21 16:42:02 -0800[diff] [blame]95return results

[8]ページ先頭

©2009-2025 Movatter.jp