[PATCH] Use $(CC) when linking instead of $(LD) and use $(CFLAGS) when linking.

Nathan Phillip Brink ohnobinki at ohnopublishing.net
Mon Mar 7 02:36:56 UTC 2011


On Mon, Mar 07, 2011 at 02:37:38AM +0100, Denys Vlasenko wrote:
> On Monday 07 March 2011 01:59, Nathan Phillip Brink wrote:
> > This fixes the issue where LDFLAGS escaped with -Wl are ignored during
> > compilation. It also simplifies using CFLAGS (such as -m32 on x86_64)
> > which apply to both compilation and linking situations.
> 
> "make CFLAGS=-m32" disables ALL optimizations.
> You need to use EXTRA_CFLAGS (and EXTRA_LDFLAGS):
> 
>    text    data     bss     dec     hex filename
> 1134371    2125    9156 1145652  117b34 busybox_CFLAGSm32
>  769631    2067    9084  780782   be9ee busybox_EXTRA_CFLAGSm32
> 
> make EXTRA_CFLAGS=-m32 EXTRA_LDFLAGS=-m32 works without your patch.
> Do you see other reasons to apply it?

I would like to get rid of all direct calls to ld because I think it's
cleaner to directly call the compiler driver instead. Also, this does
fix the following TODO in Makefile.build:

# TODO: LDFLAGS usually is supposed to contain gcc's flags, not ld's.
# but here we feed them to ld!

What I'm saying is that removing the $(filter-out -Wl$(comma)%,$(LDFLAGS) $(EXTRA_LDFLAGS))
line is a benefit :-).

Also, concerning both CFLAGS and LDFLAGS, I like automake's behavior
of sending CFLAGS to every invocation of $(CC) instead of GNU Make's
behavior of only using LDFLAGS during linking. This way, CFLAGS rules
over the compiler driver, CPPFLAGS over compilation, and LDFLAGS over
linking.

Sorry about my ignorance about CFLAGS versus EXTRA_CFLAGS. I did
eventually notice that CFLAGS=-m32 disables optimizations and actually
used the simple CFLAGS=-m32\ -O2\ -pipe during one of my
compilations. It looks like I need to add EXTRA_CFLAGS to every place
that I added CFLAGS now if I want to pass CFLAGS during
linking. Should I throw another patch for that?

-- 
binki

Look out for missing apostrophes!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20110306/8f51c032/attachment-0001.asc>


More information about the busybox mailing list