1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4import os 5import sys 6import subprocess 7 8 9ELF_MAGIC = '\x7fELF' 10 11with open(sys.argv[1], "rb") as f: 12 buf = f.read(len(ELF_MAGIC)) 13 if buf != ELF_MAGIC: 14 sys.exit(0) 15 16llvm_objcopy = os.path.join('@LLVM_RUNTIME_OUTPUT_INTDIR@', 'llvm-objcopy') 17install_dir = os.path.join(os.getenv('DESTDIR', ''), '@CMAKE_INSTALL_PREFIX@') 18link_dir = os.path.join(install_dir, 'lib', 'debug', '.build-id') 19 20sys.exit(subprocess.call([ 21 llvm_objcopy, 22 '--strip-all', 23 '--build-id-link-dir=' + link_dir, 24 '--build-id-link-input=.debug', 25 '--build-id-link-output=', 26 sys.argv[1], 27])) 28