-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unwinder visibility for most ABIs.
When we switched to using a linker script for libgcc in r19 we broke `-Wl,--exclude-libs,libgcc.a`, because `--exclude-libs` has no effect on the contents of linker scripts. As such, libgcc was not being hidden as expected. The good news is that on the one platform this causes the most trouble (Arm32, since it uses the LLVM unwinder for exception handling rather than libgcc) this didn't cause any issues. Since libunwind was linked first (and the `--exclude-libs` worked there, since the actual library was named), the libgcc unwind symbols did not end up in the output at all. So while this has not caused any issues, it is still a good idea for us to link libgcc hidden to guard against any future unwind ABI breaks. Test: Added a test that checks ndk-build output with readelf Bug: android/ndk#1092 Change-Id: I5c8203afd29f0b7b272a51aadfc1a5ca6cbd33e4
- Loading branch information
Showing
11 changed files
with
108 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
LOCAL_PATH := $(call my-dir) | ||
|
||
include $(CLEAR_VARS) | ||
LOCAL_MODULE := foo | ||
LOCAL_SRC_FILES := foo.cpp | ||
LOCAL_CPPFLAGS := -fexceptions -frtti | ||
include $(BUILD_SHARED_LIBRARY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
APP_STL := c++_static |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
void foo() { | ||
throw 42; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# | ||
# Copyright (C) 2018 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. | ||
# | ||
"""Check for correct link order from ndk-build. | ||
""" | ||
from pathlib import Path | ||
import re | ||
import subprocess | ||
from typing import Iterator, List, Optional, Tuple | ||
|
||
from ndk.abis import Abi | ||
import ndk.hosts | ||
from ndk.toolchains import LinkerOption | ||
|
||
|
||
def find_public_unwind_symbols(output: str) -> Iterator[str]: | ||
"""Returns an iterator over readelf lines with unwind symbols in them.""" | ||
# 274: 00000000000223d8 8 FUNC GLOBAL DEFAULT 11 _Unwind_GetIP | ||
# Group 1: Visibility | ||
# Group 2: Name | ||
readelf_regex = re.compile(r'^.*?(\S+)\s+\d+\s+(\S+)$') | ||
for line in output.splitlines(): | ||
match = readelf_regex.match(line) | ||
if match is None: | ||
continue | ||
visibility, name = match.groups() | ||
if name.startswith('_Unwind') and visibility == 'DEFAULT': | ||
yield name | ||
|
||
|
||
def readelf(ndk_path: Path, host: ndk.hosts.Host, library: Path, | ||
*args: str) -> str: | ||
"""Runs readelf, returning the output.""" | ||
readelf_path = (ndk_path / 'toolchains/llvm/prebuilt' / | ||
ndk.hosts.get_host_tag(str(ndk_path)) / 'bin/llvm-readelf') | ||
if host.is_windows: | ||
readelf_path = readelf_path.with_suffix('.exe') | ||
|
||
return subprocess.run( | ||
[str(readelf_path), *args, str(library)], | ||
check=True, | ||
encoding='utf-8', | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.STDOUT).stdout | ||
|
||
|
||
def run_test(ndk_path: str, abi: Abi, platform: Optional[int], | ||
linker: LinkerOption, build_flags: List[str]) -> Tuple[bool, str]: | ||
"""Check that unwinder symbols are hidden in outputs.""" | ||
ndk_build = Path(ndk_path) / 'ndk-build' | ||
host = ndk.hosts.get_default_host() | ||
if host.is_windows: | ||
ndk_build = ndk_build.with_suffix('.cmd') | ||
project_path = Path('project') | ||
ndk_args = build_flags + [ | ||
f'APP_ABI={abi}', | ||
f'APP_LD={linker.value}', | ||
f'APP_PLATFORM=android-{platform}', | ||
] | ||
subprocess.run( | ||
[str(ndk_build), '-C', str(project_path)] + ndk_args, | ||
check=True, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.STDOUT) | ||
|
||
library = project_path / 'libs' / str(abi) / 'libfoo.so' | ||
readelf_output = readelf(Path(ndk_path), host, library, '-sW') | ||
for symbol in find_public_unwind_symbols(readelf_output): | ||
return False, f'Found public unwind symbol: {symbol}' | ||
return True, '' |