我需要一种方法来分析我的GCC编译器的ARM输出文件.我正在编制裸机,我非常关心尺寸.我可以使用arm-none-eabi-objdump交叉编译器提供但是如果存在用于此任务的工具,则解析输出不是我想要做的事情.你知道这样的工具存在吗?我的搜索没有结果.
还有一件事,我自己的代码中的每个函数都在它自己的部分.
我正在尝试为PEG.js写一个简单的语法来匹配这样的东西:
some text;
arbitrary other text that can also have µnicode; different expression;
let's escape the \; semicolon, and \not recognized escapes are not a problem;
possibly last expression not ending with semicolon
Run Code Online (Sandbox Code Playgroud)
所以基本上这些是用分号分隔的一些文本.我的简化语法看起来像这样:
start
= flow:Flow
Flow
= instructions:Instruction*
Instruction
= Empty / Text
TextCharacter
= "\\;" /
.
Text
= text:TextCharacter+ ';' {return text.join('')}
Empty
= Semicolon
Semicolon "semicolon"
= ';'
Run Code Online (Sandbox Code Playgroud)
问题是,如果我在输入中放入除分号以外的任何内容,我会得到:
SyntaxError: Expected ";", "\\;" or any character but end of input found.
Run Code Online (Sandbox Code Playgroud)
怎么解决这个?我已经读过PEG.js无法匹配输入结束.
我的目标设备是基于 EFM32 Cortex-M3 的设备。我的工具链是官方的 ARM GNU 工具链 gcc-arm-none-eabi-8-2018-q4-major。
在没有 LTO 的情况下一切正常,但为了使 LTO 工作,我必须用-fno-lto. 我想摆脱这种解决方法。
问题是,每个中断处理程序都从最终的二进制文件中删除。(我正在检查arm-none-eabi-nm --print-size --size-sort --radix=d -C -n file.out)这会导致二进制崩溃。
在谷歌搜索类似问题后进行更深入的挖掘:
__attribute__((used)),__attribute((interrupt))但无济于事 - 尽管有这些属性,但中断处理程序正在被删除。(相关防止 GCC LTO 删除功能)来自startup_efm32gg.c定义默认中断处理程序的示例代码如下:
void DMA_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
/* many other interrupts */
void Default_Handler(void) { while (1); }
Run Code Online (Sandbox Code Playgroud)
常规中断处理程序定义也会发生同样的问题(例如,没有别名且不弱)
这可能是相关的,但似乎弱符号在 LTO 模式下也以同样的方式运行不正常。
提前感谢您的任何想法!
编辑:有关完整解决方案,请参阅我对标记答案的回复!
我想做的是创建:
template<Args... args)>
int println(Args...) {
// implementation which calls:
// printf("<string literal format string at compile time>", args...);
// additional perk would be compile time type checking
// I expect to provide a format string for each type by some template
// specialization.
}
Run Code Online (Sandbox Code Playgroud)
我一直在用编译时字符串文字分析两个有趣的工作:
编译时间内存对齐的字符串文字
100%constexpr字符串实现
http://sourceforge.net/p/constexprstr/code/HEAD/tree/no-pp-constexpr_string.cpp
基本上我或多或少能够静态地推断格式所需的字符串文字的长度,但仅仅是编译器拒绝将我的工作视为constexpr.另一个大问题是,当使用上述链接中的constexpr字符串时,编译器永远无法推断出结果字符串的大小.
我越努力实现这一点,我的无知就越多,超过了我的热情.我将不胜感激任何解决部分或全部问题的技巧和/或代码示例.
注意:我不是在寻找有关使用不同形式的日志记录的建议,例如通过cout.
注意2:不应该使用任何std :: string,因为它们是运行时
注3:通常所有类型安全的printfs都使用不同的方法,我很熟悉这可以通过多次调用轻松完成printf.我想一次性完成.我也知道缓冲区可以逐步构建,但这个问题是关于构造格式字符串.:)
更新:基本上代码的哪个部分需要实现
constexpr const char* formatString = build_compile_time_format_string(args...);
// build_compile_time_format_string(3, "hi", -3.4)
// should evaluate to "%d %s %f"
// or to …Run Code Online (Sandbox Code Playgroud) 以下代码正常工作
<!DOCTYPE html>
<html>
<head>
<title>Working</title>
<style type="text/css">
html {
height: 100%;
}
body {
height: 100%; /* !!!!! difference in here */
}
div#main {
min-height: 100%;
background-color: red;
}
</style>
</head>
<body>
<div id="main"></div>
</body>
Run Code Online (Sandbox Code Playgroud)
而使用min-height代替heightfor body 的代码会阻止#main占用空间
<!DOCTYPE html>
<html>
<head>
<title>Not working</title>
<style type="text/css">
html {
height: 100%;
}
body {
min-height: 100%; /* !!!!! difference in here */
}
div#main {
min-height: 100%;
background-color: red;
}
</style>
</head>
<body> …Run Code Online (Sandbox Code Playgroud)