diff options
author | der richter <der.richter@gmx.de> | 2019-09-22 00:32:40 +0200 |
---|---|---|
committer | Jan Ekström <jeebjp@gmail.com> | 2019-09-22 17:07:51 +0300 |
commit | e3972746dc18473ad577d04547d0f05775da4658 (patch) | |
tree | 3b7ab652399b9a8fbd3e8c15b885e0e3095b1554 | |
parent | f64c0115ae475c8584e0825340b7488be4095c2c (diff) | |
download | mpv-e3972746dc18473ad577d04547d0f05775da4658.tar.bz2 mpv-e3972746dc18473ad577d04547d0f05775da4658.tar.xz |
osxbundle: remove rpath definitions towards dev tools
since the loading order of rpaths is system wide lib path, dev tool path
and then bundle lib path it's possible for the xcode swift libs to be
incompatible with the libs the bundle was build with. this leads to
possible segfaults. if we distribute the bundle we don't want to load
the libs from the dev tools anyway.
-rwxr-xr-x | TOOLS/dylib-unhell.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/TOOLS/dylib-unhell.py b/TOOLS/dylib-unhell.py index 05c75789e7..fe26f38e67 100755 --- a/TOOLS/dylib-unhell.py +++ b/TOOLS/dylib-unhell.py @@ -24,10 +24,21 @@ def is_user_lib(objfile, libname): not "libswift" in libname def otool(objfile): - command = "otool -L %s | grep -e '\t' | awk '{ print $1 }'" % objfile + command = "otool -L '%s' | grep -e '\t' | awk '{ print $1 }'" % objfile output = subprocess.check_output(command, shell = True, universal_newlines=True) return set(filter(partial(is_user_lib, objfile), output.split())) +def get_rpaths_dev_tools(binary): + command = "otool -l '%s' | grep -A2 LC_RPATH | grep path | grep \"Xcode\|CommandLineTools\"" % binary + result = subprocess.check_output(command, shell = True, universal_newlines=True) + pathRe = re.compile("^\s*path (.*) \(offset \d*\)$") + output = [] + + for line in result.splitlines(): + output.append(pathRe.search(line).group(1).strip()) + + return output + def install_name_tool_change(old, new, objfile): subprocess.call(["install_name_tool", "-change", old, new, objfile]) @@ -37,6 +48,9 @@ def install_name_tool_id(name, objfile): def install_name_tool_add_rpath(rpath, binary): subprocess.call(["install_name_tool", "-add_rpath", rpath, binary]) +def install_name_tool_delete_rpath(rpath, binary): + subprocess.call(["install_name_tool", "-delete_rpath", rpath, binary]) + def libraries(objfile, result = dict()): libs_list = otool(objfile) result[objfile] = libs_list @@ -104,6 +118,10 @@ def process_swift_libraries(binary): print(">> setting additional rpath for swift libraries") install_name_tool_add_rpath("@executable_path/lib", binary) +def remove_dev_tools_rapths(binary): + for path in get_rpaths_dev_tools(binary): + install_name_tool_delete_rpath(path, binary) + def main(): binary = os.path.abspath(sys.argv[1]) if not os.path.exists(lib_path(binary)): @@ -116,6 +134,9 @@ def main(): while libs_processed is not None: libs_processed = process_libraries(libs, binary, libs_processed) + print(">> removing rpath definitions towards dev tools") + remove_dev_tools_rapths(binary) + print(">> copying and processing swift libraries") process_swift_libraries(binary) |