如何使用-flot flag?

发布于 2025-02-10 03:06:36 字数 3047 浏览 2 评论 0原文

我希望将malloc符号重新定义为own_malloc,以便我可以知道内存alloc的详细信息并打印alloc-size。但是当我借口订单时,我发现它不起作用:

arm-none-eabi-objcopy --redefine-sym malloc=own_malloc test.o

测试来源:

#include <stdlib.h>

extern "C" void test();

void test(){
    void* ptr = ::malloc(16);
    free(ptr);
}

我exec objdump查看符号表,

arm-none-eabi-objdump -t test.o

我会在那儿添加我的 储物表在符号表中不是malloc/自由符号。

SYMBOL TABLE:
00000000 l    df *ABS*  00000000 test.cxx
00000000 l    d  .text  00000000 .text
00000000 l    d  .data  00000000 .data
00000000 l    d  .bss   00000000 .bss
00000000 l    d  .gnu.debuglto_.debug_info      00000000 .gnu.debuglto_.debug_info
00000000 l    d  .gnu.debuglto_.debug_abbrev    00000000 .gnu.debuglto_.debug_abbrev
00000000 l    d  .gnu.debuglto_.debug_line      00000000 .gnu.debuglto_.debug_line
00000000 l    d  .gnu.debuglto_.debug_str       00000000 .gnu.debuglto_.debug_str
00000000 l    d  .gnu.lto_.profile.7c13183f5b427e41     00000000 .gnu.lto_.profile.7c13183f5b427e41
00000000 l    d  .gnu.lto_.icf.7c13183f5b427e41 00000000 .gnu.lto_.icf.7c13183f5b427e41
00000000 l    d  .gnu.lto_.ipa_sra.7c13183f5b427e41     00000000 .gnu.lto_.ipa_sra.7c13183f5b427e41
00000000 l    d  .gnu.lto_.inline.7c13183f5b427e41      00000000 .gnu.lto_.inline.7c13183f5b427e41
00000000 l    d  .gnu.lto_.jmpfuncs.7c13183f5b427e41    00000000 .gnu.lto_.jmpfuncs.7c13183f5b427e41
00000000 l    d  .gnu.lto_.pureconst.7c13183f5b427e41   00000000 .gnu.lto_.pureconst.7c13183f5b427e41
00000000 l    d  .gnu.lto_.lto.7c13183f5b427e41 00000000 .gnu.lto_.lto.7c13183f5b427e41
00000000 l    d  .gnu.lto_test.0.7c13183f5b427e41       00000000 .gnu.lto_test.0.7c13183f5b427e41
00000000 l    d  .gnu.lto_.symbol_nodes.7c13183f5b427e41        00000000 .gnu.lto_.symbol_nodes.7c13183f5b427e41
00000000 l    d  .gnu.lto_.refs.7c13183f5b427e41        00000000 .gnu.lto_.refs.7c13183f5b427e41
00000000 l    d  .gnu.lto_.decls.7c13183f5b427e41       00000000 .gnu.lto_.decls.7c13183f5b427e41
00000000 l    d  .gnu.lto_.symtab.7c13183f5b427e41      00000000 .gnu.lto_.symtab.7c13183f5b427e41
00000000 l    d  .gnu.lto_.ext_symtab.7c13183f5b427e41  00000000 .gnu.lto_.ext_symtab.7c13183f5b427e41
00000000 l    d  .gnu.lto_.opts 00000000 .gnu.lto_.opts
00000000 l    d  .comment       00000000 .comment
00000000 l    d  .ARM.attributes        00000000 .ARM.attributes
00000000  w      .gnu.debuglto_.debug_info      00000000 .hidden test.cxx.cee7ff5d
00000001       O *COM*  00000001 __gnu_lto_slim

我使用了以下汇编参数:

arm-none-eabi-g++ -c -fno-common -nostdinc++ -Wall -Wshadow -Wundef -fno-exceptions -fcheck-new -fno-rtti -std=c++17 -pipe -Os -fno-strict-aliasing -fomit-frame-pointer -flto -fuse-linker-plugin -fno-builtin -ffunction-sections -fdata-sections -g -march=armv8-m.main+dsp -mtune=cortex-m33 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard _ -Wno-cpp --std=c++17 -Werror test.cxx -o test.o

