我正在尝试按照此处描述的方式遵循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
提供支持。
的主要问题
- Clang的
-ftest-Coverage
在没有stdlib的情况下可以使用
- 吗?
- 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
- Can Clang's
-ftest-coverage
work without stdlib?
- 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.
发布评论