Ding Brains
Ding Brains

Reputation: 11

How to redefine symbol of object file from the arm-none-eabi compile with -flot flag?

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 ?

Upvotes: 1

Views: 250

Answers (0)

Related Questions