This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [PATCH] newlib: Remove debug flag for --enable-target-optspace
- From: Stephanos Ioannidis <root at stephanos dot io>
- To: Andrew Pinski <pinskia at gmail dot com>, Jon Beniston <jon at beniston dot com>
- Cc: "<newlib at sourceware dot org>" <newlib at sourceware dot org>
- Date: Sat, 30 Nov 2019 05:31:52 +0000
- Subject: Re: [PATCH] newlib: Remove debug flag for --enable-target-optspace
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=stephanos.io; dmarc=pass action=none header.from=stephanos.io; dkim=pass header.d=stephanos.io; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F8T3QFO7B1tfGy8MgD1jY3naFF1lSkf2xh6ng5U7pzw=; b=Hk57qDWWRgD0c99hx6xo0eHyG3uXvaLFEG0eVQJUWmhbIxciAb8YLyHPGehV3IHAZXr4C1Xaipie00QSj9uJVjWesTI0TQfZ02/nGMNBwJu8rQX9erZrNY6vJKer4F8G4a4DaDO+DzwiVl5vIPatQqoy2AbfJtVWd5JqJ+8+8z9Ab5AY3gMK0No4m45S6UX7/qQmsN1TqaAm8Poo3VcOsQ7xikq79RArm/yFHZoOn7YRllVSZ3v7YT7KF9TxJyHKSNwAWXgKnIAFEiZIgFwqPtw70lGpAYjGuSDiYE5gyRr/c9iv/nD+eXGU6GcQZPXTKGzgQ2hnb4Se26RZheAnUw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TZXbTG7SEA7zHKQ3u+RaMQwjFs6TbZ+Ch0Xd+1k/scnk89gQPu4w7SHUk1HFYai/z6Il0lCx/sqHYgByiqNWvgSyuQIlkPyBDnF5dCDNJ5Ny9FT/RtJPeYXo6ZYSY/nfrd3g04XGAhmqh3Ds8UQxXqg3ZjrP7ueSKXdCHqTXiwVKR7GzsTjyuQh461ScTjj8Oh+mOTawBhvWJWZklsvnYz7Xh+WlpU2IquSsFMWTsYoszpFu7JyfDoiwySoBPEFL2RLB+5qDqLMMukwYS4LDWq69YLxJvxwd3bvBJbUw7oKBOX2n7RRbOLCioTSC00fudVBkFuAygiYVvorysVRnTw==
- References: <20191129034435.39599-1-root@stephanos.io> <005701d5a69b$32580a70$97081f50$@beniston.com> <PSXP216MB06478BDA3D5C6C27C5C59DBFBD460@PSXP216MB0647.KORP216.PROD.OUTLOOK.COM> <004901d5a6a6$e34b6a10$a9e23e30$@beniston.com>,<CA+=Sn1=k8MB5VxLP3D5X1Ujz38nxMUH2mq+16_ZWGAOQhGSWkA@mail.gmail.com>
Hi Andrew and Jon,
> Actually you are wrong. --enable-target-optspace changes the (normal)
CFLAGS to be "-g -O2 -g -Os". The "-g" in the config/mt-ospace is
redundant now.
It does seem that way (very messy though ...).
> The reasoning Stephanos is giving of removing the "-g" there is not
correct though.
If you are overriding CFLAGS for other purposes and want to _only_ enable `-Os`, you cannot use `--enable-target-optspace` because it has an unwanted side effect of enabling debug information output alongside optimisation for size. After all, the option is called `--enable-target-optspace`, not `--enable-target-optspace-and-debug-info`.
What is more frustrating is that the documentation for `--enable-target-optspace` mentions nothing about enabling debug information output and this can be very confusing and misleading to users; I spent hours trying out many different build options in attempt to figure out why the compiled libraries included debug information in spite of never being instructed to do so, until I finally decided to have a look at the newlib build scripts.
*By removing `-g` in `mt-ospace`, we can support both cases:*
1. CFLAGS is not overridden: Since the default CFLAGS is `-g -O2`, `-Os` will override`-O2` to optimise for size.
2. CFLAGS is overridden: It will simply add `-Os` to optimise for size. If user wanted debug information output, he/she will add "-g" in the CFLAGS separately.
One could possibly argue that user can simply put `-Os` in the overridden CFLAGS instead of using `--enable-target-optspace`, but that is not a valid excuse for the latter to misbehave.
> Because many people want to be able to debug their code!
Some might, some might not- especially if they are compiling newlib to be used by someone else, which would often be the case; the debug information is not very useful unless you have a local copy of the newlib source code.
For instance, GNU ARM Embedded build script is setting CFLAGS to `-Os` instead of using `--enable-target-optspace` because the latter is not achieving the intended behavior.
More importantly, I do not think any normal average person would somehow automatically assume `--enable-target-optspace` must mean enabling both optimisation for size and debugging information output!
Regards,
Stephanos
________________________________________
From: Andrew Pinski <pinskia@gmail.com>
Sent: 30 November 2019 10:13
To: Jon Beniston <jon@beniston.com>
Cc: Stephanos Ioannidis <root@stephanos.io>; <newlib@sourceware.org> <newlib@sourceware.org>
Subject: Re: [PATCH] newlib: Remove debug flag for --enable-target-optspace
On Fri, Nov 29, 2019 at 3:19 AM Jon Beniston <jon@beniston.com> wrote:
>
> Hi Stephanos,
>
> >As you suggested, the debug information added by `--enable-target-optspace`
> can be stripped, but why add it in the first place if it is not necessary?
>
> Because many people want to be able to debug their code!
>
> >Unless there is a good reason to keep `-g` and `-Os` together in
> `--enable-target-optspace`,
> >I strongly believe `-g` should be removed and moved into a separate
> configuration option.
>
> Currently the default for CFLAGS_FOR_TARGET is "-g -O2".
> --enable-target-optspace Changes this to "-g -Os"
Actually you are wrong. --enable-target-optspace changes the (normal)
CFLAGS to be "-g -O2 -g -Os". The "-g" in the config/mt-ospace is
redundant now.
Please see https://gcc.gnu.org/ml/gcc-patches/2014-11/msg02062.html as
that changed CFLAGS from being destroyed to be additional.
The reasoning Stephanos is giving of removing the "-g" there is not
correct though. I am saying the patch is correct but the REASON
behind of why it is correct is NOT. The "-g" is redudant and can be
removed from config/mt-ospace.
Thanks,
Andrew Pinski
>
> If -g is to be controlled by a separate option, then it should apply in both
> cases. And this new option should probably be enabled by default to maintain
> existing behaviour (so perhaps add a --disable-target-debug option that
> removes -g)
>
> Cheers,
> Jon
>
>