-1

I use 106Micro core and Xtensa toolchain (gcc) for ESP8266 chip.

Not sure what strncpy function is used

According to map file

 .text          0x4010077c       0xfa c:/sysgcc/esp8266/bin/../lib/gcc/xtensa-lx106-elf/5.2.0/../../../../xtensa-lx106-elf/lib\libc.a(lib_a-strncpy.o)
                0x401007b4                strncpy

But also in ROM, there is a function that is already present with the same name

        0x4000c0a0                PROVIDE (strncpy, 0x4000c0a0)

Since if function from libc is present in binary, seems that the ROM one was ignored. Most likely I haven't a prototype defined for ROM one (since ESP8266 has many ROM functions not explained, without an ykind of prototype) and due to the libc was chosen.

Now how can I include the ROM version, but keep the in program?

Thanks for clarifications,

yo3hcv
  • 1,531
  • 2
  • 17
  • 27
  • Can you step through in your debugger and find out? – tadman Jan 19 '18 at 19:10
  • I would, but Chinese manufacturers barely knows to write a datasheet. Debugger is non existing. – yo3hcv Jan 19 '18 at 20:20
  • If they both work the same then I guess the issue is academic. If they work differently then you can always discover which one you're using, – tadman Jan 19 '18 at 20:22
  • 1
    I don't know, the ROM version doesn't have proto and is unknown. I have to dump the content, dissassm then reconstruct, to see clearly. Thanks anyhow. – yo3hcv Jan 19 '18 at 20:27
  • @tadman It is not academic even if they are identical. Ignoring the ROM version bloats the size of executable. – user58697 Jan 19 '18 at 21:21
  • How your linker script look like? – user58697 Jan 19 '18 at 21:22
  • @user58697 If it's in a shared library that's already there then there's no difference. That's how `libc` is often shipped. – tadman Jan 19 '18 at 21:51
  • [Never use strncpy for any purpose.](https://stackoverflow.com/a/46563868/584518) – Lundin Jan 22 '18 at 09:12

1 Answers1

1

It is not clear what linker you are using, but for GNU ld the PROVIDE directive (with slightly different syntax) is used to:

[...] define a symbol only if it is referenced and is not defined by any object included in the link.

Because you have provided libc, and thus a definition for strncpy then that will override the PROVIDE'ed strncpy.

If you remove libc from the link, the symbol will be resolved by the PROVIDE directive. If you are not explicitly linking libc, you may need to use the link option --nodefaultlibs or --nostdlib to prevent linking code already provided.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • I use GNU ld, built for Xtensa (pretty much standard gcc) The --nostdlib was given but --nodefaultlibs was not (forgotten by me) but >>> Thank you! <<< I missed the part with override, didn't knew. Cheers! – yo3hcv Jan 22 '18 at 16:50