那么如何重新定义malloc并免费使用lo lto flag的malloc和own_free?

I want redefine malloc symbol to own_malloc, so that I can know memory alloc details and print alloc-size.But I found it don't work when I excuting order:

arm-none-eabi-objcopy --redefine-sym malloc=own_malloc test.o

the test source:

#include <stdlib.h>

extern "C" void test();

void test(){
    void* ptr = ::malloc(16);
    free(ptr);
}

I exec objdump to look the symbol table

arm-none-eabi-objdump -t test.o

I fount there was not malloc/free symbol in symbols table.

SYMBOL TABLE:
00000000 l    df *ABS*  00000000 test.cxx
00000000 l    d  .text  00000000 .text
00000000 l    d  .data  00000000 .data
00000000 l    d  .bss   00000000 .bss
00000000 l    d  .gnu.debuglto_.debug_info      00000000 .gnu.debuglto_.debug_info
00000000 l    d  .gnu.debuglto_.debug_abbrev    00000000 .gnu.debuglto_.debug_abbrev
00000000 l    d  .gnu.debuglto_.debug_line      00000000 .gnu.debuglto_.debug_line
00000000 l    d  .gnu.debuglto_.debug_str       00000000 .gnu.debuglto_.debug_str
00000000 l    d  .gnu.lto_.profile.7c13183f5b427e41     00000000 .gnu.lto_.profile.7c13183f5b427e41
00000000 l    d  .gnu.lto_.icf.7c13183f5b427e41 00000000 .gnu.lto_.icf.7c13183f5b427e41
00000000 l    d  .gnu.lto_.ipa_sra.7c13183f5b427e41     00000000 .gnu.lto_.ipa_sra.7c13183f5b427e41
00000000 l    d  .gnu.lto_.inline.7c13183f5b427e41      00000000 .gnu.lto_.inline.7c13183f5b427e41
00000000 l    d  .gnu.lto_.jmpfuncs.7c13183f5b427e41    00000000 .gnu.lto_.jmpfuncs.7c13183f5b427e41
00000000 l    d  .gnu.lto_.pureconst.7c13183f5b427e41   00000000 .gnu.lto_.pureconst.7c13183f5b427e41
00000000 l    d  .gnu.lto_.lto.7c13183f5b427e41 00000000 .gnu.lto_.lto.7c13183f5b427e41
00000000 l    d  .gnu.lto_test.0.7c13183f5b427e41       00000000 .gnu.lto_test.0.7c13183f5b427e41
00000000 l    d  .gnu.lto_.symbol_nodes.7c13183f5b427e41        00000000 .gnu.lto_.symbol_nodes.7c13183f5b427e41
00000000 l    d  .gnu.lto_.refs.7c13183f5b427e41        00000000 .gnu.lto_.refs.7c13183f5b427e41
00000000 l    d  .gnu.lto_.decls.7c13183f5b427e41       00000000 .gnu.lto_.decls.7c13183f5b427e41
00000000 l    d  .gnu.lto_.symtab.7c13183f5b427e41      00000000 .gnu.lto_.symtab.7c13183f5b427e41
00000000 l    d  .gnu.lto_.ext_symtab.7c13183f5b427e41  00000000 .gnu.lto_.ext_symtab.7c13183f5b427e41
00000000 l    d  .gnu.lto_.opts 00000000 .gnu.lto_.opts
00000000 l    d  .comment       00000000 .comment
00000000 l    d  .ARM.attributes        00000000 .ARM.attributes
00000000  w      .gnu.debuglto_.debug_info      00000000 .hidden test.cxx.cee7ff5d
00000001       O *COM*  00000001 __gnu_lto_slim

I used the following compilation parameters:

arm-none-eabi-g++ -c -fno-common -nostdinc++ -Wall -Wshadow -Wundef -fno-exceptions -fcheck-new -fno-rtti -std=c++17 -pipe -Os -fno-strict-aliasing -fomit-frame-pointer -flto -fuse-linker-plugin -fno-builtin -ffunction-sections -fdata-sections -g -march=armv8-m.main+dsp -mtune=cortex-m33 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard _ -Wno-cpp --std=c++17 -Werror test.cxx -o test.o

So how can I redefine malloc and free to own_malloc and own_free with lto flag ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文