【问题标题】:Why my (kernel) GCov doesn't work on linux 3.9?为什么我的(内核)GCov 在 linux 3.9 上不起作用?
【发布时间】:2013-06-10 05:10:59
【问题描述】:

我已经按照“Documentation/gcov.txt”所说的做了。

mime 基础知识:

$ uname -a
Linux turf.ivor 3.9.5 #1 SMP Fri Jun 14 00:51:05 CST 2013 x86_64 x86_64 x86_64 GNU/Linux

$ cat /etc/redhat-release
Fedora release 18 (Spherical Cow)

$ zcat /proc/config.gz | egrep "GCOV_|DEBUG_FS"

CONFIG_GCOV_KERNEL=y
CONFIG_GCOV_PROFILE_ALL=y
CONFIG_DEBUG_FS=y

$ mount | grep debugfs
debugfs on /sys/kernel/debug type debugfs (rw,relatime)

# ls -la /sys/kernel/debug/gcov/ 
total 0
drwxr-xr-x  2 root root 0 Jun 14  2013 .
drwx------ 17 root root 0 Jun 14  2013 ..
-rw-------  1 root root 0 Jun 14  2013 reset

我只找到了一个重置​​文件(一个空文件)。

正如“文件”所说:

 90 4. Files
 91 ========
 92                                                                                
 93 The gcov kernel support creates the following files in debugfs:
 94 
 95         /sys/kernel/debug/gcov
 96                 Parent directory for all gcov-related files.
 97 
 98         /sys/kernel/debug/gcov/reset
 99                 Global reset file: resets all coverage data to zero when
100                 written to.
101 
102         /sys/kernel/debug/gcov/path/to/compile/dir/file.gcda
103                 The actual gcov data file as understood by the gcov
104                 tool. Resets file coverage data to zero when written to.
105 
106         /sys/kernel/debug/gcov/path/to/compile/dir/file.gcno
107                 Symbolic link to a static data file required by the gcov
108                 tool. This file is generated by gcc when compiling with
109                 option -ftest-coverage.

我该怎么办?

gcov 还支持最新的 linux 版本吗?

任何建议,谢谢。

`

【问题讨论】:

    标签: linux-kernel kernel gcov


    【解决方案1】:

    问题很可能是 gcc。一些较新的版本不再生成 .ctors 选项,而是使用 .init_array 代替。您可以通过对启用了 gcov 的内核对象之一执行 objdump -dr -j .ctors 来确认这一点。如果它返回没有找到这样的部分,请尝试 .init_array。

    我现在正在努力解决这个问题,试图了解在 init/main.c 的 do_ctors 调用中用 .init_array 替换 .ctors 的奥秘。这可不像在 vmlinux.lds.h 中交换节名那么简单

    抱歉,这还不是答案。

    【讨论】:

      【解决方案2】:

      在 vmlinux.lds.h 文件中进行以下更改,在 vmlinux 文件的 .ctors 部分添加 .init_array 即可:-

      谢谢

      【讨论】:

        【解决方案3】:

        内核中未启用对 ARM 的 GCOV 支持。 请参考下面的 URL,将 2 个补丁应用到您的内核,您将能够在目标上看到 gcov 文件

        https://groups.google.com/forum/#!topic/linux.kernel/JsvylFnag-Y

        【讨论】:

          【解决方案4】:

          对于 3.7 或 3.8 以上的新内核版本,您必须是 sudo 用户才能获取 gcda 文件。

          sudo su

          现在转到目录/sys/kernel/debug/gcov/

          您将看到构建的 linux 代码路径。

          【讨论】:

            【解决方案5】:

            我遇到了同样的问题,我认为 gcc 是罪魁祸首。当我的 gcc 版本低于 4.7 时,一切似乎都很顺利。否则像你一样的问题就出来了。

            为什么?

            greebo52 的答案就是答案。

            如何解决?

            你可以在 4.7 下使用 gcc 或者编译你自己的 gcc 4.7。当你配置 gcc 4.7 时,添加这个 --disable-initfini-array。 像这样:

            ./configure --disable-initfini-array ...(其他选项)

            【讨论】:

              猜你喜欢
              • 2015-10-29
              • 1970-01-01
              • 2012-11-22
              • 2016-03-19
              • 2017-04-08
              • 1970-01-01
              • 2015-08-21
              • 2022-11-13
              • 1970-01-01
              相关资源
              最近更新 更多