public inbox for cygwin-developers@cygwin.com
 help / color / mirror / Atom feed
* automake issue
@ 2021-10-20 20:58 Ken Brown
  2021-10-21 10:48 ` Corinna Vinschen
  0 siblings, 1 reply; 5+ messages in thread
From: Ken Brown @ 2021-10-20 20:58 UTC (permalink / raw)
  To: cygwin-devel

I was debugging with what I thought was an unoptimized build of cygwin1.dll 
(with -O0 in CXXFLAGS), but then I discovered that malloc.cc was actually 
compiled with -O3.  This is because of the following snippet from 
winsup/cygwin/Makefile.am:

# If an optimization level is explicitly set in CXXFLAGS, set -O3 for these files
# XXX: this seems to assume it's not -O0?
#
# (the indentation here prevents automake trying to process this as an automake
# conditional)
  ifneq "${filter -O%,$(CXXFLAGS)}" ""
   malloc_CFLAGS=-O3
   sync_CFLAGS=-O3
  endif

I thought I could fix this by changing the snippet to

  ifneq "${filter -O%,$(CXXFLAGS)}" ""
   ifeq "${filter -O0,$(CXXFLAGS)}" ""
    malloc_CFLAGS=-O3
    sync_CFLAGS=-O3
   endif
  endif

but this didn't work.  After running winsup/autogen.sh, 
winsup/cygwin/Makefile.in contained

malloc_CFLAGS = -O3
sync_CFLAGS = -O3

unconditionally.

So in spite of the comment above about indentation, it seems that the 
conditional is being treated as an automake conditional.

Does anyone know how to fix this so that -O0 really produces an unoptimized build?

Ken

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: automake issue
  2021-10-20 20:58 automake issue Ken Brown
@ 2021-10-21 10:48 ` Corinna Vinschen
  2021-10-21 13:08   ` Jon Turney
  0 siblings, 1 reply; 5+ messages in thread
From: Corinna Vinschen @ 2021-10-21 10:48 UTC (permalink / raw)
  To: cygwin-developers

On Oct 20 16:58, Ken Brown wrote:
> I was debugging with what I thought was an unoptimized build of cygwin1.dll
> (with -O0 in CXXFLAGS), but then I discovered that malloc.cc was actually
> compiled with -O3.  This is because of the following snippet from
> winsup/cygwin/Makefile.am:
> 
> # If an optimization level is explicitly set in CXXFLAGS, set -O3 for these files
> # XXX: this seems to assume it's not -O0?
> #
> # (the indentation here prevents automake trying to process this as an automake
> # conditional)
>  ifneq "${filter -O%,$(CXXFLAGS)}" ""
>   malloc_CFLAGS=-O3
>   sync_CFLAGS=-O3
>  endif
> 
> I thought I could fix this by changing the snippet to
> 
>  ifneq "${filter -O%,$(CXXFLAGS)}" ""
>   ifeq "${filter -O0,$(CXXFLAGS)}" ""
>    malloc_CFLAGS=-O3
>    sync_CFLAGS=-O3
>   endif
>  endif
> 
> but this didn't work.  After running winsup/autogen.sh,
> winsup/cygwin/Makefile.in contained
> 
> malloc_CFLAGS = -O3
> sync_CFLAGS = -O3
> 
> unconditionally.
> 
> So in spite of the comment above about indentation, it seems that the
> conditional is being treated as an automake conditional.
> 
> Does anyone know how to fix this so that -O0 really produces an unoptimized build?

I workaround this by setting CFLAGS=-g on the command line.  There's no
-O then and it should work as desired.  The save thing would probably
be something like this, though:

https://stackoverflow.com/questions/4256609/makefile-conditional-with-automake-autoconf


Corinna

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: automake issue
  2021-10-21 10:48 ` Corinna Vinschen
@ 2021-10-21 13:08   ` Jon Turney
  2021-10-21 19:33     ` Ken Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Jon Turney @ 2021-10-21 13:08 UTC (permalink / raw)
  To: cygwin-developers

