GCC extract symbol list and link by another images

924 views Asked by At

All I am trying to do, extacting some symbols from an image and using (linking) symbols from different image.

With armccc/armlink, when specify --symdefs=, it creates file which includes symbols ad their addresses.
On the other hand, if you remove unused symbols, it just updates existing symbols. And if you include this file to compilation, it links previous image's symbols with new image.

But I cannot find similar approach for GNU toolchaing (arm-none-eabi-). if I use arm-none-eabi-nm, it creates symbol list like armcc --symdefs option but cannot find a way to use this symbol list with second image compliation. (Also there is no way to filter symbols without grep).

Other option seems also using arm-none-eabi-objcopy but could not find how to use it with second image compliation too.

In GNU toolchain, how can we do that? Any idea?

On the other hand, I want to apply that for Keil uVision IDE if possible. Thanks.

1

There are 1 answers

1
yugr On

Not knowing much about armcc, it may be quite easy to emulate this behavior with standard GNU tools. E.g. to generate symdef file:

$ cat tmp.c
int foo() { return 0; }
int bar() { return 1; }
int main() { return 0; }
$ gcc tmp.c
$  readelf -sW a.out | grep GLOBAL | awk '{print $8 " " $2 }' | grep -v '^_' > symdef.lst

And then use it to define missing symbols for linker via --defsym flag:

$ LDFLAGS=$(cat symdef.lst |  awk '{print "-Wl,--defsym=" $1 "=" $2}' | tr '\n' ' ')
$ echo $LDFLAGS
-Wl,--defsym=bar=0000000000400481 -Wl,--defsym=foo=0000000000400476 -Wl,--defsym=main=000000000040048