> -----Original Message-----
> From: Joseph Myers <josmy...@redhat.com>
> Sent: 29 November 2024 21:48
> To: Prathamesh Kulkarni <prathame...@nvidia.com>
> Cc: Xi Ruoyao <xry...@xry111.site>; Matthew Malcomson
> <mmalcom...@nvidia.com>; gcc-patches@gcc.gnu.org
> Subject: RE: [RFC] PR81358: Enable automatic linking of libatomic
> 
> External email: Use caution opening links or attachments
> 
> 
> On Fri, 29 Nov 2024, Prathamesh Kulkarni wrote:
> 
> > > My expectation is that CFLAGS should not be modified until after
> > > save_CFLAGS is set, which should not be until after configure has
> > > executed the logic that sets a -g -O2 default.  Is there some
> > > problem with that ordering (e.g. configure tests that expect to
> link
> > > target programs but run as part of the same Autoconf macro
> > > invocation that also generates the logic to determine default
> > > values)?  Also, the
> > It seems that in configure, AC_PROG_CC expands to setting "-g -O2"
> in
> > CFLAGS, and running conftests using those CFLAGS, and any
> adjustments to CFLAGS after invoking AC_PROG_CC don't help.
> > In the attached patch, I simply moved save_CFLAGS and CFLAGS before
> > invoking AC_PROG_CC, and adding "-fno-link-libatomic" to CFLAGS,
> which seems to work, but not sure if it's the correct approach ?
> 
> I don't think having those settings before the default from AC_PROG_CC
> is logically right, because the default from AC_PROG_CC only applies
> if CFLAGS is not already set (that is, you'd lose the default -g -O2,
> if libatomic/configure is run without CFLAGS set).
> 
> The underlying principle is that CFLAGS is a variable for the *user*
> to set as they wish, not something that should be used for any options
> required as part of the build (that's what other things such as
> XCFLAGS and AM_CFLAGS are for).  So if you need to modify CFLAGS in
> configure for use as part of configure tests, it should only be done
> temporarily in a way that doesn't interfere with the normal logic to
> determine that default setting.  If for some reason that doesn't work
> (if AC_PROG_CC also runs tests that need modified CFLAGS, giving
> nowhere you get modify the value between the default being set and it
> being used), you'd need an assertion that libatomic/configure didn't
> get run with unset CFLAGS so the default wouldn't be applicable
> anyway, with appropriate comments explaining the issues.
Hi Joseph,
Thanks for the suggestions! Unfortunately, it seems to me that AC_PROG_CC also 
does run tests that
need modified CFLAGS. I tried the following assertion before invoking 
AC_PROG_CC (for stage-1 build):

if test -z "${CFLAGS}"; then
  AC_MSG_ERROR([CFLAGS must be set.])
fi

and it seems to pass. So I suppose the default setting of CFLAGS in AC_PROG_CC 
won't be applicable anyway ?
I checked what value CFLAGS was set to and it turned out to be "-g -O2" (same 
as default setting in AC_PROG_CC, altho I am not quite sure
where CFLAGS were set before invoking libatomic/configure). Given that the 
above assert passes, would it be safe to add "-fno-link-libatomic"
to CFLAGS before invoking AC_PROG_CC (and after the assert) ?

Thanks,
Prathamesh
> 
> --
> Joseph S. Myers
> josmy...@redhat.com

Reply via email to