On 21/10/2021 11:48, Corinna Vinschen wrote:
> On Oct 20 16:58, Ken Brown wrote:
>> I was debugging with what I thought was an unoptimized build of cygwin1.dll
>> (with -O0 in CXXFLAGS), but then I discovered that malloc.cc was actually
>> compiled with -O3.  This is because of the following snippet from
>> winsup/cygwin/Makefile.am:
>>
>> # If an optimization level is explicitly set in CXXFLAGS, set -O3 for these files
>> # XXX: this seems to assume it's not -O0?

Note that this is my observation of a pre-existing issue, not something 
that's introduced by the automake conversion.

>> #
>> # (the indentation here prevents automake trying to process this as an automake
>> # conditional)
>>   ifneq "${filter -O%,$(CXXFLAGS)}" ""
>>    malloc_CFLAGS=-O3
>>    sync_CFLAGS=-O3
>>   endif
>>
>> I thought I could fix this by changing the snippet to
>>
>>   ifneq "${filter -O%,$(CXXFLAGS)}" ""
>>    ifeq "${filter -O0,$(CXXFLAGS)}" ""
>>     malloc_CFLAGS=-O3
>>     sync_CFLAGS=-O3
>>    endif
>>   endif

Clever.  It didn't occur to me to write something like this.

>> but this didn't work.  After running winsup/autogen.sh,
>> winsup/cygwin/Makefile.in contained
>>
>> malloc_CFLAGS = -O3
>> sync_CFLAGS = -O3
>>
>> unconditionally.

Hmm.. yes.  That's disappointing.  I think it was working at some stage, 
so idk if this is a automake change?

>> So in spite of the comment above about indentation, it seems that the
>> conditional is being treated as an automake conditional.
>>
>> Does anyone know how to fix this so that -O0 really produces an unoptimized build?
> 
> I workaround this by setting CFLAGS=-g on the command line.  There's no
> -O then and it should work as desired.  The save thing would probably
> be something like this, though:
> 
> https://stackoverflow.com/questions/4256609/makefile-conditional-with-automake-autoconf

Using an automake conditional isn't good, because that can't  consider 
the value of CXXFLAGS if it's overriden on the 'make' command line.

Really, I'm not sure if this block is a good idea at all.  I did 
consider removing it when converting to automake.

