From 711cabf7b1db8218138b960949561b690092537a Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 21 Feb 2020 15:35:04 -0800 Subject: [PATCH] Add ifuncs to the elf symbol list. Otherwise, we may miss parts of the ABI that are implemented as ifuncs, and get spurious errors when changing a function to an ifunc. Bug: 135772972 Change-Id: I2a85775731133fb5da3ba362b2bb74a1c6f160b5 --- .../src/repr/symbol/so_file_parser.cpp | 17 +++++++++---- .../tests/integration/ifunc/Android.bp | 23 +++++++++++++++++ .../tests/integration/ifunc/ifunc.c | 5 ++++ .../tests/integration/ifunc/map.txt | 4 +++ .../integration/ifunc/prebuilts/libifunc.so | Bin 0 -> 10848 bytes vndk/tools/header-checker/tests/module.py | 11 ++++++++ .../reference_dumps/arm/libifunc.so.lsdump | 24 ++++++++++++++++++ .../reference_dumps/arm64/libifunc.so.lsdump | 24 ++++++++++++++++++ .../reference_dumps/mips/libifunc.so.lsdump | 24 ++++++++++++++++++ .../reference_dumps/mips64/libifunc.so.lsdump | 24 ++++++++++++++++++ .../reference_dumps/x86/libifunc.so.lsdump | 24 ++++++++++++++++++ .../reference_dumps/x86_64/libifunc.so.lsdump | 24 ++++++++++++++++++ vndk/tools/header-checker/tests/test.py | 4 +++ 13 files changed, 203 insertions(+), 5 deletions(-) create mode 100644 vndk/tools/header-checker/tests/integration/ifunc/Android.bp create mode 100644 vndk/tools/header-checker/tests/integration/ifunc/ifunc.c create mode 100644 vndk/tools/header-checker/tests/integration/ifunc/map.txt create mode 100755 vndk/tools/header-checker/tests/integration/ifunc/prebuilts/libifunc.so create mode 100644 vndk/tools/header-checker/tests/reference_dumps/arm/libifunc.so.lsdump create mode 100644 vndk/tools/header-checker/tests/reference_dumps/arm64/libifunc.so.lsdump create mode 100644 vndk/tools/header-checker/tests/reference_dumps/mips/libifunc.so.lsdump create mode 100644 vndk/tools/header-checker/tests/reference_dumps/mips64/libifunc.so.lsdump create mode 100644 vndk/tools/header-checker/tests/reference_dumps/x86/libifunc.so.lsdump create mode 100644 vndk/tools/header-checker/tests/reference_dumps/x86_64/libifunc.so.lsdump diff --git a/vndk/tools/header-checker/src/repr/symbol/so_file_parser.cpp b/vndk/tools/header-checker/src/repr/symbol/so_file_parser.cpp index 9320a5480..77356db53 100644 --- a/vndk/tools/header-checker/src/repr/symbol/so_file_parser.cpp +++ b/vndk/tools/header-checker/src/repr/symbol/so_file_parser.cpp @@ -101,11 +101,18 @@ ELFSoFileParser::ELFSoFileParser(const llvm::object::ELFObjectFile *obj) { LLVMToIRSymbolBinding(elf_sym->getBinding()); std::string symbol_name = UnWrap(symbol_it.getName()); - llvm::object::SymbolRef::Type type = UnWrap(symbol_it.getType()); - if (type == llvm::object::SymbolRef::Type::ST_Function) { - exported_symbols_->AddFunction(symbol_name, symbol_binding); - } else if (type == llvm::object::SymbolRef::Type::ST_Data) { - exported_symbols_->AddVar(symbol_name, symbol_binding); + switch (symbol_it.getELFType()) { + case llvm::ELF::STT_OBJECT: + case llvm::ELF::STT_COMMON: + case llvm::ELF::STT_TLS: + exported_symbols_->AddVar(symbol_name, symbol_binding); + break; + case llvm::ELF::STT_FUNC: + case llvm::ELF::STT_GNU_IFUNC: + exported_symbols_->AddFunction(symbol_name, symbol_binding); + break; + default: + break; } } } diff --git a/vndk/tools/header-checker/tests/integration/ifunc/Android.bp b/vndk/tools/header-checker/tests/integration/ifunc/Android.bp new file mode 100644 index 000000000..207fd9bfb --- /dev/null +++ b/vndk/tools/header-checker/tests/integration/ifunc/Android.bp @@ -0,0 +1,23 @@ +// +// Copyright (C) 2020 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. +// + +cc_library { + name: "libifunc", + srcs: [ + "ifunc.c", + ], + enabled: false, +} diff --git a/vndk/tools/header-checker/tests/integration/ifunc/ifunc.c b/vndk/tools/header-checker/tests/integration/ifunc/ifunc.c new file mode 100644 index 000000000..f2f84df11 --- /dev/null +++ b/vndk/tools/header-checker/tests/integration/ifunc/ifunc.c @@ -0,0 +1,5 @@ +__attribute__((used)) static void *ifunc_resolver() { + return 0; +} + +void ifunc() __attribute__((ifunc("ifunc_resolver"))); diff --git a/vndk/tools/header-checker/tests/integration/ifunc/map.txt b/vndk/tools/header-checker/tests/integration/ifunc/map.txt new file mode 100644 index 000000000..80649a44c --- /dev/null +++ b/vndk/tools/header-checker/tests/integration/ifunc/map.txt @@ -0,0 +1,4 @@ +libifunc { + global: + ifunc; +}; diff --git a/vndk/tools/header-checker/tests/integration/ifunc/prebuilts/libifunc.so b/vndk/tools/header-checker/tests/integration/ifunc/prebuilts/libifunc.so new file mode 100755 index 0000000000000000000000000000000000000000..ce122eced40b438eb0fdb9878492d90522e3d5ec GIT binary patch literal 10848 zcmeHNeNa?Y6u-NRVu>iGhJvyS_^mG~CACq}6g9{IwMf);*$;MW*@b1HRmsN04fKYuIQ;M+_aP9+k-p%ygI)SES1JD@+$Hl23_Jf1-{m^#x>YLq}R;zdEv?hy9 zXSFObGK(qOre{`5s$R&lv-p`)?iZEe!%+ouI!A+*H$(!qxu_-d=W4Y^YAB&tm;;F- zM0FotL#*MN0LEqjZUkHe_#&VSa5JDA5T%y{OtB=1DRKuWLIT1%?4i&a3%>BzA?QCE zjuBv_YlfX@kB1}p26hA3{lNZLjlm#`TmiWPas}iH$Q6()AXh-HfLsB&0=H5HcEDr` z1L3PdwMtvp-rjy^gDPw*wsDddmhOEAzFX}GIuX;_<8ZeM*0^ z?^Y^|JQukFas}iH$Q6()AXh-HfLsB&0&)f93dj|ZD{#wHKrPLr2Yitig(K}%MsPFf zxYvq8`bbIb(8q8ceoqi(B1hVfrM<q3X{oqQ{5$!$i?~1E zzGlJP&dtoDkqoqdO8c_3SDwL%T{(~VxQi?bALw?jKEUzPbt&Hl&d0rFlrCx!81BiU zQ2rPAd_Um+*STKJb@<)o@AZ)A|9Vza00FkJEn1z!ptu8gxz_as-E6 zk^Mgx@%v_zka50`IXvhO}`JSbw&M_ z+jwGqz{x(vdVg(wVP-?fR$+%D{=)e4mn*6(<5q33bdL(%*gE?ABNcfCdCT6ueC&|_ z@aXNu`p^wB=l9kV6UrZ1HUB`;!x_i2 zOvj%ndhD4>{k^rrJt-dlU2E@;OREUn^um&DTSFgO@x8NUj4Wb!P;AY_N&BCuB|B%0uK(G@wUB}{qx{NmuFPyywoB0ypn2t;!^j*s)eJU znz%HlVrOjKobf3QCUe}m;~m|fjAC(r%CVa(6mQI&MO zYv)n9=4q#9w3)YrYqx)P<;mz~*Fv+qW!=$*rBllrFU4$FP@g%|HXtLexvaJ=F#3V4 z&~X(h%0rWT=Dxaq&*%fM8NPYi_3g89WAe>Gq05>Z^=DVljwlZFkKV^V{qS9r@km=~ z$@AgqDNVKUcMmHlI{jUhx#r~!BWjL9-*#}_bXSe(o?V)wm)-We ze+qKwr%u%b1?+7dR@%vvQ?>D8b$^edJXw2ef9ZmXLq7`{TSDjM8HW7!U7PE{L7qLc z%)#Y{4}EoB|J>@boau+dPfY4Mc5>mlsMyf^GOr(vo*Px(Z^hTznzEMiq94w0?7J#* z@x_d)nxpw8%A!7#J~H%PbaLOhNMrq}wnru=m%+VQdF{%qlR6Ra$27$uN<)9+D3d@{|IRvruCZq2or#hYbEKlUJ|OIABE!k=3fAP zEnfTvJ`kZA$siP;@|UcPjpuz7zr&Fe=y^c?9nUjvup)ZJr{^0XE#Jha_=KaN1Ls8X z>3K&;b;fjp;2<8^r+^J}BL2O@}n{0@OHInwNw-MSH%UceB;%meH&Eb+) MHQiW}`VZef0nTAc<^TWy literal 0 HcmV?d00001 diff --git a/vndk/tools/header-checker/tests/module.py b/vndk/tools/header-checker/tests/module.py index c3396153e..338058d13 100755 --- a/vndk/tools/header-checker/tests/module.py +++ b/vndk/tools/header-checker/tests/module.py @@ -413,6 +413,17 @@ TEST_MODULES = [ version_script='integration/c_and_cpp/repro_map.txt', export_include_dirs=['integration/c_and_cpp/include'], ), + LsdumpModule( + name='libifunc', + srcs=['integration/ifunc/ifunc.c'], + version_script='integration/ifunc/map.txt', + export_include_dirs=[], + linker_flags=[ + '-so', relative_to_abs_path( + 'integration/ifunc/prebuilts/libifunc.so' + ), + ] + ), LsdumpModule( name='libgolden_cpp_member_name_changed', srcs=[ diff --git a/vndk/tools/header-checker/tests/reference_dumps/arm/libifunc.so.lsdump b/vndk/tools/header-checker/tests/reference_dumps/arm/libifunc.so.lsdump new file mode 100644 index 000000000..3ddc48c4f --- /dev/null +++ b/vndk/tools/header-checker/tests/reference_dumps/arm/libifunc.so.lsdump @@ -0,0 +1,24 @@ +builtin_types { + type_info { + name: "void" + size: 0 + alignment: 0 + referenced_type: "_ZTIv" + source_file: "" + linker_set_key: "_ZTIv" + self_type: "_ZTIv" + } + is_unsigned: false + is_integral: false +} +functions { + return_type: "_ZTIv" + function_name: "ifunc" + source_file: "/development/vndk/tools/header-checker/tests/integration/ifunc/ifunc.c" + linker_set_key: "ifunc" + access: public_access +} +elf_functions { + name: "ifunc" + binding: Global +} diff --git a/vndk/tools/header-checker/tests/reference_dumps/arm64/libifunc.so.lsdump b/vndk/tools/header-checker/tests/reference_dumps/arm64/libifunc.so.lsdump new file mode 100644 index 000000000..3ddc48c4f --- /dev/null +++ b/vndk/tools/header-checker/tests/reference_dumps/arm64/libifunc.so.lsdump @@ -0,0 +1,24 @@ +builtin_types { + type_info { + name: "void" + size: 0 + alignment: 0 + referenced_type: "_ZTIv" + source_file: "" + linker_set_key: "_ZTIv" + self_type: "_ZTIv" + } + is_unsigned: false + is_integral: false +} +functions { + return_type: "_ZTIv" + function_name: "ifunc" + source_file: "/development/vndk/tools/header-checker/tests/integration/ifunc/ifunc.c" + linker_set_key: "ifunc" + access: public_access +} +elf_functions { + name: "ifunc" + binding: Global +} diff --git a/vndk/tools/header-checker/tests/reference_dumps/mips/libifunc.so.lsdump b/vndk/tools/header-checker/tests/reference_dumps/mips/libifunc.so.lsdump new file mode 100644 index 000000000..3ddc48c4f --- /dev/null +++ b/vndk/tools/header-checker/tests/reference_dumps/mips/libifunc.so.lsdump @@ -0,0 +1,24 @@ +builtin_types { + type_info { + name: "void" + size: 0 + alignment: 0 + referenced_type: "_ZTIv" + source_file: "" + linker_set_key: "_ZTIv" + self_type: "_ZTIv" + } + is_unsigned: false + is_integral: false +} +functions { + return_type: "_ZTIv" + function_name: "ifunc" + source_file: "/development/vndk/tools/header-checker/tests/integration/ifunc/ifunc.c" + linker_set_key: "ifunc" + access: public_access +} +elf_functions { + name: "ifunc" + binding: Global +} diff --git a/vndk/tools/header-checker/tests/reference_dumps/mips64/libifunc.so.lsdump b/vndk/tools/header-checker/tests/reference_dumps/mips64/libifunc.so.lsdump new file mode 100644 index 000000000..3ddc48c4f --- /dev/null +++ b/vndk/tools/header-checker/tests/reference_dumps/mips64/libifunc.so.lsdump @@ -0,0 +1,24 @@ +builtin_types { + type_info { + name: "void" + size: 0 + alignment: 0 + referenced_type: "_ZTIv" + source_file: "" + linker_set_key: "_ZTIv" + self_type: "_ZTIv" + } + is_unsigned: false + is_integral: false +} +functions { + return_type: "_ZTIv" + function_name: "ifunc" + source_file: "/development/vndk/tools/header-checker/tests/integration/ifunc/ifunc.c" + linker_set_key: "ifunc" + access: public_access +} +elf_functions { + name: "ifunc" + binding: Global +} diff --git a/vndk/tools/header-checker/tests/reference_dumps/x86/libifunc.so.lsdump b/vndk/tools/header-checker/tests/reference_dumps/x86/libifunc.so.lsdump new file mode 100644 index 000000000..3ddc48c4f --- /dev/null +++ b/vndk/tools/header-checker/tests/reference_dumps/x86/libifunc.so.lsdump @@ -0,0 +1,24 @@ +builtin_types { + type_info { + name: "void" + size: 0 + alignment: 0 + referenced_type: "_ZTIv" + source_file: "" + linker_set_key: "_ZTIv" + self_type: "_ZTIv" + } + is_unsigned: false + is_integral: false +} +functions { + return_type: "_ZTIv" + function_name: "ifunc" + source_file: "/development/vndk/tools/header-checker/tests/integration/ifunc/ifunc.c" + linker_set_key: "ifunc" + access: public_access +} +elf_functions { + name: "ifunc" + binding: Global +} diff --git a/vndk/tools/header-checker/tests/reference_dumps/x86_64/libifunc.so.lsdump b/vndk/tools/header-checker/tests/reference_dumps/x86_64/libifunc.so.lsdump new file mode 100644 index 000000000..3ddc48c4f --- /dev/null +++ b/vndk/tools/header-checker/tests/reference_dumps/x86_64/libifunc.so.lsdump @@ -0,0 +1,24 @@ +builtin_types { + type_info { + name: "void" + size: 0 + alignment: 0 + referenced_type: "_ZTIv" + source_file: "" + linker_set_key: "_ZTIv" + self_type: "_ZTIv" + } + is_unsigned: false + is_integral: false +} +functions { + return_type: "_ZTIv" + function_name: "ifunc" + source_file: "/development/vndk/tools/header-checker/tests/integration/ifunc/ifunc.c" + linker_set_key: "ifunc" + access: public_access +} +elf_functions { + name: "ifunc" + binding: Global +} diff --git a/vndk/tools/header-checker/tests/test.py b/vndk/tools/header-checker/tests/test.py index b1da06b62..0bbd4cdac 100755 --- a/vndk/tools/header-checker/tests/test.py +++ b/vndk/tools/header-checker/tests/test.py @@ -372,6 +372,10 @@ class HeaderCheckerTest(unittest.TestCase): self.prepare_and_absolute_diff_all_archs( "libanonymous_enum_odr", "libanonymous_enum_odr") + def test_libifunc(self): + self.prepare_and_absolute_diff_all_archs( + "libifunc", "libifunc") + if __name__ == '__main__': unittest.main()