登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
Gitee AI
NEW
我知道了
查看详情
登录
注册
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
11
Star
0
Fork
10
src-openEuler
/
libXt
代码
Issues
0
Pull Requests
1
Wiki
统计
流水线
服务
Gitee Pages
JavaDoc
PHPDoc
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
我知道了,不再自动展开
Pull Requests
/
详情
31
Add --enable-malloc0returnsnull when using clang to fix clang build error
草稿
严莹:yy-master
src-openEuler:master
严莹
创建于 2024-09-07 18:28
克隆/下载
HTTPS
SSH
复制
下载 Email Patch
下载 Diff 文件
- 本PR基于[这个oEEP](https://gitee.com/openeuler/TC/blob/master/oEEP/oEEP-0003%20LLVM%E5%B9%B3%E8%A1%8C%E5%AE%87%E5%AE%99%E8%AE%A1%E5%88%92--%E5%9F%BA%E4%BA%8ELLVM%E6%8A%80%E6%9C%AF%E6%A0%88%E6%9E%84%E5%BB%BAoE%E8%BD%AF%E4%BB%B6%E5%8C%85.md),旨在使得该软件包可以同时支持GCC和LLVM构建。 - 在修改前使用clang构建出现错误,软件包构建于check阶段失败: ``` + make check Making check in util make[1]: Entering directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/util' make[1]: Nothing to be done for 'check'. make[1]: Leaving directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/util' Making check in src make[1]: Entering directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/src' make check-am make[2]: Entering directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/src' make[2]: Nothing to be done for 'check-am'. make[2]: Leaving directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/src' make[1]: Leaving directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/src' Making check in include make[1]: Entering directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/include' make[1]: Nothing to be done for 'check'. make[1]: Leaving directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/include' Making check in man make[1]: Entering directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/man' make[1]: Nothing to be done for 'check'. make[1]: Leaving directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/man' Making check in specs make[1]: Entering directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/specs' make[1]: Nothing to be done for 'check'. make[1]: Leaving directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/specs' Making check in test make[1]: Entering directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/test' make Alloc Converters Event make[2]: Entering directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/test' CC Alloc.o CCLD Alloc CC Converters.o CCLD Converters CC Event.o Event.c:51:1: warning: function 'sigalrm' could be declared with attribute 'noreturn' [-Wmissing-noreturn] 51 | { | ^ 1 warning generated. CCLD Event make[2]: Leaving directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/test' make check-TESTS make[2]: Entering directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/test' make[3]: Entering directory '/home/abuild/rpmbuild/BUILD/libXt-1.3.0/test' ../test-driver: line 112: 9366 Aborted (core dumped) "$@" >> "$log_file" 2>&1 FAIL: Alloc PASS: Converters PASS: Event ============================================================================ Testsuite summary for libXt 1.3.0 ============================================================================ # TOTAL: 3 # PASS: 2 # SKIP: 0 # XFAIL: 0 # FAIL: 1 # XPASS: 0 # ERROR: 0 ============================================================================ See test/test-suite.log Please report to https://gitlab.freedesktop.org/xorg/lib/libxt/-/issues/ ``` 其中,test/test-suite.log显示为: ``` ====================================== libXt 1.3.0: test/test-suite.log ====================================== # TOTAL: 3 # PASS: 2 # SKIP: 0 # XFAIL: 0 # FAIL: 1 # XPASS: 0 # ERROR: 0 .. contents:: :depth: 2 FAIL: Alloc =========== TAP version 13 # random seed: R02S8d0db6758044940514b2e6e038c63bd3 1..18 # Start of Alloc tests # Start of XtAsprintf tests ok 1 /Alloc/XtAsprintf/short ok 2 /Alloc/XtAsprintf/long # End of XtAsprintf tests # Start of XtMalloc tests ok 3 /Alloc/XtMalloc/normal ok 4 /Alloc/XtMalloc/zero Warning: This program is an suid-root program or is being run by the root user. The full text of the error or warning message cannot be safely formatted in this environment. You may get a more descriptive message by running the program as a non-root user or by removing the suid bit on the executable. Caught Error: Cannot perform %s ok 5 /Alloc/XtMalloc/oversize ok 6 /Alloc/XtMalloc/overflow # SKIP overflow not possible in this config # End of XtMalloc tests # Start of XtCalloc tests ok 7 /Alloc/XtCalloc/normal ok 8 /Alloc/XtCalloc/zero Warning: This program is an suid-root program or is being run by the root user. The full text of the error or warning message cannot be safely formatted in this environment. You may get a more descriptive message by running the program as a non-root user or by removing the suid bit on the executable. Caught Error: Cannot perform %s ok 9 /Alloc/XtCalloc/oversize ok 10 /Alloc/XtCalloc/overflow # SKIP overflow not possible in this config # End of XtCalloc tests # Start of XtRealloc tests ok 11 /Alloc/XtRealloc/normal Warning: This program is an suid-root program or is being run by the root user. The full text of the error or warning message cannot be safely formatted in this environment. You may get a more descriptive message by running the program as a non-root user or by removing the suid bit on the executable. Caught Error: Cannot perform %s ok 12 /Alloc/XtRealloc/zero ok 13 /Alloc/XtRealloc/overflow # SKIP overflow not possible in this config free(): double free detected in tcache 2 FAIL Alloc (exit status: 134) ``` - 上游社区没有相关issue。问题的根源是软件包中的文件都使用了-O2的编译优化,当使用clang构建时,-O1及以上的优化水平会导致clang将malloc优化掉,从而在`configure`脚本中的这一段: ``` # Check whether --enable-malloc0returnsnull was given. if test ${enable_malloc0returnsnull+y} then : enableval=$enable_malloc0returnsnull; MALLOC_ZERO_RETURNS_NULL=$enableval else $as_nop MALLOC_ZERO_RETURNS_NULL=auto fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether malloc(0) returns NULL" >&5 printf %s "checking whether malloc(0) returns NULL... " >&6; } if test "x$MALLOC_ZERO_RETURNS_NULL" = xauto; then if test ${xorg_cv_malloc0_returns_null+y} then : printf %s "(cached) " >&6 else $as_nop if test "$cross_compiling" = yes then : printf %s "(cached) " >&6 else $as_nop if test "$cross_compiling" = yes then : { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run test program while cross compiling See \`config.log' for more details" "$LINENO" 5; } else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include <stdlib.h> int main (void) { char *m0, *r0, *c0, *p; m0 = malloc(0); p = malloc(10); r0 = realloc(p,0); c0 = calloc(0,10); exit((m0 == 0 || r0 == 0 || c0 == 0) ? 0 : 1); ; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO" then : xorg_cv_malloc0_returns_null=yes else $as_nop xorg_cv_malloc0_returns_null=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi MALLOC_ZERO_RETURNS_NULL=$xorg_cv_malloc0_returns_null fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MALLOC_ZERO_RETURNS_NULL" >&5 printf "%s\n" "$MALLOC_ZERO_RETURNS_NULL" >&6; } if test "x$MALLOC_ZERO_RETURNS_NULL" = xyes; then MALLOC_ZERO_CFLAGS="-DMALLOC_0_RETURNS_NULL" XMALLOC_ZERO_CFLAGS=$MALLOC_ZERO_CFLAGS XTMALLOC_ZERO_CFLAGS="$MALLOC_ZERO_CFLAGS -DXTMALLOC_BC" else MALLOC_ZERO_CFLAGS="" XMALLOC_ZERO_CFLAGS="" XTMALLOC_ZERO_CFLAGS="" fi ``` 当中的conftest获得了与gcc不同的结果(若编译时采用-O0,clang的脚本执行结果与gcc相同),从而本应执行的`MALLOC_ZERO_CFLAGS="-DMALLOC_0_RETURNS_NULL"`变为了`MALLOC_ZERO_CFLAGS=""`,从而导致在`src/Alloc.c`中以下函数执行时, ``` char * XtRealloc(char *ptr, unsigned size) { if (ptr == NULL) { #ifdef MALLOC_0_RETURNS_NULL if (!size) size = 1; #endif return (XtMalloc(size)); } else if ((ptr = Xrealloc(ptr, size)) == NULL #ifdef MALLOC_0_RETURNS_NULL && size #endif ) _XtAllocError("realloc"); return (ptr); } ``` 由于没有定义`MALLOC_0_RETURNS_NULL`所以不会判断`&& size`,做出错误的行为。但是`configure`脚本通过`configure.ac`生成,而`configure.ac`中使用的是`xorg-macros`([xorg-macros.m4.in · master · xorg / util / macros · GitLab](https://gitlab.freedesktop.org/xorg/util/macros/-/blob/master/xorg-macros.m4.in?ref_type=heads))的`XORG_CHECK_MALLOC_ZERO`来产生上文提到的片段: ``` # Require X.Org macros 1.16 or later for XORG_MEMORY_CHECK_FLAGS m4_ifndef([XORG_MACROS_VERSION], [m4_fatal([must install xorg-macros 1.16 or later before running autoconf/autogen])]) XORG_MACROS_VERSION(1.16) XORG_DEFAULT_OPTIONS XORG_CHECK_MALLOC_ZERO XORG_ENABLE_SPECS XORG_WITH_XMLTO(0.0.20) XORG_WITH_FOP XORG_WITH_XSLTPROC XORG_CHECK_SGML_DOCTOOLS(1.01) XORG_PROG_RAWCPP ``` 目前我采用的是直接修改spec文件,当使用clang构建时传入`--enable-malloc0returnsnull`的configure参数的办法来强制指定的简单方案。 - 不影响gcc构建行为,修改后llvm构建成功。llvm构建OBS验证工程: https://build.tarsier-infra.isrc.ac.cn/package/show/home:yy:branches:Mega-LLVM:24.03/libXt
此 Pull Request 暂不能合并,一些审核尚未通过
怎样手动合并此 Pull Request
git checkout master
git pull https://gitee.com/yanyir/libXt.git yy-master
git push origin master
评论
36
提交
1
文件
1
检查
代码问题
0
展开设置
折叠设置
审查
审查人员
douyan
dou33
yanan-rock
yanan-rock
Randy.Wang
wangxp006
small_leek
small_leek
t.feng
t_feng
wenlongd
dwl301
open-bot
open-bot
Lostway
Lostwayzxc
未设置
最少人数
0
Code Owner
测试
douyan
dou33
yanan-rock
yanan-rock
Randy.Wang
wangxp006
small_leek
small_leek
t.feng
t_feng
wenlongd
dwl301
open-bot
open-bot
Lostway
Lostwayzxc
未设置
最少人数
0
优先级
不指定
严重
主要
次要
不重要
标签
openeuler-cla/yes
ci_successful
sig/Desktop
关联 Issue
未关联
Pull Request 合并后将关闭上述关联 Issue
里程碑
未关联
合并选项
合并后删除提交分支
合并后关闭提到的 Issue
接受 Pull Request 时使用扁平化(Squash)合并
勾选此选项后,将建议使用 Squash Merge 方式合并以精简提交历史记录
参与者
(7)
Cherry Pick
选择 Cherry-Pick 代码的目标仓库
src-openeuler/libXt
选择要提交 PR 的目标仓库和分支
src-openeuler/libXt
master
提交模式
Fast forward
non-Fast forward
提交列表
Commit SHA
Commit Message
Cherry-pick Commit Message
*
取消
Cherry-pick
1
https://gitee.com/src-openeuler/libXt.git
git@gitee.com:src-openeuler/libXt.git
src-openeuler
libXt
libXt
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册