鲲鹏社区首页
中文
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助

atomic场景源码扫描

atomic场景源码扫描是在普通场景基础上,当用户使用c++ atomic时,静态扫描工具会识别包含memory_order语义的atomic,并在最终报告中呈现出来。

扫描源代码

  1. GithubGitee代码样例atomic获取待使用的软件源码包。

    下载的源码包为devkitdemo-main.zip,解压后的“./devkitdemo-main/Porting_advisor/testdemo/weak_consistency/atomic”为内存一致性静态检查的待扫描代码。

  2. 生成BC文件。
    1. 执行以下命令,扫描修改后的源码文件,并生成BC文件。
      1
      2
      cd /home/software/Porting_advisor/testdemo/weak_consistency/atomic/
      devkit advisor bc-gen -o /home/report -c make
      

      显示信息如下:

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      Executing static memory consistency check task, please wait...
      Current progress: ###### [20%]
      Start to get the compile database
      Current progress: ################ [50%]
      Start to generate the bc files
      Current progress: ################################# [100%]
      Configuration:
          Generate bc files path: /home/report
          Compile command: make
          Threads: The threads is not set, using the half number of cores.
          Task Timeout Interval: The timeout period is not set.
          Log level: info
      Summary:
          Scanned all source files, there are 1 linked bc files and 1 object bc files generated.
      For the detail information, please check:
      Output path of linked bc files: /home/report/bc-gen_20250225061701_192f/bin
      Output path of object bc files: /home/report/bc-gen_20250225061701_192f/object
      There are 0 linked bc files fail to be generated. For the causes of the failure to generate all the bc files and their intermediates, please check:
      Log path: /opt/DevKit-CLI-25.0.0-Linux-Kunpeng/advisor/logs/affinity/affinity.log
      
      • -o:生成BC文件的存放路径,需要有写权限。报告默认存放在当前路径下,名称默认为“模块名称_时间戳”。
      • -c:源码的构建命令。

      请下载回显信息中“Output path of linked bc files”后面路径下的“bc-gen_20250225061701_192f”文件夹,“bin”文件夹作为3中BC文件存放路径。

  3. 进入鲲鹏DevKit,在左侧列表中单击“亲和分析 > 内存一致性静态检查”,检查模式选择“静态检查”
    • 将automic文件夹上传到服务器上的“/opt/DevKit/workspace/devadmin/affinity/weakconsistency/”下,单击源码文件存放路径的填写框,选择automic下拉项。
    • 鼠标悬浮到“上传”,选择“压缩包”(上传过程中自动解压)或“文件夹”

    这里以上传文件夹方式为例,单击“文件夹”,上传automic文件夹。BC文件存放路径也以上传文件夹方式为例,单击“文件夹”,上传bin文件夹。如图1所示。

    图1 内存一致性源码文件静态检查界面
  4. 单击“开始检查”,执行内存一致性检查任务,并得到扫描分析报告,如图2所示。
    图2 内存一致性源码扫描分析报告

源代码内存一致性问题

单击内存一致性报告的“查看建议源码”,查看具体的内存一致性问题所在的源码位置,如图3图4所示。
图3 源码修改建议报告界面
图4 内存一致性问题所在的源码位置

<atomic.c>扫描出4个内存一致性问题。这里的C++ atomic操作没有使用正确的memory order,内存一致性扫描工具识别并报告了源码位置。