【发布时间】:2018-12-23 12:11:27
【问题描述】:
我有许多函数和相应的单元测试。我想将测试嵌入代码库本身。我想出了以下解决方案:
void a() {
// this code should be tested
}
__attribute__((section(".tests")))
void a_test() {
// test if a() works
}
测试放在.tests 部分中,我可以将其剥离以进行发布构建。我尝试了以下方法:
$ gcc -c a.c -o a.orig.o # a.c is shown above
$ objcopy -R.tests a.orig.o a.o
objcopy: a.o: symbol `.tests' required but not present
objcopy:a.o: no symbols
我发现this question 描述了一个类似的问题,答案说这是因为该部分正在从某个地方交叉引用。
我认为.eh_frame 是有罪的部分,因为删除它会
工作:
$ objcopy -R.tests -R.eh_frame a.orig.o a.o
- 我可以删除此部分而不产生任何后果吗?
- 有没有更好的方法来解决这个问题?
【问题讨论】: