help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Rd: Using the same options for compiling and linking


From: Britton Kerin
Subject: Rd: Using the same options for compiling and linking
Date: Mon, 6 May 2013 08:05:03 -0800

On Sun, May 5, 2013 at 9:03 AM, Pau Koning <address@hidden> wrote:
> Hi,
>
> there are currently some things going on regarding the analysis of the
> build logs using blhc. This is extreme nice and made me think about a
> sentence most people missed in the GCC documentation (it is repeated often):
>
> "For predictable results, you must also specify the same set of options
> used for compilation (-fpic, -fPIC, or model suboptions) when you specify
> this linker option."
>
> Most of the time it works quite well, but what happens when somebody wants
> to enable -flto (just using the environment CFLAGS variable)? For example
> libtool will then stop to generate debug info because it drops the -g from
> Debians CFLAGS in the linking stage.
>
> Or as another example take the builtin rules from GNU make:
>
> LINK.o = $(CC) $(LDFLAGS) $(TARGET_ARCH)
>
> %: %.o
> #  commands to execute (built-in):
> $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
>
> It is missing the CFLAGS completely. So, the requested optimizations
> (either added by the Makefile to CFLAGS or by the user environment) is now
> completely dropped and only linker flags are used during the -flto compile
> step during the linking (when CFLAGS and LDFLAGS have -flto). Or the
> link-time optimization is not done as expected (-flto only specified in
> CFLAGS)
>
> This is rather problematic for my example but also subtle defects can
> happen.
>
> Any thoughts on making this a long term QA goal? Or are there other ideas
> about this problem? I've Cc'ed the mentioned projects to allow them to make
> statements about their position.

Don't use the built-in rules or variables (always invoke make with -rR).
Better yet, don't use implicit rules at all (use static pattern rules).
Especially don't use the builtin rules for the linker.  It would be nice if
make provided a way to disable built in rules and variable form the Makefile
itself instead of from the command line.  Assigning to MAKEFLAGS only affects
sub-makes, despite this (wrong) paragraph from the documentation:

     MAKEFLAGS
         The flags given to make. You can set this in the environment
or a makefile to set flags.
         See Communicating Options to a Sub-make.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]