2

I got an embedded project for cortex-m0+ and I would like to link with newlib-nano library. I'm learning, how things work (that you need to implement stubs for certain functions etc.). I've managed to create a working example which builds.

Source code:

int main(void)
{
  uint32_t i = 0;
  printf("Hello Wordl!");
  while (1)
  {
    i += 1;
  }
}

I was curious, which functions get invoked, to peek behind the scene a bit so I made a dump of the final elf file and to my surprise, the code invokes "iprintf" instead of printf.

However, I failed to locate, where the iprintf get's mapped to printf. I would expect some macro in the headers or so, but I'm not able to locate it.

Could anyone explain what is happening or direct me, where to find this "mapping"?

Thx a lot

ST Renegade
  • 311
  • 3
  • 14

1 Answers1

3

At https://github.com/32bitmicro/newlib-nano-1.0/blob/master/newlib/libc/stdio/printf.c iprintf is an alias for printf:

_EXFUN(iprintf, (const char *, ...)
       _ATTRIBUTE ((alias("printf"))));

The nano printf() does not have floating-point support, so the iprintf() variant is the same function whereas in full Newlib, they would be distinct implementations.

Since they refer to the same implementation, whether your elf dump emits iprintf or printf as a matching symbol is perhaps arbitrary and possibly non-deterministic - that is a question about the how the linker symbol table is formed and perhaps the behaviour of objdump or nm whatever you used. They are simply different names for the same thing.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • Thx for pointing this out. I'm wondering, how relevant these newlib sources are, as it seems they were provided 9 years ago. Also the way how the compiler/linker uses the names is interesting. But I think there is no reason to delve deeper. Thx! :-) – ST Renegade Apr 08 '22 at 11:11
  • Seems this location https://guix.gnu.org/en/packages/newlib-nano-2.4.0/ references to the latest newlib-nano. Although the difference in case of printf is minor. – ST Renegade Apr 08 '22 at 11:16
  • @STRenegade : yes, sorry. I did not want to go to the trouble of downloading the package to check, and wanted an example that could be used in an answer. – Clifford Apr 09 '22 at 14:46