From ed90addf36270b22bf2e798eb1d3275a4659b4e9 Mon Sep 17 00:00:00 2001 From: yang yunjia <14576829+elcnukys@user.noreply.gitee.com> Date: Thu, 16 Jan 2025 19:47:19 +0800 Subject: [PATCH 1/2] clang_rt.crtbegin.o clang_rt.crtend.o bti enable --- llvm-build/build.py | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/llvm-build/build.py b/llvm-build/build.py index 4459e122e246..d4e027acfdf8 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -1588,6 +1588,9 @@ class LlvmLibs(BuildUtils): self.build_crts(llvm_install, arch, llvm_triple, cflags, ldflags, multilib_suffix, defines, first_time=False) + if arch == 'aarch64': + self.build_crts(llvm_install, arch, llvm_triple, cflags, ldflags, multilib_suffix, defines, + first_time=False, bti=True) if llvm_triple in arch_list: if self.build_config.need_lldb_tools and has_lldb_tools and llvm_triple not in seen_arch_list: @@ -1638,6 +1641,9 @@ class LlvmLibs(BuildUtils): else: self.build_crts(llvm_install, arch, llvm_triple, cflags, ldflags, multilib_suffix, defines, first_time=False) + if arch == 'aarch64': + self.build_crts(llvm_install, arch, llvm_triple, cflags, ldflags, multilib_suffix, defines, + first_time=False, bti=True) elif libs_type == 'runtimes': if is_first_time: self.build_runtimes(llvm_install, "libunwind", ldflags, cflags, llvm_triple, arch, multilib_suffix, defines) @@ -1733,12 +1739,16 @@ class LlvmLibs(BuildUtils): ldflags, multilib_suffix, defines, - first_time=True): + first_time=True, + bti=False): self.logger().info('Building compiler-rt for %s', arch) suffix = '-' + multilib_suffix if multilib_suffix else '' - crt_path = self.merge_out_path('lib', 'clangrt-%s%s' % (llvm_triple, suffix)) + if bti: + crt_path = self.merge_out_path('lib', 'clangrt-%s%s-bti' % (llvm_triple, suffix)) + else: + crt_path = self.merge_out_path('lib', 'clangrt-%s%s' % (llvm_triple, suffix)) crt_install = os.path.join(llvm_install, 'lib', 'clang', self.build_config.VERSION) crt_extra_flags = [] @@ -1746,6 +1756,13 @@ class LlvmLibs(BuildUtils): # Remove absolute paths from compiler-rt debug info emitted with -gline-tables-only crt_extra_flags = ['-ffile-prefix-map=%s=.' % self.build_config.REPOROOT_DIR] + build_target = [] + install_target = [] + if arch == 'aarch64' and bti: + crt_extra_flags.append('-mbranch-protection=bti') + build_target = ['clang_rt.crtbegin-aarch64', 'clang_rt.crtend-aarch64'] + install_target = ['install-clang_rt.crtend-aarch64', 'install-clang_rt.crtbegin-aarch64'] + crt_defines = defines.copy() crt_defines['CMAKE_EXE_LINKER_FLAGS'] = ' '.join(ldflags) crt_defines['CMAKE_SHARED_LINKER_FLAGS'] = ' '.join(ldflags) @@ -1784,10 +1801,20 @@ class LlvmLibs(BuildUtils): crt_defines, env=dict(self.build_config.ORIG_ENV)) - self.invoke_ninja(out_path=crt_path, - env=dict(self.build_config.ORIG_ENV), - target=None, - install=True) + if not bti: + self.invoke_ninja(out_path=crt_path, + env=dict(self.build_config.ORIG_ENV), + target=None, + install=True) + else: + self.invoke_ninja(out_path=crt_path, + env=dict(self.build_config.ORIG_ENV), + target=build_target, + install=False) + self.invoke_ninja(out_path=crt_path, + env=dict(self.build_config.ORIG_ENV), + target=install_target, + install=False) def build_libomp(self, llvm_install, -- Gitee From 67bf535bc625e05b675c82cf6476e20414ea1323 Mon Sep 17 00:00:00 2001 From: yang yunjia <14576829+elcnukys@user.noreply.gitee.com> Date: Thu, 16 Jan 2025 19:47:19 +0800 Subject: [PATCH 2/2] clang_rt.crtbegin.o clang_rt.crtend.o bti enable Signed-off-by: yang yunjia --- llvm-build/build.py | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/llvm-build/build.py b/llvm-build/build.py index 4459e122e246..d4e027acfdf8 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -1588,6 +1588,9 @@ class LlvmLibs(BuildUtils): self.build_crts(llvm_install, arch, llvm_triple, cflags, ldflags, multilib_suffix, defines, first_time=False) + if arch == 'aarch64': + self.build_crts(llvm_install, arch, llvm_triple, cflags, ldflags, multilib_suffix, defines, + first_time=False, bti=True) if llvm_triple in arch_list: if self.build_config.need_lldb_tools and has_lldb_tools and llvm_triple not in seen_arch_list: @@ -1638,6 +1641,9 @@ class LlvmLibs(BuildUtils): else: self.build_crts(llvm_install, arch, llvm_triple, cflags, ldflags, multilib_suffix, defines, first_time=False) + if arch == 'aarch64': + self.build_crts(llvm_install, arch, llvm_triple, cflags, ldflags, multilib_suffix, defines, + first_time=False, bti=True) elif libs_type == 'runtimes': if is_first_time: self.build_runtimes(llvm_install, "libunwind", ldflags, cflags, llvm_triple, arch, multilib_suffix, defines) @@ -1733,12 +1739,16 @@ class LlvmLibs(BuildUtils): ldflags, multilib_suffix, defines, - first_time=True): + first_time=True, + bti=False): self.logger().info('Building compiler-rt for %s', arch) suffix = '-' + multilib_suffix if multilib_suffix else '' - crt_path = self.merge_out_path('lib', 'clangrt-%s%s' % (llvm_triple, suffix)) + if bti: + crt_path = self.merge_out_path('lib', 'clangrt-%s%s-bti' % (llvm_triple, suffix)) + else: + crt_path = self.merge_out_path('lib', 'clangrt-%s%s' % (llvm_triple, suffix)) crt_install = os.path.join(llvm_install, 'lib', 'clang', self.build_config.VERSION) crt_extra_flags = [] @@ -1746,6 +1756,13 @@ class LlvmLibs(BuildUtils): # Remove absolute paths from compiler-rt debug info emitted with -gline-tables-only crt_extra_flags = ['-ffile-prefix-map=%s=.' % self.build_config.REPOROOT_DIR] + build_target = [] + install_target = [] + if arch == 'aarch64' and bti: + crt_extra_flags.append('-mbranch-protection=bti') + build_target = ['clang_rt.crtbegin-aarch64', 'clang_rt.crtend-aarch64'] + install_target = ['install-clang_rt.crtend-aarch64', 'install-clang_rt.crtbegin-aarch64'] + crt_defines = defines.copy() crt_defines['CMAKE_EXE_LINKER_FLAGS'] = ' '.join(ldflags) crt_defines['CMAKE_SHARED_LINKER_FLAGS'] = ' '.join(ldflags) @@ -1784,10 +1801,20 @@ class LlvmLibs(BuildUtils): crt_defines, env=dict(self.build_config.ORIG_ENV)) - self.invoke_ninja(out_path=crt_path, - env=dict(self.build_config.ORIG_ENV), - target=None, - install=True) + if not bti: + self.invoke_ninja(out_path=crt_path, + env=dict(self.build_config.ORIG_ENV), + target=None, + install=True) + else: + self.invoke_ninja(out_path=crt_path, + env=dict(self.build_config.ORIG_ENV), + target=build_target, + install=False) + self.invoke_ninja(out_path=crt_path, + env=dict(self.build_config.ORIG_ENV), + target=install_target, + install=False) def build_libomp(self, llvm_install, -- Gitee