On Tue, 19 Nov 2024, Prathamesh Kulkarni wrote:

> +#ifdef USE_LD_AS_NEEDED
> +#define LINK_LIBATOMIC_SPEC "%{!fno-link-libatomic:" LD_AS_NEEDED_OPTION \
> +                         " -latomic " LD_NO_AS_NEEDED_OPTION "} "
> +#else
> +#define LINK_LIBATOMIC_SPEC ""
> +#endif

I'd expect conditionals to be set up so that, if libatomic is not built 
(typically because an unsupported target OS resulted in UNSUPPORTED=1 
being set in libatomic/configure.tgt), no attempt is ever made to link it 
in.  (So in that case, users might get undefined references to __atomic_* 
and it would be their responsibility to provide a board support package 
that links with appropriate definitions of those symbols.)

> diff --git a/libatomic/Makefile.am b/libatomic/Makefile.am

> +AM_CFLAGS = $(XCFLAGS) -fno-link-libatomic
> +AM_CCASFLAGS = $(XCFLAGS) -fno-link-libatomic
> +AM_LDFLAGS = $(XLDFLAGS) $(SECTION_LDFLAGS) $(OPT_LDFLAGS) 
> -fno-link-libatomic

> diff --git a/libatomic/configure.ac b/libatomic/configure.ac

> +CFLAGS="$CFLAGS -fno-link-libatomic"

> +XCFLAGS="$XCFLAGS $XPCFLAGS -fno-link-libatomic"

I don't see any clear conceptual design here for where this flag should 
go.  It should only need to be added in one place, not three times.  
Adding to CFLAGS before the default is set in configure, and before 
save_CFLAGS is set, seems especially dubious, though maybe you avoid 
problems with losing the default CFLAGS setting if libatomic is always 
configured with CFLAGS set by the toplevel Makefile.

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 comment on save_CFLAGS 
says:

# In order to override CFLAGS_FOR_TARGET, all of our special flags go
# in XCFLAGS.  But we need them in CFLAGS during configury.  So put them
# in both places for now and restore CFLAGS at the end of config.

So if the option is set in CFLAGS itself during configure, that should be 
after save_CFLAGS is set, meaning only the setting in XCFLAGS is relevant 
for actually building libatomic.

Also, the new command-line option should be documented in invoke.texi.

-- 
Joseph S. Myers
josmy...@redhat.com

Reply via email to