I couldn't find any history which suggests these flags are here due to 
evidence ('using -O3 makes this benchmark faster'), rather than 
guesswork ('these files probably contain hotspots, so use -O3 to make it 
go faster!').

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: automake issue
  2021-10-21 13:08   ` Jon Turney
@ 2021-10-21 19:33     ` Ken Brown
  2021-10-22  8:44       ` Corinna Vinschen
  0 siblings, 1 reply; 5+ messages in thread
From: Ken Brown @ 2021-10-21 19:33 UTC (permalink / raw)
  To: cygwin-developers

On 10/21/2021 9:08 AM, Jon Turney wrote:
> On 21/10/2021 11:48, Corinna Vinschen wrote:
>> On Oct 20 16:58, Ken Brown wrote:
>>> I was debugging with what I thought was an unoptimized build of cygwin1.dll
>>> (with -O0 in CXXFLAGS), but then I discovered that malloc.cc was actually
>>> compiled with -O3.  This is because of the following snippet from
>>> winsup/cygwin/Makefile.am:
>>>
>>> # If an optimization level is explicitly set in CXXFLAGS, set -O3 for these 
>>> files
>>> # XXX: this seems to assume it's not -O0?
> 
> Note that this is my observation of a pre-existing issue, not something that's 
> introduced by the automake conversion.
> 
>>> #
>>> # (the indentation here prevents automake trying to process this as an automake
>>> # conditional)
>>>   ifneq "${filter -O%,$(CXXFLAGS)}" ""
>>>    malloc_CFLAGS=-O3
>>>    sync_CFLAGS=-O3
>>>   endif
>>>
>>> I thought I could fix this by changing the snippet to
>>>
>>>   ifneq "${filter -O%,$(CXXFLAGS)}" ""
>>>    ifeq "${filter -O0,$(CXXFLAGS)}" ""
>>>     malloc_CFLAGS=-O3
>>>     sync_CFLAGS=-O3
>>>    endif
>>>   endif
> 
> Clever.  It didn't occur to me to write something like this.
> 
>>> but this didn't work.  After running winsup/autogen.sh,
>>> winsup/cygwin/Makefile.in contained
>>>
>>> malloc_CFLAGS = -O3
>>> sync_CFLAGS = -O3
>>>
>>> unconditionally.
> 
> Hmm.. yes.  That's disappointing.  I think it was working at some stage, so idk 
> if this is a automake change?
> 
>>> So in spite of the comment above about indentation, it seems that the
>>> conditional is being treated as an automake conditional.
>>>
>>> Does anyone know how to fix this so that -O0 really produces an unoptimized 
>>> build?
>>
>> I workaround this by setting CFLAGS=-g on the command line.  There's no
>> -O then and it should work as desired.  The save thing would probably
>> be something like this, though:
>>
>> https://stackoverflow.com/questions/4256609/makefile-conditional-with-automake-autoconf 
>>
> 
> Using an automake conditional isn't good, because that can't  consider the value 
> of CXXFLAGS if it's overriden on the 'make' command line.
> 
> Really, I'm not sure if this block is a good idea at all.  I did consider 
> removing it when converting to automake.
> 
> I couldn't find any history which suggests these flags are here due to evidence 
> ('using -O3 makes this benchmark faster'), rather than guesswork ('these files 
> probably contain hotspots, so use -O3 to make it go faster!').

It's too bad we don't know why this was done.  In the meantime, I'll work around 
the problem by using a private branch in which that block is removed.  I tried 
Corinna's suggestion of setting CFLAGS=-g, but that didn't produce an 
unoptimized build.  I still saw '-O2 -g' when building newlib and '-O2 -g -g 
-O2' when building cygwin.

Ken

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: automake issue
  2021-10-21 19:33     ` Ken Brown
@ 2021-10-22  8:44       ` Corinna Vinschen
  0 siblings, 0 replies; 5+ messages in thread
From: Corinna Vinschen @ 2021-10-22  8:44 UTC (permalink / raw)
  To: cygwin-developers

On Oct 21 15:33, Ken Brown wrote:
> On 10/21/2021 9:08 AM, Jon Turney wrote:
> > On 21/10/2021 11:48, Corinna Vinschen wrote:
> > > On Oct 20 16:58, Ken Brown wrote:
> > > > I was debugging with what I thought was an unoptimized build of cygwin1.dll
> > > > (with -O0 in CXXFLAGS), but then I discovered that malloc.cc was actually
> > > > compiled with -O3.  This is because of the following snippet from
> > > > winsup/cygwin/Makefile.am:
> > > > [...]
> > I couldn't find any history which suggests these flags are here due to
> > evidence ('using -O3 makes this benchmark faster'), rather than
> > guesswork ('these files probably contain hotspots, so use -O3 to make it
> > go faster!').
> 
> It's too bad we don't know why this was done.

Optimization.  Either 9 or 16 years ago.  Using very different GCC
versions and *only* on 32 bit at the time.  It's pretty unlikely they
are still needed, especially on 64 bit.  If it works fine without them,
we should just remove them.

> In the meantime, I'll work
> around the problem by using a private branch in which that block is removed.
> I tried Corinna's suggestion of setting CFLAGS=-g, but that didn't produce
> an unoptimized build.  I still saw '-O2 -g' when building newlib and '-O2 -g
> -g -O2' when building cygwin.

Yeah, I configure the entire tree with C{XX}FLAGS=-g from scratch for
en entirely unoptimized tree, because I want newlib usually unoptimized
as well.


Corinna

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-10-22  8:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-20 20:58 automake issue Ken Brown
2021-10-21 10:48 ` Corinna Vinschen
2021-10-21 13:08   ` Jon Turney
2021-10-21 19:33     ` Ken Brown
2021-10-22  8:44       ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).