From 89538876f396376db3e0a961447adbd1f4b372fc Mon Sep 17 00:00:00 2001 From: xwx1135370 Date: Tue, 26 Jul 2022 13:06:58 +0000 Subject: [PATCH 1/9] =?UTF-8?q?Signed-off-by:=20xwx1135370=20=20attach=20->fport=20rm=20=E3=80=90fport=20rm=E3=80=91A?= =?UTF-8?q?fter=20repeated=20C++=20debugging,=20lldb=20returns=20"[Fail]hd?= =?UTF-8?q?c=20thread=20pool=20busy,=20may=20cause=20reset=20later"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp index 249cd5e9d801..d28a73e3ec0d 100644 --- a/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp +++ b/lldb/source/Plugins/Platform/OHOS/PlatformOHOS.cpp @@ -221,6 +221,9 @@ Status PlatformOHOS::DisconnectRemote() { if (error.Success()) { m_device_id.clear(); m_sdk_version = 0; + if (m_remote_platform_sp) { + m_remote_platform_sp = nullptr; + } } return error; } -- Gitee From 0599d44e5e761a55c545a46a53903bb10ab80e1d Mon Sep 17 00:00:00 2001 From: xwx1135370 Date: Thu, 28 Jul 2022 11:34:39 +0000 Subject: [PATCH 2/9] =?UTF-8?q?Signed-off-by:=20xwx1135370=20=20HOS->HDC=5FSERVER=5FPORT.=20=E3=80=90lldb=E3=80=91=20?= =?UTF-8?q?OHOS=E6=89=93=E5=A3=B3=E8=BF=90=E8=A1=8C=EF=BC=8C=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3=E5=86=B2=E7=AA=81=E9=97=AE=E9=A2=98=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lldb/source/Plugins/Platform/Android/AdbClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Platform/Android/AdbClient.cpp b/lldb/source/Plugins/Platform/Android/AdbClient.cpp index ffccd6d628aa..50a4a07a9bab 100644 --- a/lldb/source/Plugins/Platform/Android/AdbClient.cpp +++ b/lldb/source/Plugins/Platform/Android/AdbClient.cpp @@ -134,7 +134,7 @@ Status AdbClient::Connect() { Status error; m_conn = std::make_unique(); std::string port = "5037"; - if (const char *env_port = std::getenv("ANDROID_ADB_SERVER_PORT")) { + if (const char *env_port = std::getenv("HDC_SERVER_PORT")) { port = env_port; } std::string uri = "connect://127.0.0.1:" + port; -- Gitee From 2dc6064bed7ee2ec39a0d2e94fc8de9cfc9a28fa Mon Sep 17 00:00:00 2001 From: chenhao346 Date: Fri, 29 Jul 2022 19:25:30 +0800 Subject: [PATCH 3/9] Resume download toolchain Signed-off-by: chenhao346 --- llvm-build/env_prepare.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm-build/env_prepare.sh b/llvm-build/env_prepare.sh index 527c69a51fd9..9a0adb720531 100755 --- a/llvm-build/env_prepare.sh +++ b/llvm-build/env_prepare.sh @@ -36,7 +36,7 @@ function download_and_archive() { archive_dir=$1 download_source_url=$2 bin_file=$(basename ${download_source_url}) - #wget -t3 -T10 -O "${bin_dir}/${bin_file}" "${download_source_url}" + wget -t3 -T10 -O "${bin_dir}/${bin_file}" "${download_source_url}" if [ ! -d "${code_dir}/${archive_dir}" ];then mkdir -p "${code_dir}/${archive_dir}" fi -- Gitee From 2910202c709cc6aee27daaad3c205643f09684f1 Mon Sep 17 00:00:00 2001 From: chenhao346 Date: Mon, 1 Aug 2022 10:48:46 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E3=80=90OHOS=E3=80=91=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E9=93=BE=E4=B8=8B=E8=BD=BD=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenhao346 --- llvm-build/env_prepare.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm-build/env_prepare.sh b/llvm-build/env_prepare.sh index 9a0adb720531..59210a7c4f29 100755 --- a/llvm-build/env_prepare.sh +++ b/llvm-build/env_prepare.sh @@ -113,9 +113,9 @@ if [ -d "${code_dir}/prebuilts/clang/ohos/darwin-${host_cpu}/clang-530132" ];the fi fi -if [ -d "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang+llvm-10.0.1-x86_64-gnu-ubuntu-16.04.tar.xz" ];then +if [ -d "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang+llvm-10.0.1-x86_64-linux-gnu-ubuntu-16.04" ];then rm -rf "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-10.0.1" - mv "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang+llvm-10.0.1-x86_64-gnu-ubuntu-16.04" "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-10.0.1" + mv "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang+llvm-10.0.1-x86_64-linux-gnu-ubuntu-16.04" "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-10.0.1" fi if [ -d "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang+llvm-10.0.1-x86_64-apple-darwin" ];then -- Gitee From be1c769b94a1aa7dcc7a33ba96663071a577635e Mon Sep 17 00:00:00 2001 From: liwentao_uiw Date: Tue, 2 Aug 2022 21:55:12 +0800 Subject: [PATCH 5/9] Update prebuilt dependency Signed-off-by: liwentao Change-Id: Ia10eb351fcd7764f02a2c7f00a2446910e19f6c9 --- llvm-build/env_prepare.sh | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/llvm-build/env_prepare.sh b/llvm-build/env_prepare.sh index 59210a7c4f29..acfc3d247f5d 100755 --- a/llvm-build/env_prepare.sh +++ b/llvm-build/env_prepare.sh @@ -51,20 +51,20 @@ function download_and_archive() { copy_config=""" -prebuilts/clang/ohos/${host_platform}-${host_cpu},https://mirrors.huaweicloud.com/openharmony/compiler/clang/12.0.1-530132/${host_platform}/clang-530132-${host_platform}-x86_64.tar.bz2 """ copy_config_linux_x86_64=""" prebuilts/cmake,https://mirrors.huaweicloud.com/harmonyos/compiler/cmake/3.16.5/${host_platform}/cmake-${host_platform}-x86-3.16.5.tar.gz +prebuilts/clang/ohos/${host_platform}-${host_cpu},https://mirrors.huaweicloud.com/openharmony/compiler/clang/10.0.1-62608/${host_platform}/llvm.tar.gz prebuilts/clang/ohos/${host_platform}-${host_cpu},https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.1/clang+llvm-10.0.1-x86_64-linux-gnu-ubuntu-16.04.tar.xz """ copy_config_darwin_x86_64=""" prebuilts/cmake,https://mirrors.huaweicloud.com/harmonyos/compiler/cmake/3.16.5/${host_platform}/cmake-${host_platform}-x86-3.16.5.tar.gz -prebuilts/clang/ohos/${host_platform}-${host_cpu},https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.1/clang+llvm-10.0.1-x86_64-apple-darwin.tar.xz +prebuilts/clang/ohos/${host_platform}-${host_cpu},https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz """ -# + if [[ "${host_platform}" == "linux" ]]; then if [[ "${host_cpu}" == "x86_64" ]]; then copy_config+=${copy_config_linux_x86_64} @@ -86,7 +86,6 @@ else fi - for i in $(echo ${copy_config}) do unzip_dir=$(echo $i|awk -F ',' '{print $1}') @@ -95,30 +94,19 @@ do done -if [ -d "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-530132" ];then +if [ -d "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-62608" ];then rm -rf "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm" - mv "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-530132" "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm" - ln -snf 12.0.1 "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm/lib/clang/current" + mv "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-62608" "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm" + ln -snf 10.0.1 "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm/lib/clang/current" fi -if [ -d "${code_dir}/prebuilts/clang/ohos/darwin-${host_cpu}/clang-530132" ];then - if [[ "${host_cpu}" == "arm64" ]]; then - rm -rf "${code_dir}/prebuilts/clang/ohos/darwin-arm64/llvm" - mv "${code_dir}/prebuilts/clang/ohos/darwin-arm64/clang-530132" "${code_dir}/prebuilts/clang/ohos/darwin-arm64/llvm" - ln -snf 12.0.1 "${code_dir}/prebuilts/clang/ohos/darwin-arm64/llvm/lib/clang/current" - else - rm -rf "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/llvm" - mv "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang-530132" "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/llvm" - ln -snf 12.0.1 "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/llvm/lib/clang/current" - fi -fi if [ -d "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang+llvm-10.0.1-x86_64-linux-gnu-ubuntu-16.04" ];then rm -rf "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-10.0.1" mv "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang+llvm-10.0.1-x86_64-linux-gnu-ubuntu-16.04" "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-10.0.1" fi -if [ -d "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang+llvm-10.0.1-x86_64-apple-darwin" ];then +if [ -d "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang+llvm-12.0.0-x86_64-apple-darwin" ];then rm -rf "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang-10.0.1" - mv "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang+llvm-10.0.1-x86_64-apple-darwin" "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang-10.0.1" + mv "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang+llvm-12.0.0-x86_64-apple-darwin" "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang-10.0.1" fi -- Gitee From 7f81edec1d188ae19cd5342a0fda25c1a9b5b11e Mon Sep 17 00:00:00 2001 From: wzjemo Date: Thu, 11 Aug 2022 14:53:59 +0800 Subject: [PATCH 6/9] Update the clang definition Signed-off-by: wzjemo --- llvm-build/build.py | 43 ++++++++++++++++--------------- llvm-build/build_cpython-mingw.sh | 5 ++-- llvm-build/env_prepare.sh | 1 + llvm-build/mingw.py | 21 ++++++++------- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/llvm-build/build.py b/llvm-build/build.py index a200c11b05c4..e82eac923d95 100755 --- a/llvm-build/build.py +++ b/llvm-build/build.py @@ -59,6 +59,7 @@ class BuildConfig(): self.OPENHOS_SFX = '-linux-ohos' self.LITEOS_SFX = '-liteos-ohos' self.LLDB_PY_VERSION = '3.10' + self.CLANG_VERSION = '10.0.1' logging.basicConfig(level=logging.INFO) @staticmethod @@ -464,7 +465,7 @@ class LlvmCore(BuildUtils): llvm_clang_install = os.path.abspath(os.path.join(self.build_config.REPOROOT_DIR, 'prebuilts/clang/ohos', self.use_platform(), - 'clang-10.0.1')) + 'clang-%s' % self.build_config.CLANG_VERSION)) llvm_path = self.merge_out_path('llvm_make') llvm_cc = os.path.join(llvm_clang_install, 'bin', 'clang') llvm_cxx = os.path.join(llvm_clang_install, 'bin', 'clang++') @@ -528,7 +529,7 @@ class LlvmCore(BuildUtils): windows_defines['LLDB_RELOCATABLE_PYTHON'] = 'OFF' win_sysroot = self.merge_out_path( - 'clang_mingw', 'clang-10.0.1', 'x86_64-w64-mingw32') + 'clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION, 'x86_64-w64-mingw32') windows_defines['LLDB_ENABLE_PYTHON'] = 'ON' windows_defines['LLDB_PYTHON_HOME'] = 'python' windows_defines['LLDB_PYTHON_RELATIVE_PATH'] = 'bin/python/lib/python%s' % (self.build_config.LLDB_PY_VERSION) @@ -631,11 +632,11 @@ class LlvmCore(BuildUtils): self.logger().info('Building llvm for windows.') build_dir = self.merge_out_path("windows-x86_64") - windowstool_path = self.merge_out_path('clang_mingw', 'clang-10.0.1') + windowstool_path = self.merge_out_path('clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION) windows64_install = self.merge_out_path('windows-x86_64-install') windows_sysroot = os.path.join(windowstool_path, 'x86_64-w64-mingw32') - compiler_rt_path = self.merge_out_path('clang_mingw', 'clang-10.0.1', - 'lib', 'clang', '10.0.1', 'lib', 'windows') + compiler_rt_path = self.merge_out_path('clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION, + 'lib', 'clang', self.build_config.CLANG_VERSION, 'lib', 'windows') self.check_create_dir(build_dir) @@ -1335,11 +1336,11 @@ class LlvmLibs(BuildUtils): def build_libs_for_windows(self, libname, enable_assertions): self.logger().info('Building libs for windows.') - toolchain_dir = self.merge_out_path('clang_mingw', 'clang-10.0.1') + toolchain_dir = self.merge_out_path('clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION) install_dir = self.merge_out_path('windows-x86_64-install') - compiler_rt_path = self.merge_out_path('clang_mingw', 'clang-10.0.1', 'lib', 'clang', - '10.0.1', 'lib', 'windows') - windows_sysroot = self.merge_out_path('clang_mingw', 'clang-10.0.1', 'x86_64-w64-mingw32') + compiler_rt_path = self.merge_out_path('clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION, 'lib', 'clang', + self.build_config.CLANG_VERSION, 'lib', 'windows') + windows_sysroot = self.merge_out_path('clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION, 'x86_64-w64-mingw32') ldflags = ['-fuse-ld=lld', '--rtlib=compiler-rt', '-L%s' % compiler_rt_path, '-lunwind'] cflags = ['-stdlib=libc++', '--target=x86_64-pc-windows-gnu', '-D_LARGEFILE_SOURCE', @@ -1405,7 +1406,7 @@ class LldbMi(BuildUtils): self.logger().info('Building lldb-mi for linux.') llvm_path = os.path.abspath(os.path.join(self.build_config.REPOROOT_DIR, - 'prebuilts/clang/ohos', self.use_platform(), 'clang-10.0.1')) + 'prebuilts/clang/ohos', self.use_platform(), 'clang-%s' % self.build_config.CLANG_VERSION)) lldb_mi_cmake_path = os.path.join(self.build_config.LLVM_PROJECT_DIR, '../lldb-mi') lldb_mi_path = self.merge_out_path('lldb_mi_build') @@ -1495,17 +1496,17 @@ class LldbMi(BuildUtils): def build_lldb_mi_for_windows(self): self.logger().info('Building lldb-mi for windows.') - build_dir = self.merge_out_path('clang_mingw', 'clang-10.0.1') + build_dir = self.merge_out_path('clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION) lldb_mi_windows64_path = self.merge_out_path('windows-x86_64-lldb-mi') lldb_mi_cmake_path = os.path.abspath(os.path.join(self.build_config.LLVM_PROJECT_DIR, '../lldb-mi')) windows64_install = self.merge_out_path('windows-x86_64-install') cc = os.path.join(build_dir, 'bin', 'clang') cxx = os.path.join(build_dir, 'bin', 'clang++') - windows_sysroot = self.merge_out_path('clang_mingw', 'clang-10.0.1', 'x86_64-w64-mingw32') + windows_sysroot = self.merge_out_path('clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION, 'x86_64-w64-mingw32') self.check_create_dir(lldb_mi_windows64_path) - compiler_rt_path = self.merge_out_path('clang_mingw', 'clang-10.0.1', - 'lib', 'clang', '10.0.1', 'lib', 'windows') + compiler_rt_path = self.merge_out_path('clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION, + 'lib', 'clang', self.build_config.CLANG_VERSION, 'lib', 'windows') ldflags = ['-fuse-ld=lld', '--rtlib=compiler-rt', @@ -1661,7 +1662,7 @@ class LlvmPackage(BuildUtils): def strip_lldb_server(self, host, install_dir): - clang_version_bin_dir = os.path.join(install_dir, 'lib', 'clang', '10.0.1', 'bin') + clang_version_bin_dir = os.path.join(install_dir, 'lib', 'clang', self.build_config.CLANG_VERSION, 'bin') if not host.startswith('linux') or not os.path.exists(clang_version_bin_dir): return @@ -1708,7 +1709,7 @@ class LlvmPackage(BuildUtils): if host.startswith('windows'): windows64_install = self.merge_out_path('windows-x86_64-install') clang_mingw_dir = self.merge_out_path('clang_mingw') - clang_mingw_sysroot_dir = os.path.join(clang_mingw_dir, 'clang-10.0.1', 'x86_64-w64-mingw32') + clang_mingw_sysroot_dir = os.path.join(clang_mingw_dir, 'clang-%s' % self.build_config.CLANG_VERSION, 'x86_64-w64-mingw32') package_name = 'clang-mingw-%s' % self.build_config.build_name clang_mingw_sysroot_lib_dir = os.path.join(clang_mingw_sysroot_dir, 'lib') clang_windows_lib_dir = os.path.join(windows64_install, 'lib') @@ -1721,19 +1722,19 @@ class LlvmPackage(BuildUtils): os.path.join(clang_mingw_sysroot_dir, 'include', 'c++')) lib_files = [] - if os.path.isdir(os.path.join(clang_mingw_dir, 'clang-10.0.1', 'lib')): - lib_files = os.listdir(os.path.join(clang_mingw_dir, 'clang-10.0.1', 'lib')) + if os.path.isdir(os.path.join(clang_mingw_dir, 'clang-%s' % self.build_config.CLANG_VERSION, 'lib')): + lib_files = os.listdir(os.path.join(clang_mingw_dir, 'clang-%s' % self.build_config.CLANG_VERSION, 'lib')) for lib_file in lib_files: if lib_file.endswith('.a'): - static_library = os.path.join(os.path.join(clang_mingw_dir, 'clang-10.0.1', 'lib'), lib_file) + static_library = os.path.join(os.path.join(clang_mingw_dir, 'clang-%s' % self.build_config.CLANG_VERSION, 'lib'), lib_file) os.remove(static_library) - self.check_rm_tree(os.path.join(clang_mingw_dir, 'clang-10.0.1', 'include')) + self.check_rm_tree(os.path.join(clang_mingw_dir, 'clang-%s' % self.build_config.CLANG_VERSION, 'include')) package_path = '%s%s' % (self.merge_out_path(package_name), '.tar.bz2') self.logger().info('Packaging %s', package_path) toolchain_name = 'clang-%s' % self.build_config.build_name - self.check_copy_tree(os.path.join(clang_mingw_dir, 'clang-10.0.1'), + self.check_copy_tree(os.path.join(clang_mingw_dir, 'clang-%s' % self.build_config.CLANG_VERSION), os.path.join(clang_mingw_dir, toolchain_name)) args = ['tar', '-cjC', clang_mingw_dir, '-f', package_path, toolchain_name] self.check_call(args) diff --git a/llvm-build/build_cpython-mingw.sh b/llvm-build/build_cpython-mingw.sh index 570741b720bc..7419458cc7d9 100755 --- a/llvm-build/build_cpython-mingw.sh +++ b/llvm-build/build_cpython-mingw.sh @@ -23,8 +23,9 @@ cd ${CPYTHON_MINGW_BUILD} MINGW_PREFIX=${CPYTHON_MINGW_BUILD}/mingw64 MINGW_CHOST=x86_64-w64-mingw32 MINGW_BUILD=x86_64-unknown-linux-gnu -TOOLCHAIN_ROOT=${CLANG_MINGW_BUILD}/clang-10.0.1/bin -SYSROOT=${CLANG_MINGW_BUILD}/clang-10.0.1/x86_64-w64-mingw32 +CLANG_VERSION=clang-10.0.1 +TOOLCHAIN_ROOT=${CLANG_MINGW_BUILD}/${CLANG_VERSION}/bin +SYSROOT=${CLANG_MINGW_BUILD}/${CLANG_VERSION}/x86_64-w64-mingw32 mkdir $MINGW_BUILD export CC=$TOOLCHAIN_ROOT/clang diff --git a/llvm-build/env_prepare.sh b/llvm-build/env_prepare.sh index acfc3d247f5d..552fbdba4772 100755 --- a/llvm-build/env_prepare.sh +++ b/llvm-build/env_prepare.sh @@ -59,6 +59,7 @@ prebuilts/clang/ohos/${host_platform}-${host_cpu},https://mirrors.huaweicloud.co prebuilts/clang/ohos/${host_platform}-${host_cpu},https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.1/clang+llvm-10.0.1-x86_64-linux-gnu-ubuntu-16.04.tar.xz """ + copy_config_darwin_x86_64=""" prebuilts/cmake,https://mirrors.huaweicloud.com/harmonyos/compiler/cmake/3.16.5/${host_platform}/cmake-${host_platform}-x86-3.16.5.tar.gz prebuilts/clang/ohos/${host_platform}-${host_cpu},https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz diff --git a/llvm-build/mingw.py b/llvm-build/mingw.py index 8b73bca1749a..2ab852afb2cd 100755 --- a/llvm-build/mingw.py +++ b/llvm-build/mingw.py @@ -25,9 +25,10 @@ import sys class BuildConfig(): def __init__(self): + self.CLANG_VERSION = '10.0.1' self.THIS_DIR = os.path.realpath(os.path.dirname(__file__)) self.OUT_DIR = os.environ.get('OUT_DIR', self.repo_root('out')) - self.MINGW_DIR = self.out_root('clang_mingw', 'clang-10.0.1', 'x86_64-w64-mingw32') + self.MINGW_DIR = self.out_root('clang_mingw', 'clang-%s' % self.CLANG_VERSION, 'x86_64-w64-mingw32') def repo_root(self, *args): return os.path.realpath(os.path.join(self.THIS_DIR, '../../', *args)) @@ -53,14 +54,14 @@ class LlvmMingw(): self.CMAKE_BIN_PATH = os.path.join(self.cmake_prebuilt_bin_dir(), 'cmake') self.NINJA_BIN_PATH = os.path.join(self.cmake_prebuilt_bin_dir(), 'ninja') - self.CLANG_PATH = self.build_config.out_root('clang_mingw', 'clang-10.0.1') + self.CLANG_PATH = self.build_config.out_root('clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION) self.LLVM_CONFIG = os.path.join(self.CLANG_PATH, 'bin', 'llvm-config') - self.SYSROOT = self.build_config.out_root('clang_mingw', 'clang-10.0.1', 'x86_64-w64-mingw32') + self.SYSROOT = self.build_config.out_root('clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION, 'x86_64-w64-mingw32') self.LLVM_TRIPLE = 'x86_64-windows-gnu' # out path self.CRT_PATH = self.build_config.out_root('clang_mingw', 'lib', 'clangrt-%s' % self.LLVM_TRIPLE) # install path - self.CRT_INSTALL = self.build_config.out_root('clang_mingw', 'clang-10.0.1', 'lib', 'clang', '10.0.1') + self.CRT_INSTALL = self.build_config.out_root('clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION, 'lib', 'clang', self.build_config.CLANG_VERSION) # prefix & env self.prefix = build_config.mingw64_dir() common_flags = "-target x86_64-w64-mingw32 -rtlib=compiler-rt \ @@ -116,7 +117,7 @@ class LlvmMingw(): self.crt_defines['CMAKE_C_COMPILER'] = cc self.crt_defines['CMAKE_CXX_COMPILER'] = cxx self.crt_defines['LLVM_CONFIG_PATH'] = self.LLVM_CONFIG - clang_libcxx_lib = self.build_config.out_root('clang_mingw', 'clang-10.0.1', 'lib') + clang_libcxx_lib = self.build_config.out_root('clang_mingw', 'clang-%s' % self.build_config.CLANG_VERSION, 'lib') ldflags = [ '-L%s' % clang_libcxx_lib, '-fuse-ld=lld', @@ -197,17 +198,17 @@ class LlvmMingw(): if os.path.isdir(clang_mingw_dir): shutil.rmtree(clang_mingw_dir) os.makedirs(clang_mingw_dir) - shutil.copytree(self.build_config.repo_root('prebuilts/clang/ohos/linux-x86_64/clang-10.0.1'), - '%s/clang-10.0.1' % clang_mingw_dir) + shutil.copytree(self.build_config.repo_root('prebuilts/clang/ohos/linux-x86_64/clang-%s' % self.build_config.CLANG_VERSION), + '%s/clang-%s' % (clang_mingw_dir, self.build_config.CLANG_VERSION)) # Replace clang binaries to avoid dependency on libtinfo # TODO: Use `prebuilts/clang/ohos/linux-x86_64/llvm` instead of # `prebuilts/clang/ohos/linux-x86_64/clang-10.0.1` shutil.copy(self.build_config.repo_root('prebuilts/clang/ohos/linux-x86_64/llvm/bin/clang'), - '%s/clang-10.0.1/bin/clang' % clang_mingw_dir) + '%s/clang-%s/bin/clang' % (clang_mingw_dir, self.build_config.CLANG_VERSION)) shutil.copy(self.build_config.repo_root('prebuilts/clang/ohos/linux-x86_64/llvm/bin/clang++'), - '%s/clang-10.0.1/bin/clang++' % clang_mingw_dir) + '%s/clang-%s/bin/clang++' % (clang_mingw_dir, self.build_config.CLANG_VERSION)) shutil.copy(self.build_config.repo_root('prebuilts/clang/ohos/linux-x86_64/llvm/bin/clang-10'), - '%s/clang-10.0.1/bin/clang-10' % clang_mingw_dir) + '%s/clang-%s/bin/clang-10' % (clang_mingw_dir, self.build_config.CLANG_VERSION)) def build_mingw64_headers(self): headers_dir = self.build_config.repo_root('third_party', 'mingw-w64', 'mingw-w64-headers', 'build') -- Gitee From d377ab4ea3888e2224ed0fd704b1ccc43a96eccc Mon Sep 17 00:00:00 2001 From: JinuineLi Date: Wed, 13 Jul 2022 14:58:28 +0800 Subject: [PATCH 7/9] feat: add OpenHarmony Checkers UnixAPIArgsChecker: checks open() system call args MemcpyChecker: checks memcpy_s() system call args Signed-off-by: Hongjin Li Change-Id: Ib29befb50a720e0a0a9c097df61135b107c9bbaa --- .../clang/StaticAnalyzer/Checkers/Checkers.td | 16 ++ .../StaticAnalyzer/Checkers/CMakeLists.txt | 2 + .../Checkers/OpenHarmony/MemcpyChecker.cpp | 112 ++++++++ .../OpenHarmony/UnixAPIArgsChecker.cpp | 239 ++++++++++++++++++ clang/test/Analysis/memcpy_s.c | 51 ++++ clang/test/Analysis/unix-api.c | 26 ++ 6 files changed, 446 insertions(+) create mode 100644 clang/lib/StaticAnalyzer/Checkers/OpenHarmony/MemcpyChecker.cpp create mode 100644 clang/lib/StaticAnalyzer/Checkers/OpenHarmony/UnixAPIArgsChecker.cpp create mode 100644 clang/test/Analysis/memcpy_s.c diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td index 444b00d73f0b..7ba490e62456 100644 --- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td +++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td @@ -119,6 +119,8 @@ def FuchsiaAlpha : Package<"fuchsia">, ParentPackage; def WebKit : Package<"webkit">; def WebKitAlpha : Package<"webkit">, ParentPackage; +def OpenHarmony : Package<"openharmony">; + //===----------------------------------------------------------------------===// // Core Checkers. //===----------------------------------------------------------------------===// @@ -1673,3 +1675,17 @@ def UncountedLocalVarsChecker : Checker<"UncountedLocalVarsChecker">, Documentation; } // end alpha.webkit + +//===----------------------------------------------------------------------===// +// OpenHarmony checkers. +//===----------------------------------------------------------------------===// + +let ParentPackage = OpenHarmony in { +def UnixAPIArgsChecker : Checker<"UnixAPIArgs">, + HelpText<"Check for open unix api arguments">, + Documentation; + +def MemcpyChecker : Checker<"Memcpy">, + HelpText<"Check for memcpy_s api arguments">, + Documentation; +} diff --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt index eb4f30137732..2a63b9446dcc 100644 --- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt +++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt @@ -129,6 +129,8 @@ add_clang_library(clangStaticAnalyzerCheckers WebKit/UncountedCallArgsChecker.cpp WebKit/UncountedLambdaCapturesChecker.cpp WebKit/UncountedLocalVarsChecker.cpp + OpenHarmony/UnixAPIArgsChecker.cpp + OpenHarmony/MemcpyChecker.cpp LINK_LIBS clangAST diff --git a/clang/lib/StaticAnalyzer/Checkers/OpenHarmony/MemcpyChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/OpenHarmony/MemcpyChecker.cpp new file mode 100644 index 000000000000..0f80e0e458e0 --- /dev/null +++ b/clang/lib/StaticAnalyzer/Checkers/OpenHarmony/MemcpyChecker.cpp @@ -0,0 +1,112 @@ +//== MemcpyChecker.cpp ------------------------------*- C++ -*--==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines MemcpyChecker, which is a path-sensitive check +// looking for mismatch src and dest buffer length may cause buffer overflow. +// +//===----------------------------------------------------------------------===// + +#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" +#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" +#include "clang/StaticAnalyzer/Core/Checker.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h" + +using namespace clang; +using namespace ento; + +namespace { +class MemcpyChecker : public Checker { + CallDescription MemcpyS; + + std::unique_ptr OverflowBugType; +public: + MemcpyChecker(); + void checkPreCall(const CallEvent &Call, CheckerContext &C) const; +}; + +MemcpyChecker::MemcpyChecker() + : MemcpyS("memcpy_s") { + OverflowBugType.reset( + new BugType(this, "Unsafe buffer operation", categories::UnixAPI)); + } + +void MemcpyChecker::checkPreCall(const CallEvent &Call, CheckerContext &C) const { + if (!Call.isCalled(MemcpyS)) { + return; + } + + SValBuilder &SVB = C.getSValBuilder(); + ProgramStateRef state = C.getState(); + SVal dstAddrSVal = Call.getArgSVal(0); + SVal srcLengthSVal = Call.getArgSVal(3); + + const MemRegion *dstAddrMR = dstAddrSVal.getAsRegion(); + if (!dstAddrMR) { + return; + } + + const ElementRegion *dstAddrER = dyn_cast(dstAddrMR); + if (!dstAddrER) { + return; + } + + DefinedOrUnknownSVal Idx = dstAddrER->getIndex().castAs(); + Optional IdxSVal = Idx.getAs(); + if (!IdxSVal) { + return; + } + + DefinedOrUnknownSVal ElementCount = getDynamicElementCount( + state, dstAddrER->getSuperRegion(), C.getSValBuilder(), dstAddrER->getValueType()); + + Optional dstAddrLenSVal = ElementCount.getAs(); + if (!dstAddrLenSVal) { + return; + } + + Optional srcLengthDSVal = srcLengthSVal.getAs(); + if (!srcLengthDSVal) { + return; + } + + SVal srcLenDSval = SVB.evalBinOp(state, BO_Add, *srcLengthDSVal, *IdxSVal, SVB.getArrayIndexType()); + + SVal dstLessThanSrcLength = SVB.evalBinOp(state, BO_LT, *dstAddrLenSVal, srcLenDSval, SVB.getConditionType()); + + Optional dstLessThanSrcLengthDVal = dstLessThanSrcLength.getAs(); + if (!dstLessThanSrcLengthDVal) { + return; + } + + if (state->assume(*dstLessThanSrcLengthDVal, true)) { + // it is possible that dst less than src length + ExplodedNode *ErrNode = C.generateNonFatalErrorNode(); + // If we've already reached this node on another path, return. + if (!ErrNode) + return; + + // Generate the report. + auto R = std::make_unique( + *OverflowBugType, "memcpy_s(): src length may be larger than dst length", ErrNode); + R->addRange(Call.getSourceRange()); + C.emitReport(std::move(R)); + return; + } +} +} + +void ento::registerMemcpyChecker(CheckerManager &mgr) { + mgr.registerChecker(); +} + +// This checker should be enabled regardless of how language options are set. +bool ento::shouldRegisterMemcpyChecker(const CheckerManager &mgr) { + return true; +} diff --git a/clang/lib/StaticAnalyzer/Checkers/OpenHarmony/UnixAPIArgsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/OpenHarmony/UnixAPIArgsChecker.cpp new file mode 100644 index 000000000000..c4747fcdfe33 --- /dev/null +++ b/clang/lib/StaticAnalyzer/Checkers/OpenHarmony/UnixAPIArgsChecker.cpp @@ -0,0 +1,239 @@ +//== UnixAPIArgsChecker.cpp ------------------------------*- C++ -*--==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This defines UnixAPIArgsChecker, which is a path-sensitive checker +// looking for open a file with open() with GROUP and OTHER having +// write or execute permission +// +//===----------------------------------------------------------------------===// + +#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" +#include "clang/Basic/TargetInfo.h" +#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" +#include "clang/StaticAnalyzer/Core/Checker.h" +#include "clang/StaticAnalyzer/Core/CheckerManager.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/Support/raw_ostream.h" + +using namespace clang; +using namespace ento; + +enum class OpenVariant { + /// The standard open() call: + /// int open(const char *pathname, int flags, mode_t mode); + Open, + + /// The variant taking a directory file descriptor and a relative path: + /// int openat(int fd, const char *pathname, int flags, mode_t mode); + OpenAt +}; + +namespace { +class UnixAPIArgsChecker : public Checker< check::PreStmt > { + mutable std::unique_ptr BT_open; + // value of O_CREAT flag + const uint64_t Val_O_CREAT = 0100; + // value of mode being checked + const uint64_t Val_MODE = 0133; + +public: + void checkPreStmt(const CallExpr *CE, CheckerContext &C) const; + + void CheckOpen(CheckerContext &C, const CallExpr *CE) const; + void CheckOpenAt(CheckerContext &C, const CallExpr *CE) const; + + void CheckOpenVariant(CheckerContext &C, + const CallExpr *CE, OpenVariant Variant) const; + + void ReportOpenBug(CheckerContext &C, + ProgramStateRef State, + const char *Msg, + SourceRange SR) const; +}; +} //end anonymous namespace + +static void LazyInitialize(const CheckerBase *Checker, + std::unique_ptr &BT, + const char *name) { + if (BT) + return; + BT.reset(new BugType(Checker, name, categories::UnixAPI)); +} + +//===----------------------------------------------------------------------===// +// "open" (man 2 open) +//===----------------------------------------------------------------------===/ + +void UnixAPIArgsChecker::checkPreStmt(const CallExpr *CE, + CheckerContext &C) const { + const FunctionDecl *FD = C.getCalleeDecl(CE); + if (!FD || FD->getKind() != Decl::Function) + return; + + // Don't treat functions in namespaces with the same name a Unix function + // as a call to the Unix function. + const DeclContext *NamespaceCtx = FD->getEnclosingNamespaceContext(); + if (NamespaceCtx && isa(NamespaceCtx)) + return; + + StringRef FName = C.getCalleeName(FD); + if (FName.empty()) + return; + + if (FName == "open") + CheckOpen(C, CE); + + else if (FName == "openat") + CheckOpenAt(C, CE); +} +void UnixAPIArgsChecker::ReportOpenBug(CheckerContext &C, + ProgramStateRef State, + const char *Msg, + SourceRange SR) const { + ExplodedNode *N = C.generateErrorNode(State); + if (!N) + return; + + LazyInitialize(this, BT_open, "Improper use of 'open'"); + + auto Report = std::make_unique(*BT_open, Msg, N); + Report->addRange(SR); + C.emitReport(std::move(Report)); +} + +void UnixAPIArgsChecker::CheckOpen(CheckerContext &C, + const CallExpr *CE) const { + CheckOpenVariant(C, CE, OpenVariant::Open); +} + +void UnixAPIArgsChecker::CheckOpenAt(CheckerContext &C, + const CallExpr *CE) const { + CheckOpenVariant(C, CE, OpenVariant::OpenAt); +} + +void UnixAPIArgsChecker::CheckOpenVariant(CheckerContext &C, + const CallExpr *CE, + OpenVariant Variant) const { + // The index of the argument taking the flags open flags (O_RDONLY, + // O_WRONLY, O_CREAT, etc.), + unsigned int FlagsArgIndex; + switch (Variant) { + case OpenVariant::Open: + FlagsArgIndex = 1; + break; + case OpenVariant::OpenAt: + FlagsArgIndex = 2; + break; + }; + + // All calls should at least provide arguments up to the 'flags' parameter. + unsigned int MinArgCount = FlagsArgIndex + 1; + + // If the flags has O_CREAT set then open/openat() require an additional + // argument specifying the file mode (permission bits) for the created file. + unsigned int CreateModeArgIndex = FlagsArgIndex + 1; + + // The create mode argument should be the last argument. + unsigned int MaxArgCount = CreateModeArgIndex + 1; + + ProgramStateRef state = C.getState(); + + // Checked via UnixAPIChecker + if (CE->getNumArgs() < MinArgCount || CE->getNumArgs() > MaxArgCount) { + return; + } else if (CE->getNumArgs() == MaxArgCount) { + const Expr *Arg = CE->getArg(CreateModeArgIndex); + QualType QT = Arg->getType(); + if (!QT->isIntegerType()) { + return; + } + } + + // Now check if oflags has O_CREAT set. + const Expr *oflagsEx = CE->getArg(FlagsArgIndex); + const SVal V = C.getSVal(oflagsEx); + if (!V.getAs()) { + // The case where 'V' can be a location can only be due to a bad header, + // so in this case bail out. + return; + } + NonLoc oflags = V.castAs(); + NonLoc ocreateFlag = C.getSValBuilder() + .makeIntVal(Val_O_CREAT, oflagsEx->getType()).castAs(); + SVal maskedFlagsUC = C.getSValBuilder().evalBinOpNN(state, BO_And, + oflags, ocreateFlag, + oflagsEx->getType()); + if (maskedFlagsUC.isUnknownOrUndef()) + return; + DefinedSVal maskedFlags = maskedFlagsUC.castAs(); + + // Check if maskedFlags is non-zero. + ProgramStateRef trueState, falseState; + std::tie(trueState, falseState) = state->assume(maskedFlags); + + // Only emit an error if the value of 'maskedFlags' is properly + // constrained; + if (!(trueState && !falseState)) + return; + + if (CE->getNumArgs() < MaxArgCount) { + return; + } + + // Now check mode when O_CREAT flag is set, GROUP and OTHER should not + // have write or execute permission + const Expr *createModeEx = CE->getArg(CreateModeArgIndex); + const SVal CM = C.getSVal(createModeEx); + if (!CM.getAs()) { + return; + } + NonLoc createMode = CM.castAs(); + NonLoc createModeCheck = C.getSValBuilder(). + makeIntVal(Val_MODE, createModeEx->getType()).castAs(); + + SVal maskedCreateMode = C.getSValBuilder().evalBinOpNN(state, BO_And, + createMode, createModeCheck, + createModeEx->getType()); + if (maskedCreateMode.isUnknownOrUndef()) + return; + DefinedSVal maskedCreateModeSVal = maskedCreateMode.castAs(); + + // Check if maskedFlags is non-zero. + ProgramStateRef t, f; + std::tie(t, f) = state->assume(maskedCreateModeSVal); + + // Only emit an error if the value of 'maskedFlags' is properly + // constrained; + if (t && !f) { + SmallString<256> SBuf; + llvm::raw_svector_ostream OS(SBuf); + OS << "Open() system call, GROUP/OTHER should not have write or execute permission"; + ReportOpenBug(C, t, + SBuf.c_str(), + createModeEx->getSourceRange()); + } +} + +//===----------------------------------------------------------------------===// +// Registration. +//===----------------------------------------------------------------------===// + +#define REGISTER_CHECKER(CHECKERNAME) \ + void ento::register##CHECKERNAME(CheckerManager &mgr) { \ + mgr.registerChecker(); \ + } \ + \ + bool ento::shouldRegister##CHECKERNAME(const CheckerManager &mgr) { \ + return true; \ + } + +REGISTER_CHECKER(UnixAPIArgsChecker) diff --git a/clang/test/Analysis/memcpy_s.c b/clang/test/Analysis/memcpy_s.c new file mode 100644 index 000000000000..e040e181bd90 --- /dev/null +++ b/clang/test/Analysis/memcpy_s.c @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +//===----------------------------------------------------------------------===// + +#define __STDC_WANT_LIB_EXT1__ 1 +#include +#include +#include +#include +#include + +int memcpy_s(char *dst, int dstLen, char *src, int srcLen) { + return dstLen; +} + +void check1(int dstLen, int srcLen) { + char dstStr[dstLen]; + char srcStr[srcLen]; + memcpy_s(dstStr, sizeof(dstStr), srcStr, srcLen); // expected-warning{{src length may be larger than dst length}} +} + +void check2() { + int dstLen = 20; + int srcLen = 10; + char dstStr[dstLen]; + char srcStr[srcLen]; + memcpy_s(dstStr, sizeof(dstStr), srcStr, srcLen); // no-warning +} + +void check3() { + int dstLen = 10; + int srcLen = 20; + char dstStr[dstLen]; + char srcStr[srcLen]; + memcpy_s(dstStr, sizeof(dstStr), srcStr, srcLen); // expected-warning{{src length may be larger than dst length}} +} + +void check4() { + int dstLen = 20; + int srcLen = 10; + char dstStr[dstLen]; + char srcStr[srcLen]; + int offset = 15; + // srcLen > dstStr[offset]'s length, bug reported + memcpy_s(&dstStr[offset], srcLen, srcStr, srcLen); // expected-warning{{src length may be larger than dst length}} + offset = 5; + // srcLen < dstStr[offset]'s length, no bug reported + memcpy_s(&dstStr[offset], srcLen, srcStr, srcLen); // no-warning +} diff --git a/clang/test/Analysis/unix-api.c b/clang/test/Analysis/unix-api.c index 64ff3c0fccf4..722702fc0c89 100644 --- a/clang/test/Analysis/unix-api.c +++ b/clang/test/Analysis/unix-api.c @@ -1,9 +1,19 @@ +//===----------------------------------------------------------------------===// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +//===----------------------------------------------------------------------===// + // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.API -verify %s #ifndef O_RDONLY #define O_RDONLY 0 #endif +#ifndef O_CREAT +#define O_CREAT 0100 +#endif + #ifndef NULL #define NULL ((void*) 0) #endif @@ -90,3 +100,19 @@ void open_8(const char *path) { if (fd > -1) close(fd); } + +void open_9(const char *path) { + int fd; + int mode = 0631; + fd = open(path, O_CREAT, mode); // expected-warning{{Open() system call, GROUP/OTHER should not have write or execute permission}} + if (fd > -1) + close(fd); +} + +void open_10(const char *path) { + int fd; + int mode = 0644; + fd = open(path, O_CREAT, mode); // no-warning + if (fd > -1) + close(fd); +} \ No newline at end of file -- Gitee From 81e3157e2194e55794bf1ed749c24f71b3769daf Mon Sep 17 00:00:00 2001 From: hhj Date: Tue, 9 Aug 2022 11:48:06 +0800 Subject: [PATCH 8/9] fixed 44c508e from https://gitee.com/huanghuijin/third_party_llvm-project/pulls/40 Use emulated-tls for ohos build For ie/le compatibility reasons, use the emulated-tls as the default TLS implementation for ohos target. If want to change diable emulated tls, pls use -fno-emulated-tls options. TEST: llvm CodeGen/santizer test case Signed-off-by: hhj --- compiler-rt/lib/asan/asan_fake_stack.cpp | 2 +- compiler-rt/lib/lsan/lsan_common.h | 3 ++- .../sanitizer_platform_interceptors.h | 2 +- llvm/include/llvm/ADT/Triple.h | 2 +- llvm/test/CodeGen/AArch64/emutls.ll | 4 ++++ llvm/test/CodeGen/AArch64/emutls_generic.ll | 12 ++++++++++++ llvm/test/CodeGen/ARM/emutls.ll | 4 ++++ llvm/test/CodeGen/ARM/emutls_generic.ll | 4 ++++ llvm/test/CodeGen/X86/emutls-pic.ll | 4 ++++ llvm/test/CodeGen/X86/emutls-pie.ll | 8 ++++++++ llvm/test/CodeGen/X86/emutls.ll | 4 ++++ llvm/test/CodeGen/X86/emutls_generic.ll | 12 ++++++++++++ 12 files changed, 57 insertions(+), 4 deletions(-) diff --git a/compiler-rt/lib/asan/asan_fake_stack.cpp b/compiler-rt/lib/asan/asan_fake_stack.cpp index 295e6debc96c..959a61b09d60 100644 --- a/compiler-rt/lib/asan/asan_fake_stack.cpp +++ b/compiler-rt/lib/asan/asan_fake_stack.cpp @@ -170,7 +170,7 @@ void FakeStack::ForEachFakeFrame(RangeIteratorCallback callback, void *arg) { } } -#if (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_FUCHSIA +#if (SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_OHOS) || SANITIZER_FUCHSIA static THREADLOCAL FakeStack *fake_stack_tls; FakeStack *GetTLSFakeStack() { diff --git a/compiler-rt/lib/lsan/lsan_common.h b/compiler-rt/lib/lsan/lsan_common.h index 3c65d9df225e..bc4ad44eb748 100644 --- a/compiler-rt/lib/lsan/lsan_common.h +++ b/compiler-rt/lib/lsan/lsan_common.h @@ -31,7 +31,8 @@ // the new architecture inside the sanitizer library. // Exclude leak-detection on arm32 for Android because `__aeabi_read_tp` // is missing. This caused a link error. -#if (SANITIZER_ANDROID && (__ANDROID_API__ < 28 || defined(__arm__))) +#if SANITIZER_OHOS || \ +(SANITIZER_ANDROID && (__ANDROID_API__ < 28 || defined(__arm__))) #define CAN_SANITIZE_LEAKS 0 #elif (SANITIZER_LINUX || SANITIZER_MAC) && (SANITIZER_WORDSIZE == 64) && \ (defined(__x86_64__) || defined(__mips64) || defined(__aarch64__) || \ diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index 70e8a2c197fa..f53e9b9f27e8 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -413,7 +413,7 @@ (SI_FREEBSD || SI_NETBSD || SI_GLIBC || SI_SOLARIS) #define SANITIZER_INTERCEPT_TLS_GET_ADDR \ - (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) + (SI_FREEBSD || SI_NETBSD || (SI_LINUX_NOT_ANDROID && !SI_OHOS) || SI_SOLARIS) #define SANITIZER_INTERCEPT_LISTXATTR SI_LINUX #define SANITIZER_INTERCEPT_GETXATTR SI_LINUX diff --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h index 183ac3787fdc..cfda6ad94281 100644 --- a/llvm/include/llvm/ADT/Triple.h +++ b/llvm/include/llvm/ADT/Triple.h @@ -821,7 +821,7 @@ public: /// Tests whether the target uses emulated TLS as default. bool hasDefaultEmulatedTLS() const { - return isAndroid() || isOSOpenBSD() || isWindowsCygwinEnvironment(); + return isOpenHOS() || isAndroid() || isOSOpenBSD() || isWindowsCygwinEnvironment(); } /// Tests whether the target uses -data-sections as default. diff --git a/llvm/test/CodeGen/AArch64/emutls.ll b/llvm/test/CodeGen/AArch64/emutls.ll index 25be391bbfaa..918eb75bc7bd 100644 --- a/llvm/test/CodeGen/AArch64/emutls.ll +++ b/llvm/test/CodeGen/AArch64/emutls.ll @@ -2,6 +2,10 @@ ; RUN: -relocation-model=pic -frame-pointer=all < %s | FileCheck -check-prefix=ARM64 %s ; RUN: llc -mtriple=aarch64-linux-android \ ; RUN: -relocation-model=pic -frame-pointer=all < %s | FileCheck -check-prefix=ARM64 %s +; RUN: llc -emulated-tls -mtriple=aarch64-linux-ohos \ +; RUN: -relocation-model=pic -frame-pointer=all < %s | FileCheck -check-prefix=ARM64 %s +; RUN: llc -mtriple=aarch64-linux-ohos \ +; RUN: -relocation-model=pic -frame-pointer=all < %s | FileCheck -check-prefix=ARM64 %s ; Copied from X86/emutls.ll diff --git a/llvm/test/CodeGen/AArch64/emutls_generic.ll b/llvm/test/CodeGen/AArch64/emutls_generic.ll index 840833972881..6b5819a7fc4e 100644 --- a/llvm/test/CodeGen/AArch64/emutls_generic.ll +++ b/llvm/test/CodeGen/AArch64/emutls_generic.ll @@ -8,6 +8,12 @@ ; RUN: | FileCheck -check-prefix=ARM_64 %s ; RUN: llc < %s -emulated-tls -mtriple=aarch64-apple-darwin -O3 \ ; RUN: | FileCheck -check-prefix=DARWIN %s +; RUN: llc < %s -emulated-tls -mtriple=aarch64-linux-ohos -relocation-model=pic \ +; RUN: | FileCheck -check-prefix=ARM_64 %s +; RUN: llc < %s -emulated-tls -mtriple=aarch64-linux-ohos -relocation-model=pic -O3 \ +; RUN: | FileCheck -check-prefix=ARM_64 %s +; RUN: llc < %s -emulated-tls -mtriple=aarch64-linux-ohos -O3 \ +; RUN: | FileCheck -check-prefix=ARM_64 %s ; RUN: llc < %s -mtriple=aarch64-linux-android -relocation-model=pic \ ; RUN: | FileCheck -check-prefix=ARM_64 %s @@ -18,6 +24,12 @@ ; aarch64-windows-gnu needs explicit -emulated-tls ; RUN: llc < %s -mtriple=aarch64-apple-darwin -O3 \ ; RUN: | FileCheck -check-prefix=NoEMU %s +; RUN: llc < %s -mtriple=aarch64-linux-ohos -relocation-model=pic \ +; RUN: | FileCheck -check-prefix=ARM_64 %s +; RUN: llc < %s -mtriple=aarch64-linux-ohos -relocation-model=pic -O3 \ +; RUN: | FileCheck -check-prefix=ARM_64 %s +; RUN: llc < %s -mtriple=aarch64-linux-ohos -O3 \ +; RUN: | FileCheck -check-prefix=ARM_64 %s ; NoEMU-NOT: __emutls diff --git a/llvm/test/CodeGen/ARM/emutls.ll b/llvm/test/CodeGen/ARM/emutls.ll index 92b656d9ba09..29894a9efa7b 100644 --- a/llvm/test/CodeGen/ARM/emutls.ll +++ b/llvm/test/CodeGen/ARM/emutls.ll @@ -2,6 +2,10 @@ ; RUN: -relocation-model=pic < %s | FileCheck -check-prefix=ARM32 %s ; RUN: llc -mtriple=arm-linux-android \ ; RUN: -relocation-model=pic < %s | FileCheck -check-prefix=ARM32 %s +; RUN: llc -emulated-tls -mtriple=arm-linux-ohos \ +; RUN: -relocation-model=pic < %s | FileCheck -check-prefix=ARM32 %s +; RUN: llc -mtriple=arm-linux-ohos \ +; RUN: -relocation-model=pic < %s | FileCheck -check-prefix=ARM32 %s ; Copied from X86/emutls.ll diff --git a/llvm/test/CodeGen/ARM/emutls_generic.ll b/llvm/test/CodeGen/ARM/emutls_generic.ll index 8bf0ab301244..803462740f79 100644 --- a/llvm/test/CodeGen/ARM/emutls_generic.ll +++ b/llvm/test/CodeGen/ARM/emutls_generic.ll @@ -10,6 +10,8 @@ ; RUN: | FileCheck -check-prefix=DARWIN %s ; RUN: llc < %s -emulated-tls -mtriple=thumbv7-windows-gnu -O3 \ ; RUN: | FileCheck -check-prefix=WIN %s +; RUN: llc < %s -emulated-tls -mtriple=arm-linux-ohos -relocation-model=pic \ +; RUN: | FileCheck -check-prefix=ARM_32 %s ; RUN: llc < %s -mtriple=arm-linux-android -relocation-model=pic \ ; RUN: | FileCheck -check-prefix=ARM_32 %s @@ -21,6 +23,8 @@ ; RUN: | FileCheck -check-prefix=ARM_32 %s ; arm-apple-darwin must use -emulated-tls ; windows must use -emulated-tls +; RUN: llc < %s -mtriple=arm-linux-ohos -relocation-model=pic \ +; RUN: | FileCheck -check-prefix=ARM_32 %s ; Make sure that TLS symbols are emitted in expected order. diff --git a/llvm/test/CodeGen/X86/emutls-pic.ll b/llvm/test/CodeGen/X86/emutls-pic.ll index 66f226a8bd5a..b265bb6517c3 100644 --- a/llvm/test/CodeGen/X86/emutls-pic.ll +++ b/llvm/test/CodeGen/X86/emutls-pic.ll @@ -2,11 +2,15 @@ ; RUN: llc < %s -emulated-tls -mtriple=x86_64-linux-gnu -relocation-model=pic | FileCheck -check-prefix=X64 %s ; RUN: llc < %s -emulated-tls -mtriple=i386-linux-android -relocation-model=pic | FileCheck -check-prefix=X86 %s ; RUN: llc < %s -emulated-tls -mtriple=x86_64-linux-android -relocation-model=pic | FileCheck -check-prefix=X64 %s +; RUN: llc < %s -emulated-tls -mtriple=i386-linux-ohos -relocation-model=pic | FileCheck -check-prefix=X86 %s +; RUN: llc < %s -emulated-tls -mtriple=x86_64-linux-ohos -relocation-model=pic | FileCheck -check-prefix=X64 %s ; RUN: llc < %s -mtriple=i386-linux-gnu -relocation-model=pic | FileCheck -check-prefix=NoEMU %s ; RUN: llc < %s -mtriple=x86_64-linux-gnu -relocation-model=pic | FileCheck -check-prefix=NoEMU %s ; RUN: llc < %s -mtriple=i386-linux-android -relocation-model=pic | FileCheck -check-prefix=X86 %s ; RUN: llc < %s -mtriple=x86_64-linux-android -relocation-model=pic | FileCheck -check-prefix=X64 %s +; RUN: llc < %s -mtriple=i386-linux-ohos -relocation-model=pic | FileCheck -check-prefix=X86 %s +; RUN: llc < %s -mtriple=x86_64-linux-ohos -relocation-model=pic | FileCheck -check-prefix=X64 %s ; NoEMU-NOT: __emutls diff --git a/llvm/test/CodeGen/X86/emutls-pie.ll b/llvm/test/CodeGen/X86/emutls-pie.ll index 38f0c245bee6..40945a37ab57 100644 --- a/llvm/test/CodeGen/X86/emutls-pie.ll +++ b/llvm/test/CodeGen/X86/emutls-pie.ll @@ -6,6 +6,10 @@ ; RUN: | FileCheck -check-prefix=X86 %s ; RUN: llc < %s -emulated-tls -mcpu=generic -mtriple=x86_64-linux-android -relocation-model=pic \ ; RUN: | FileCheck -check-prefix=X64 %s +; RUN: llc < %s -emulated-tls -mcpu=generic -mtriple=i386-linux-ohos -relocation-model=pic \ +; RUN: | FileCheck -check-prefix=X86 %s +; RUN: llc < %s -emulated-tls -mcpu=generic -mtriple=x86_64-linux-ohos -relocation-model=pic \ +; RUN: | FileCheck -check-prefix=X64 %s ; RUN: llc < %s -mcpu=generic -mtriple=i386-linux-gnu -relocation-model=pic \ ; RUN: | FileCheck -check-prefix=NoEMU %s @@ -15,6 +19,10 @@ ; RUN: | FileCheck -check-prefix=X86 %s ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-android -relocation-model=pic \ ; RUN: | FileCheck -check-prefix=X64 %s +; RUN: llc < %s -mcpu=generic -mtriple=i386-linux-ohos -relocation-model=pic \ +; RUN: | FileCheck -check-prefix=X86 %s +; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-ohos -relocation-model=pic \ +; RUN: | FileCheck -check-prefix=X64 %s ; NoEMU-NOT: __emutls diff --git a/llvm/test/CodeGen/X86/emutls.ll b/llvm/test/CodeGen/X86/emutls.ll index 7e567d287c61..7105f595221e 100644 --- a/llvm/test/CodeGen/X86/emutls.ll +++ b/llvm/test/CodeGen/X86/emutls.ll @@ -2,11 +2,15 @@ ; RUN: llc < %s -emulated-tls -mtriple=x86_64-linux-gnu | FileCheck -check-prefix=X64 %s ; RUN: llc < %s -emulated-tls -mtriple=i386-linux-android | FileCheck -check-prefix=X86 %s ; RUN: llc < %s -emulated-tls -mtriple=x86_64-linux-android | FileCheck -check-prefix=X64 %s +; RUN: llc < %s -emulated-tls -mtriple=i386-linux-ohos | FileCheck -check-prefix=X86 %s +; RUN: llc < %s -emulated-tls -mtriple=x86_64-linux-ohos | FileCheck -check-prefix=X64 %s ; RUN: llc < %s -mtriple=i386-linux-gnu | FileCheck -check-prefix=NoEMU %s ; RUN: llc < %s -mtriple=x86_64-linux-gnu | FileCheck -check-prefix=NoEMU %s ; RUN: llc < %s -mtriple=i386-linux-android | FileCheck -check-prefix=X86 %s ; RUN: llc < %s -mtriple=x86_64-linux-android | FileCheck -check-prefix=X64 %s +; RUN: llc < %s -mtriple=i386-linux-ohos | FileCheck -check-prefix=X86 %s +; RUN: llc < %s -mtriple=x86_64-linux-ohos | FileCheck -check-prefix=X64 %s ; Copied from tls.ll; emulated TLS model is not implemented ; for *-pc-win32 and *-pc-windows targets yet. diff --git a/llvm/test/CodeGen/X86/emutls_generic.ll b/llvm/test/CodeGen/X86/emutls_generic.ll index 7fc6089b9077..9e61bc5924cf 100644 --- a/llvm/test/CodeGen/X86/emutls_generic.ll +++ b/llvm/test/CodeGen/X86/emutls_generic.ll @@ -6,6 +6,12 @@ ; RUN: | FileCheck -check-prefix=X86_64 %s ; RUN: llc < %s -emulated-tls -mtriple=i386-linux-gnu -relocation-model=pic \ ; RUN: | FileCheck %s +; RUN: llc < %s -emulated-tls -mtriple=i686-linux-ohos -relocation-model=pic \ +; RUN: | FileCheck -check-prefix=X86_32 %s +; RUN: llc < %s -emulated-tls -mtriple=i686-linux-ohos -relocation-model=pic \ +; RUN: | FileCheck -check-prefix=X86_32 %s +; RUN: llc < %s -emulated-tls -mtriple=x86_64-linux-ohos -relocation-model=pic \ +; RUN: | FileCheck -check-prefix=X86_64 %s ; RUN: llc < %s -mtriple=i686-linux-android -relocation-model=pic \ ; RUN: | FileCheck -check-prefix=X86_32 %s @@ -15,6 +21,12 @@ ; RUN: | FileCheck -check-prefix=X86_64 %s ; RUN: llc < %s -mtriple=i386-linux-gnu -relocation-model=pic \ ; RUN: | FileCheck -check-prefix=NoEMU %s +; RUN: llc < %s -mtriple=i686-linux-ohos -relocation-model=pic \ +; RUN: | FileCheck -check-prefix=X86_32 %s +; RUN: llc < %s -mtriple=i686-linux-ohos -relocation-model=pic \ +; RUN: | FileCheck -check-prefix=X86_32 %s +; RUN: llc < %s -mtriple=x86_64-linux-ohos -relocation-model=pic \ +; RUN: | FileCheck -check-prefix=X86_64 %s ; NoEMU-NOT: __emutls -- Gitee From 9cfa0ea19745b311eec3dd6aeb26c5c2ccfd774a Mon Sep 17 00:00:00 2001 From: Sukhikh Alexander Date: Thu, 1 Sep 2022 15:03:11 +0300 Subject: [PATCH 9/9] Add execution permission to ohos test helpers Signed-off-by: Sukhikh Alexander --- .../test/sanitizer_common/ohos_family_commands/ohos_common.py | 0 .../test/sanitizer_common/ohos_family_commands/ohos_compile.py | 0 .../test/sanitizer_common/ohos_family_commands/ohos_run.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_common.py mode change 100644 => 100755 compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_compile.py mode change 100644 => 100755 compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_run.py diff --git a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_common.py b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_common.py old mode 100644 new mode 100755 diff --git a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_compile.py b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_compile.py old mode 100644 new mode 100755 diff --git a/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_run.py b/compiler-rt/test/sanitizer_common/ohos_family_commands/ohos_run.py old mode 100644 new mode 100755 -- Gitee