MCU上的独立代码 - 除了VSNPrintf -C替代VSNPRINTF之外,一切都起作用?
我把听到的声音很长一段时间。我正在尝试在微控制器上实现独立的位置代码。这是一个兔子洞。我已经走了这么远,可以将我的应用在线携带,并且对MQTT命令响应迅速。
对于我来说,我唯一做不到的是完全未知的原因,是1个特定的stdlib调用:vsnprintf
或其任何兄弟姐妹。我正在使用10.2版10.2版。我也有这个特定功能的源代码,但是它深深地涉及我不够理解的内容,因此我会遇到解决这个问题的每一次尝试。
我使用的是LWIP(轻质IP),该LWIP将呼叫纳入snprintf
。它可以正常工作,直到我将应用程序重新安置到Flash中的其他位置。 .got部分和SRAM内存适当地用我在自定义引导程序中计算的LMA_OFFSET进行了正确修补。同样,除了这个可怕的单一怪异的呼唤中,一切都起作用。
出于调试目的,我为snprintf
制作了一个包装器,希望我可以进一步钻一点以了解问题所在。我没有进一步。
int snprintf_override (
char *__restrict buffer,
size_t size,
const char *__restrict format,
...)
{
int result;
va_list args;
va_start(args, format);
// The next line calls into std lib, and hard faults, I wish I could share anything else that made any sense...
result = vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
return result;
}
问题1:
是否有人可以建议另一种方式
在功能上与vsnprintf
相同?从头开始写一些东西甚至可行吗?我感觉那个功能有很多复杂性吗?
问题2:
或者,是否有人知道,将导致svnprintf
失败的代码的问题有什么问题?浏览recent
/impurePointers(?),挖掘,实现依赖于
file
实例。我仍然会在天真中说“只是数据”,但也许不仅仅是吗?是否有一些根本无法重新定位的汇编(我不可能是不可能的,Linux OS无助于用-fpic -fpic
...)?
恐怕这个问题几乎没有引起关注,但是也许,也许有人对STD Lib和/或位置独立代码点击,并愿意帮助我...
I am pulling my hear out for quite a while. I am trying to achieve position independent code on a microcontroller. It's quite a rabbit hole. I've gotten so far that I can bring my app online, and responsive for mqtt commands.
The only thing I can't seem to do, for to me completely unknown reasons, is 1 specific stdlib call: vsnprintf
or any of its siblings. I am using the arm-none-eabi toolchain version 10.2. I have the source code, also of this specific function, but it goes sooo deep into stuff I just don't understand enough about, so I am stuck on every attempt to get around this problem.
I am using lwip (light weight IP) which makes calls into snprintf
. It works fine, until I relocate my app to a different location in flash. The .got section and sram memory is properly patched with the lma_offset I calculate in my custom bootloader. Again, everything works, except this horrible single freaking call into the std lib.
For debugging purposes, I made a wrapper for snprintf
in the hope I could drill down just a bit more to understand what the problem is. I am not getting much further.
int snprintf_override (
char *__restrict buffer,
size_t size,
const char *__restrict format,
...)
{
int result;
va_list args;
va_start(args, format);
// The next line calls into std lib, and hard faults, I wish I could share anything else that made any sense...
result = vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
return result;
}
Question 1:
Is there anybody who can suggest another way
to achieve functionally the same as vsnprintf
? Is it even doable to write something from scratch? I have the feeling there is quite some complexity in that function?
Question 2:
Or, is there anybody, who has ANY idea what can be the problem in relocating code which causes svnprintf
to fail? Digging through the stdlib code I come across REENT
/ impurepointers (?), and the implementation relies on a FILE
instance. Still "just data" I would say in my naivety, but maybe it's more than that? Is there some assembly hidden somewhere which is simply not relocatable (I can't believe it's not possible, linux OS does nothing else than compile with -fpic
...)?
I am afraid this question gets little attention, but maybe, just maybe, somebody with some severe understanding of std lib and/or position independent code clicks on it, and is willing to help me out...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从来没有发现在libc-nano中完全出错。但是,我认为我有足够的证据表明,我遇到的问题与未与-fpic一起编译的Libc -Nano有关。
我在较小的测试设置中重现了该问题,该设置由:
main
中,我只呼叫stdlib的vsnprintf
。i集成 picolibc (用-fpic重新编译)到我的原始项目中。现在一切正常。
I never found out exactly goes wrong in the libc-nano. But, I think I have proof enough that the problem I ran into has everything to do with libc-nano not being compiled with -fpic.
I reproduced the problem in a smaller test setup which consists of:
main
of the app, I only make a call to stdlib'svsnprintf
.I integrated picolibc (recompiled with -fpic) into my original project. Now everything works perfectly.