diff mbox

[1/7] kbuild: add ld-name macro and support for GNU gold

Message ID 20171129234442.655-2-samitolvanen@google.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sami Tolvanen Nov. 29, 2017, 11:44 p.m. UTC
GNU gold may require different flags than GNU ld. Add a macro for
detecting the linker and conditionally add gold specific flags from
LDFLAGS_GOLD.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
---
 Makefile               | 5 +++++
 scripts/Kbuild.include | 4 ++++
 2 files changed, 9 insertions(+)

Comments

Nick Desaulniers Nov. 30, 2017, 12:32 a.m. UTC | #1
On Wed, Nov 29, 2017 at 3:44 PM, Sami Tolvanen <samitolvanen@google.com> wrote:
> GNU gold may require different flags than GNU ld. Add a macro for
> detecting the linker and conditionally add gold specific flags from
> LDFLAGS_GOLD.

Right, but you're still only ever using one linker per build, correct?
 Can we get away without 2 distinct flags?

> +# Add any flags specific to ld.gold
> +ifeq ($(ld-name),gold)
> +LDFLAGS                += $(LDFLAGS_GOLD)
> +endif
> +

Patch 1 and 6 have this pattern of always assigning to LDFLAGS_GOLD,
then that to LDFLAGS.  Wouldn't it be better to check the ld-name and
conditionally assign to LDFLAGS? Then LDFLAGS_GOLD is not necessary.
For example, what I'm suggesting is what is done in patch 4.

> +# ld-name
> +# Expands to either bfd or gold
> +ld-name = $(shell $(LD) -v 2>&1 | grep -q "GNU gold" && echo gold || echo bfd)
> +

This part LGTM.
Sami Tolvanen Nov. 30, 2017, 5:38 p.m. UTC | #2
On Wed, Nov 29, 2017 at 04:32:52PM -0800, Nick Desaulniers wrote:
> Right, but you're still only ever using one linker per build, correct?

Correct. LDFLAGS_GOLD makes it move convenient to add gold specific flags
without explicit $(ld-name) checks everywhere, but I'm fine with removing
it in v2.

Sami
diff mbox

Patch

diff --git a/Makefile b/Makefile
index f761bf475ba5..a16c98d6e3ba 100644
--- a/Makefile
+++ b/Makefile
@@ -814,6 +814,11 @@  include scripts/Makefile.kasan
 include scripts/Makefile.extrawarn
 include scripts/Makefile.ubsan
 
+# Add any flags specific to ld.gold
+ifeq ($(ld-name),gold)
+LDFLAGS		+= $(LDFLAGS_GOLD)
+endif
+
 # Add any arch overrides and user supplied CPPFLAGS, AFLAGS and CFLAGS as the
 # last assignments
 KBUILD_CPPFLAGS += $(ARCH_CPPFLAGS) $(KCPPFLAGS)
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index b6d7d347b203..a7c7843c2cf1 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -277,6 +277,10 @@  ld-option = $(call try-run-cached,\
 # Important: no spaces around options
 ar-option = $(call try-run-cached, $(AR) rc$(1) "$$TMP",$(1),$(2))
 
+# ld-name
+# Expands to either bfd or gold
+ld-name = $(shell $(LD) -v 2>&1 | grep -q "GNU gold" && echo gold || echo bfd)
+
 # ld-version
 # Note this is mainly for HJ Lu's 3 number binutil versions
 ld-version = $(call shell-cached,$(LD) --version | $(srctree)/scripts/ld-version.sh)