Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch.embedded > #28789

Re: No dynamic memory at all: newlib and sprintf

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.arch.embedded
Subject Re: No dynamic memory at all: newlib and sprintf
Date 2019-09-01 22:47 +0200
Organization A noiseless patient Spider
Message-ID <qkhapc$ica$1@dont-email.me> (permalink)
References (1 earlier) <qkakta$qbg$1@dont-email.me> <qkamdp$2ka$1@dont-email.me> <qkantj$ao8$1@dont-email.me> <qkb4bc$fea$1@dont-email.me> <qkb8v7$bt3$1@dont-email.me>

Show all headers | View raw


On 30/08/2019 15:39, pozz wrote:
> Il 30/08/2019 14:21, pozz ha scritto:
>> Il 30/08/2019 10:48, David Brown ha scritto:
>  >[...]
>> However I tried to replace sprintf() with a custom sprintf(), but in 
>> this case the linker complains with:
>>
>>    multiple definition of `sprintf'
>>
>> It sees two definitions in my printf.c and in libc_nano.a. Could you 
>> argue why this happens with sprintf() and not with malloc()?

Are you sure?  Have you checked the map file (and given the linker 
settings for showing detailed information in the map file) ?

> 
> After seen that -O1 linker option solves this problem, I found the option
> 
>    --allow-multiple-definition
> 
> that works even with -O0, that I use in debug build.
> 

It seems risky to allow multiple definitions.  It's not an option I have 
used - I'd need to look more deeply into documentation before I can be 
more helpful.

I never recommend using -O0, for any purpose.  Code at -O1 (on gcc at 
least) is much easier for debugging, with far clearer assembly.  More 
importantly, it enables a lot more analysis on the compiler and 
therefore gives far more accurate static warnings.

I usually compile at approximately -O2 (by "approximately", I mean I 
often have some additional specific flags added).  It can make 
single-step debugging difficult because it re-arranges code a lot, so 
occasionally I will go down to -O1 for a file if I need to use a lot of 
single-step or assembly level debugging on it.

I am strongly against the whole concept of "debug build" and "release 
build" if it encourages you to use different optimisation levels and 
settings.  Enabling or disabling verbose outputs for different bits of 
the code is okay.

Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

No dynamic memory at all: newlib and sprintf pozz <pozzugno@gmail.com> - 2019-08-30 09:29 +0200
  Re: No dynamic memory at all: newlib and sprintf David Brown <david.brown@hesbynett.no> - 2019-08-30 09:57 +0200
    Re: No dynamic memory at all: newlib and sprintf pozz <pozzugno@gmail.com> - 2019-08-30 10:23 +0200
      Re: No dynamic memory at all: newlib and sprintf David Brown <david.brown@hesbynett.no> - 2019-08-30 10:48 +0200
        Re: No dynamic memory at all: newlib and sprintf pozz <pozzugno@gmail.com> - 2019-08-30 14:21 +0200
          Re: No dynamic memory at all: newlib and sprintf pozz <pozzugno@gmail.com> - 2019-08-30 15:39 +0200
            Re: No dynamic memory at all: newlib and sprintf David Brown <david.brown@hesbynett.no> - 2019-09-01 22:47 +0200
              Re: No dynamic memory at all: newlib and sprintf pozz <pozzugno@gmail.com> - 2019-09-01 23:53 +0200
                Re: No dynamic memory at all: newlib and sprintf David Brown <david.brown@hesbynett.no> - 2019-09-02 13:09 +0200
    Re: No dynamic memory at all: newlib and sprintf pozz <pozzugno@gmail.com> - 2019-08-30 10:35 +0200
  Re: No dynamic memory at all: newlib and sprintf Paul Rubin <no.email@nospam.invalid> - 2019-08-30 01:46 -0700
  Re: No dynamic memory at all: newlib and sprintf Dave Nadler <drn@nadler.com> - 2019-08-30 06:17 -0700

csiph-web