使用nostdlib的clang代码覆盖范围没有与Clang的运行时配置文件lib正确链接

发布于 2025-02-04 18:56:49 字数 3422 浏览 2 评论 0 原文

我正在尝试按照此处描述的方式遵循Clang的代码覆盖功能的说明:

具体来说,我想使用代码覆盖范围,而无需文件系统x86裸机(nostdlib),通过重定向到串行端口,因为可以完成链接的文档索赔。文档未指定是否没有任何特定架构,但是当我编译以下代码时:

int __llvm_profile_runtime;

char* AllocateCodeCoverageBuffer() {
   uint64_t size = __llvm_profile_get_size_for_buffer();

   char* buffer = AllocateZeroPool((UINTN) size);

   return buffer;
}

void WriteCodeCoverageBufferToSerial(char* buffer) {
   uint64_t buffer_size = __llvm_profile_get_size_for_buffer();

   __llvm_profile_write_buffer(buffer);

   DBG_TRACE_MSG_GUID(L"Code Coverage Results start for driver", gEfiCallerBaseName);
   PRINT_BYTES(buffer,buffer_size);
   DBG_TRACE_MSG_GUID(L"Code Coverage Results end for driver", gEfiCallerBaseName);
}

我会收到以下错误:

lld-link: error: undefined symbol: __llvm_profile_get_size_for_buffer
>>> referenced by CodeCoverage.c
>>>               my.lib(myCodeCoverage.obj)

lld-link: error: undefined symbol: __llvm_profile_write_buffer
>>> referenced by eCodeCoverage.c
>>>               my.lib(myCodeCoverage.obj)
NMAKE : fatal error U1077: '"C:\Program Files\LLVM\bin\lld-link.EXE"' : return code '0x1'
Stop.

我使用的编译器选项是:

-g -nostdlib -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -ffunction-sections -fdata-sections -include AutoGen.h -fno-common -Wno-parentheses-equality -Wno-tautological-compare -Wno-tautological-constant-out-of-range-compare -Wno-empty-body -Wno-unused-const-variable -Wno-varargs -Wno-unknown-warning-option -Wno-microsoft-enum-forward-reference -Wno-unused-but-set-variable -fno-stack-protector -funsigned-char -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang -Wno-address -Wno-shift-negative-value -Wno-unknown-pragmas -Wno-incompatible-library-redeclaration -Wno-null-dereference -mno-implicit-float -mms-bitfields -mno-stack-arg-probe -m64 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -Oz -flto -target x86_64-unknown-windows-gnu -gcodeview -funwind-tables -ftest-coverage -fprofile-instr-generate -fcoverage-mapping

链接器选项是:

/NOLOGO /IGNORE:4001 /OPT:REF /OPT:ICF=10 /ALIGN:32 /FILEALIGN:32 /Machine:X64 /DLL /ENTRY:_ModuleEntryPoint /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DEBUG:GHASH /lldmap /ALIGN:4096

当我检查LLVM代码时,它向我出现,Profiler Runtime无法没有STDLIB,因为它包括 stdio stdlib https://github.com/llvm/llvm/llvm/llvm/llvm/llvm/llvm/llvm/llvm/llvm-proignt/blob/blob/blob/main/main/main/main/compiler-rt /lib/profile/instrofiling.h

Clang文档让我感到困惑,因为GCC可以支持嵌入式系统上的GCOV分析,如下所示:。感觉就像clang 应该为 ftest-Coverage 提供支持。

的主要问题

  1. Clang的 -ftest-Coverage 在没有stdlib的情况下可以使用
  2. 吗? - ftest-coverage 在裸金属上使用吗?

感谢您看看并提供您的专业知识。请让我知道我是否可以提供任何信息。

I'm attempting to follow the instructions for clang's code coverage feature as described here: https://clang.llvm.org/docs/SourceBasedCodeCoverage.html#introduction.

Specifically I want to use code coverage without a file system x86 bare metal (nostdlib), by redirecting to a serial port as the linked document claims can be done. The documentation doesn't specify whether any particular architectures are unsupported, however when I compile the following code:

int __llvm_profile_runtime;

char* AllocateCodeCoverageBuffer() {
   uint64_t size = __llvm_profile_get_size_for_buffer();

   char* buffer = AllocateZeroPool((UINTN) size);

   return buffer;
}

void WriteCodeCoverageBufferToSerial(char* buffer) {
   uint64_t buffer_size = __llvm_profile_get_size_for_buffer();

   __llvm_profile_write_buffer(buffer);

   DBG_TRACE_MSG_GUID(L"Code Coverage Results start for driver", gEfiCallerBaseName);
   PRINT_BYTES(buffer,buffer_size);
   DBG_TRACE_MSG_GUID(L"Code Coverage Results end for driver", gEfiCallerBaseName);
}

I get the following error:

lld-link: error: undefined symbol: __llvm_profile_get_size_for_buffer
>>> referenced by CodeCoverage.c
>>>               my.lib(myCodeCoverage.obj)

lld-link: error: undefined symbol: __llvm_profile_write_buffer
>>> referenced by eCodeCoverage.c
>>>               my.lib(myCodeCoverage.obj)
NMAKE : fatal error U1077: '"C:\Program Files\LLVM\bin\lld-link.EXE"' : return code '0x1'
Stop.

The compiler options I am using are:

-g -nostdlib -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -ffunction-sections -fdata-sections -include AutoGen.h -fno-common -Wno-parentheses-equality -Wno-tautological-compare -Wno-tautological-constant-out-of-range-compare -Wno-empty-body -Wno-unused-const-variable -Wno-varargs -Wno-unknown-warning-option -Wno-microsoft-enum-forward-reference -Wno-unused-but-set-variable -fno-stack-protector -funsigned-char -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang -Wno-address -Wno-shift-negative-value -Wno-unknown-pragmas -Wno-incompatible-library-redeclaration -Wno-null-dereference -mno-implicit-float -mms-bitfields -mno-stack-arg-probe -m64 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -Oz -flto -target x86_64-unknown-windows-gnu -gcodeview -funwind-tables -ftest-coverage -fprofile-instr-generate -fcoverage-mapping

The linker options are:

/NOLOGO /IGNORE:4001 /OPT:REF /OPT:ICF=10 /ALIGN:32 /FILEALIGN:32 /Machine:X64 /DLL /ENTRY:_ModuleEntryPoint /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DEBUG:GHASH /lldmap /ALIGN:4096

When I inspected the llvm code, it appears to me that the profiler runtime cannot work without stdlib since it includes stdio and stdlib: https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/profile/InstrProfiling.h.

The Clang documentation has me confused since GCC can support gcov profiling on Embedded systems as seen here: https://dzone.com/articles/code-coverage-embedded-target. Feels like Clang should also support the same for -ftest-coverage.

primary questions

  1. Can Clang's -ftest-coverage work without stdlib?
  2. Can -ftest-coverage work on bare metal?

Thank for taking a look and providing your expertise. Please let me know if there's any info I can provide.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文