Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Function Wrapping with-Wl,--wrap Not Working forpostmortem_report() on ESP8266#9193

Closed
DRSDavidSoft started this conversation inGeneral
Discussion options

I'm working on an ESP8266 project where I need to override thepostmortem_report() function in a way that ensures my custom implementation is called instead of the original one. The original function is defined asstatic in a C file, which means it has internal linkage and is only visible within that file.

To achieve this, I attempted to use the linker flag-Wl,--wrap=postmortem_report to wrap the function and redirect calls to__wrap_postmortem_report, which I have defined in my C++ code. Here’s the relevant code:

Original Function (in C file):

extern"C"staticvoidpostmortem_report(uint32_t sp_dump) {// Original implementation}

My Custom Wrapper (in C++ file):

extern"C"void__wrap_postmortem_report(uint32_t sp_dump) {// Custom implementation}

Linker Flag in Build System:

"buildPreferences": [    ["build.extra_flags","-Wl,--wrap=postmortem_report"    ]

The Problem:

Despite setting everything up as described, it seems that my__wrap_postmortem_report() function isnot being called whenpostmortem_report() is invoked. Instead, the originalpostmortem_report() is still executed.

What I've Tried:

  • Verified that the-Wl,--wrap=postmortem_report flag is correctly passed to the linker:
"xtensa-lx106-elf-g++" ... -Wl,--wrap=postmortem_report
  • Ensured that__wrap_postmortem_report has external linkage by usingextern "C".
  • Tried different compiler optimizations (-O0) to rule out issues related to inlining or optimization.
  • Checked for symbol conflicts to ensure there’s only onepostmortem_report function in the project (thestatic one).
  • Examined the linker steps for any overrides but didn’t find anything that could interfere with function wrapping.

Questions:

  1. Is there something specific about the ESP8266 toolchain that might cause this wrapping mechanism to fail?
  2. Could thestatic keyword in the original function be interfering with the wrapping process, despite the linker flag?
  3. Are there any additional steps or considerations I should take to ensure that the__wrap_postmortem_report() function is called instead of the original?

The original code in thecore_esp8266_postmortem.cpp file references thepostmortem_report() in the assembly as well:

asm(".section     .text.__wrap_system_restart_local,\"ax\",@progbits\n\t"".literal_position\n\t"".align       4\n\t"".global      __wrap_system_restart_local\n\t"".type        __wrap_system_restart_local, @function\n\t""\n""__wrap_system_restart_local:\n\t""mov          a2,     a1\n\t""j            postmortem_report\n\t"".size __wrap_system_restart_local, .-__wrap_system_restart_local\n\t");

Any insights or suggestions on what might be going wrong and how to fix it would be greatly appreciated!

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

mcspr
Aug 27, 2025
Collaborator

(better late than never :)

ld won't use your symbol for internal linkage happening in postmortem .o

https://sourceware.org/binutils/docs/ld/Options.html#index-_002d_002dwrap_003dsymbol

--wrap=symbol
...
Only undefined references are replaced by the linker. So, translation unit internal references to symbol are not resolved to __wrap_symbol. In the next example, the call to f in g is not resolved to __wrap_f.

You'd have to export it first by removing 'static', similarly to how the system restart wrapper works.
We do have hard dependency on postmortem report function atm (3.1.2), so I'd fix that issue first.

You must be logged in to vote
1 reply
@DRSDavidSoft
Comment options

(better late than never :)

Completely agree with you on that one 😅

This makes complete sense to me, so I'll also focus on the postmortem report function dependency for now.

Thank you for taking time explaining this to me, and pointing me to the documentation 🤝

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
2 participants
@DRSDavidSoft@mcspr

[8]ページ先頭

©2009-2025 Movatter.jp