MCU上的独立代码 - 除了VSNPrintf -C替代VSNPRINTF之外,一切都起作用?

发布于 2025-02-06 09:50:32 字数 1372 浏览 2 评论 0原文

我把听到的声音很长一段时间。我正在尝试在微控制器上实现独立的位置代码。这是一个兔子洞。我已经走了这么远,可以将我的应用在线携带,并且对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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜雨飘雪 2025-02-13 09:50:32

我从来没有发现在libc-nano中完全出错。但是,我认为我有足够的证据表明,我遇到的问题与未与-fpic一起编译的Libc -Nano有关。

我在较小的测试设置中重现了该问题,该设置由:

  • 一个启动加载程序(从0x60000000运行),该设置将App的VTOR复制到SRAM
  • (从0x60020000或0x600A0000运行),该应用程序复制了全局偏移表,数据,数据,数据和C ++构造函数SRAM,在启动期间。
  • 在应用程序的main中,我只呼叫stdlib的vsnprintf
libc -nanopicolibcpicolibc用-fpic
应用重新编译@0x60000000workesworkes workesworks
app@0x600A0000硬故障硬故障works

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:

  • a bootloader (runs from 0x60000000) which copies vtor of app to sram,
  • an app (runs from 0x60020000 or 0x600a0000) which copies global offset table, data, and c++ constructors, to sram, during startup.
  • in the main of the app, I only make a call to stdlib's vsnprintf.
libc-nanopicolibcpicolibc recompiled with -fpic
app@0x60000000worksworksworks
app@0x600a0000hard faulthard faultworks

I integrated picolibc (recompiled with -fpic) into my original project. Now everything works perfectly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文