diff --git a/CMakeLists.txt b/CMakeLists.txt index 6750d9dc8ffebfec620392c71e1995270fb168d4..35d680340ad775652183b95022b95f19d6ce72af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,9 +133,9 @@ if (CMAKE_BUILD_TYPE MATCHES Debug) set(CMAKE_CXX_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CMAKE_CXX_FLAGS}") set(CXXFLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CXXFLAGS}") else() - set(CMAKE_C_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-s,-z,noexecstack -fPIE -pie ${CMAKE_C_FLAGS}") - set(CMAKE_CXX_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-s,-z,noexecstack -fPIE -pie ${CMAKE_CXX_FLAGS}") - set(CXXFLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-s,-z,noexecstack -fPIE -pie ${CXXFLAGS}") + set(CMAKE_C_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CMAKE_CXX_FLAGS}") + set(CXXFLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CXXFLAGS}") endif() if (NOT DEFINED BUILD_LIBTORCH) diff --git a/build_libtorch_npu.py b/build_libtorch_npu.py index cd3ec920b8e515f1c21d5494d3f2f1d6b1a9a434..9dc8d87fef0eb0dd1748e14fdffea3b88b094a1a 100644 --- a/build_libtorch_npu.py +++ b/build_libtorch_npu.py @@ -122,6 +122,16 @@ def check_gtest_valid(base_dir): return os.path.exists(gtest_path) +def generate_dbg_files_and_strip(): + library_dir = Path(BASE_DIR).joinpath("build/packages/torch_npu") + dbg_dir = Path(BASE_DIR).joinpath("build/dbg_libtorch") + os.makedirs(dbg_dir, exist_ok=True) + library_files = [Path(i) for i in library_dir.rglob('*.so')] + for library_file in library_files: + subprocess.check_call(["eu-strip", library_file, "-f", + str(dbg_dir.joinpath(library_file.name)) + ".debug"], cwd=BASE_DIR) # Compliant + + def run_cmake(): cmake = get_cmake_command() @@ -159,6 +169,8 @@ def run_cmake(): subprocess.check_call([cmake, BASE_DIR] + cmake_args, cwd=build_type_dir, env=os.environ) subprocess.check_call(['make'] + build_args, cwd=build_type_dir, env=os.environ) + if which('eu-strip') is not None: + generate_dbg_files_and_strip() def check_opplugin_valid(base_dir): diff --git a/setup.py b/setup.py index 0a1a94ef21822b638b1b031addbfaf3ab76116cd..935582fd9f46c4639b6174cc61ddf00f87223df7 100644 --- a/setup.py +++ b/setup.py @@ -207,6 +207,16 @@ def check_tensorpipe_valid(base_dir): return os.path.exists(tensorpipe_path) +def generate_dbg_files_and_strip(): + library_dir = Path(BASE_DIR).joinpath("build/packages/torch_npu") + dbg_dir = Path(BASE_DIR).joinpath("build/dbg") + os.makedirs(dbg_dir, exist_ok=True) + library_files = [Path(i) for i in library_dir.rglob('*.so')] + for library_file in library_files: + subprocess.check_call(["eu-strip", library_file, "-f", + str(dbg_dir.joinpath(library_file.name)) + ".debug"], cwd=BASE_DIR) # Compliant + + def CppExtension(name, sources, *args, **kwargs): r''' Creates a :class:`setuptools.Extension` for C++. @@ -421,6 +431,9 @@ class PythonPackageBuild(build_py, object): class BdistWheelBuild(bdist_wheel): def run(self): + if which('eu-strip') is not None: + generate_dbg_files_and_strip() + torch_dependencies = ["libc10.so", "libtorch.so", "libtorch_cpu.so", "libtorch_python.so"] cann_dependencies = ["libhccl.so", "libascendcl.so", "libacl_op_compiler.so", "libge_runner.so", "libgraph.so", "libacl_tdt_channel.so", "libfmk_parser.so", "libascend_protobuf.so"] @@ -482,7 +495,7 @@ if DEBUG: extra_link_args += ['-O0', '-g', '-Wl,-z,now'] else: extra_compile_args += ['-DNDEBUG'] - extra_link_args += ['-Wl,-z,now,-s'] + extra_link_args += ['-Wl,-z,now'] # valid manylinux tags manylinux_tags = [