linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] Add support for GNU gold
@ 2017-11-29 23:44 Sami Tolvanen
  2017-11-29 23:44 ` [PATCH 1/7] kbuild: add ld-name macro and " Sami Tolvanen
                   ` (7 more replies)
  0 siblings, 8 replies; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-29 23:44 UTC (permalink / raw)
  To: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke, Nicholas Piggin
  Cc: Sami Tolvanen

These patches add macros for detecting the linker name and version,
and apply fixes and workarounds needed to link the arm64 kernel with
GNU gold.

Sami Tolvanen (7):
  kbuild: add ld-name macro and support for GNU gold
  kbuild: add ld-if-name-version and linker-specific macros
  kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION with GNU gold
  arm64: fix -m for GNU gold
  arm64: keep .altinstructions and .altinstr_replacement
  arm64: explicitly pass --no-fix-cortex-a53-843419 to GNU gold
  arm64: add a workaround for GNU gold with ARM64_MODULE_PLTS

 Makefile                          |  5 +++++
 arch/arm64/Makefile               | 17 +++++++++++++++++
 arch/arm64/kernel/module.lds      |  4 ++--
 arch/arm64/kernel/vmlinux.lds.S   |  4 ++--
 include/asm-generic/vmlinux.lds.h |  8 ++++----
 scripts/Kbuild.include            | 16 ++++++++++++++++
 6 files changed, 46 insertions(+), 8 deletions(-)

-- 
2.15.0.531.g2ccb3012c9-goog

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 1/7] kbuild: add ld-name macro and support for GNU gold
  2017-11-29 23:44 [PATCH 0/7] Add support for GNU gold Sami Tolvanen
@ 2017-11-29 23:44 ` Sami Tolvanen
  2017-11-30  0:32   ` Nick Desaulniers
  2017-11-29 23:44 ` [PATCH 2/7] kbuild: add ld-if-name-version and linker-specific macros Sami Tolvanen
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-29 23:44 UTC (permalink / raw)
  To: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke, Nicholas Piggin
  Cc: Sami Tolvanen

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(+)

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)
-- 
2.15.0.531.g2ccb3012c9-goog

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 2/7] kbuild: add ld-if-name-version and linker-specific macros
  2017-11-29 23:44 [PATCH 0/7] Add support for GNU gold Sami Tolvanen
  2017-11-29 23:44 ` [PATCH 1/7] kbuild: add ld-name macro and " Sami Tolvanen
@ 2017-11-29 23:44 ` Sami Tolvanen
  2017-11-29 23:44 ` [PATCH 3/7] kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION with GNU gold Sami Tolvanen
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-29 23:44 UTC (permalink / raw)
  To: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke, Nicholas Piggin
  Cc: Sami Tolvanen

Add macros for testing both linker name and version.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
---
 scripts/Kbuild.include | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index a7c7843c2cf1..5d286d69e8dc 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -289,6 +289,18 @@ ld-version = $(call shell-cached,$(LD) --version | $(srctree)/scripts/ld-version
 # Usage:  $(call ld-ifversion, -ge, 22252, y)
 ld-ifversion = $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo $(4))
 
+# ld-if-name-version
+# Usage:  $(call ld-if-name-version, gold, -ge, 112000000, y)
+ld-if-name-version = $(shell [ $(ld-name) == $(1) ] && [ $(ld-version) $(2) $(3) ] && echo $(4) || echo $(5))
+
+# bfd-ifversion
+# Usage:  $(call bfd-ifversion, -ge, 227000000, y)
+bfd-ifversion = $(call ld-if-name-version, bfd, $(1), $(2), $(3), $(4))
+
+# gold-ifversion
+# Usage:  $(call gold-ifversion, -ge, 112000000, y)
+gold-ifversion = $(call ld-if-name-version, gold, $(1), $(2), $(3), $(4))
+
 ######
 
 ###
-- 
2.15.0.531.g2ccb3012c9-goog

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 3/7] kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION with GNU gold
  2017-11-29 23:44 [PATCH 0/7] Add support for GNU gold Sami Tolvanen
  2017-11-29 23:44 ` [PATCH 1/7] kbuild: add ld-name macro and " Sami Tolvanen
  2017-11-29 23:44 ` [PATCH 2/7] kbuild: add ld-if-name-version and linker-specific macros Sami Tolvanen
@ 2017-11-29 23:44 ` Sami Tolvanen
  2017-11-30  2:10   ` Nicholas Piggin
  2017-11-29 23:44 ` [PATCH 4/7] arm64: fix -m for " Sami Tolvanen
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-29 23:44 UTC (permalink / raw)
  To: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke, Nicholas Piggin
  Cc: Sami Tolvanen

Don't remove .head.text or .exitcall.exit when linking with --gc-sections,
and include .init.text.* in .init.text and .init.rodata.* in .init.rodata.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
---
 include/asm-generic/vmlinux.lds.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index ee8b707d9fa9..eb4199c12bd2 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -515,7 +515,7 @@
 		VMLINUX_SYMBOL(__softirqentry_text_end) = .;
 
 /* Section used for early init (in .S files) */
-#define HEAD_TEXT  *(.head.text)
+#define HEAD_TEXT  KEEP(*(.head.text))
 
 #define HEAD_TEXT_SECTION							\
 	.head.text : AT(ADDR(.head.text) - LOAD_OFFSET) {		\
@@ -560,7 +560,7 @@
 	MEM_DISCARD(init.data)						\
 	KERNEL_CTORS()							\
 	MCOUNT_REC()							\
-	*(.init.rodata)							\
+	*(.init.rodata .init.rodata.*)					\
 	FTRACE_EVENTS()							\
 	TRACE_SYSCALLS()						\
 	KPROBE_BLACKLIST()						\
@@ -579,7 +579,7 @@
 	EARLYCON_TABLE()
 
 #define INIT_TEXT							\
-	*(.init.text)							\
+	*(.init.text .init.text.*)					\
 	*(.text.startup)						\
 	MEM_DISCARD(init.text)
 
@@ -596,7 +596,7 @@
 	MEM_DISCARD(exit.text)
 
 #define EXIT_CALL							\
-	*(.exitcall.exit)
+	KEEP(*(.exitcall.exit))
 
 /*
  * bss (Block Started by Symbol) - uninitialized data
-- 
2.15.0.531.g2ccb3012c9-goog

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 4/7] arm64: fix -m for GNU gold
  2017-11-29 23:44 [PATCH 0/7] Add support for GNU gold Sami Tolvanen
                   ` (2 preceding siblings ...)
  2017-11-29 23:44 ` [PATCH 3/7] kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION with GNU gold Sami Tolvanen
@ 2017-11-29 23:44 ` Sami Tolvanen
  2017-11-29 23:44 ` [PATCH 5/7] arm64: keep .altinstructions and .altinstr_replacement Sami Tolvanen
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-29 23:44 UTC (permalink / raw)
  To: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke, Nicholas Piggin
  Cc: Sami Tolvanen

GNU gold supports different emulations than bfd. Use aarch64_elf64_*_vec
instead of aarch64linux.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Acked-by: Yury Norov <ynorov@caviumnetworks.com>
---
 arch/arm64/Makefile | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index b35788c909f1..82a0df6e865e 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -64,14 +64,22 @@ KBUILD_CPPFLAGS	+= -mbig-endian
 CHECKFLAGS	+= -D__AARCH64EB__
 AS		+= -EB
 LD		+= -EB
+ifeq ($(ld-name),gold)
+LDFLAGS		+= -maarch64_elf64_be_vec
+else
 LDFLAGS		+= -maarch64linuxb
+endif
 UTS_MACHINE	:= aarch64_be
 else
 KBUILD_CPPFLAGS	+= -mlittle-endian
 CHECKFLAGS	+= -D__AARCH64EL__
 AS		+= -EL
 LD		+= -EL
+ifeq ($(ld-name),gold)
+LDFLAGS		+= -maarch64_elf64_le_vec
+else
 LDFLAGS		+= -maarch64linux
+endif
 UTS_MACHINE	:= aarch64
 endif
 
-- 
2.15.0.531.g2ccb3012c9-goog

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 5/7] arm64: keep .altinstructions and .altinstr_replacement
  2017-11-29 23:44 [PATCH 0/7] Add support for GNU gold Sami Tolvanen
                   ` (3 preceding siblings ...)
  2017-11-29 23:44 ` [PATCH 4/7] arm64: fix -m for " Sami Tolvanen
@ 2017-11-29 23:44 ` Sami Tolvanen
  2017-11-29 23:57   ` Nick Desaulniers
  2017-11-29 23:44 ` [PATCH 6/7] arm64: explicitly pass --no-fix-cortex-a53-843419 to GNU gold Sami Tolvanen
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-29 23:44 UTC (permalink / raw)
  To: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke, Nicholas Piggin
  Cc: Sami Tolvanen

Make sure the linker doesn't remove .altinstructions or
.altinstr_replacement when CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is
enabled.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
---
 arch/arm64/kernel/vmlinux.lds.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index 7da3e5c366a0..15479995869c 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -138,11 +138,11 @@ SECTIONS
 	. = ALIGN(4);
 	.altinstructions : {
 		__alt_instructions = .;
-		*(.altinstructions)
+		KEEP(*(.altinstructions))
 		__alt_instructions_end = .;
 	}
 	.altinstr_replacement : {
-		*(.altinstr_replacement)
+		KEEP(*(.altinstr_replacement))
 	}
 
 	. = ALIGN(PAGE_SIZE);
-- 
2.15.0.531.g2ccb3012c9-goog

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 6/7] arm64: explicitly pass --no-fix-cortex-a53-843419 to GNU gold
  2017-11-29 23:44 [PATCH 0/7] Add support for GNU gold Sami Tolvanen
                   ` (4 preceding siblings ...)
  2017-11-29 23:44 ` [PATCH 5/7] arm64: keep .altinstructions and .altinstr_replacement Sami Tolvanen
@ 2017-11-29 23:44 ` Sami Tolvanen
  2017-11-30  0:30   ` Nick Desaulniers
  2017-11-29 23:44 ` [PATCH 7/7] arm64: add a workaround for GNU gold with ARM64_MODULE_PLTS Sami Tolvanen
  2017-11-30 23:38 ` [PATCH v2 0/7] Add support for GNU gold Sami Tolvanen
  7 siblings, 1 reply; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-29 23:44 UTC (permalink / raw)
  To: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke, Nicholas Piggin
  Cc: Sami Tolvanen

Some versions of GNU gold are known to produce broken code with
--fix-cortex-a53-843419 as explained in this bug:

  https://sourceware.org/bugzilla/show_bug.cgi?id=21491

If ARM64_ERRATUM_843419 is disabled and we're using GNU gold, pass
--no-fix-cortex-a53-843419 to the linker to ensure the erratum
fix is not used even if the linker is configured to enable it by
default.

This change also adds a warning if the erratum fix is enabled and
gold version <1.14 is used.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
---
 arch/arm64/Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 82a0df6e865e..81a12713f7af 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -26,10 +26,19 @@ ifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
   ifeq ($(call ld-option, --fix-cortex-a53-843419),)
 $(warning ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum)
   else
+    ifeq ($(call gold-ifversion, -lt, 114000000, y), y)
+$(warning This version of GNU gold may generate incorrect code with --fix-cortex-a53-843419;\
+	see https://sourceware.org/bugzilla/show_bug.cgi?id=21491)
+    endif
 LDFLAGS_vmlinux	+= --fix-cortex-a53-843419
   endif
 endif
 
+ifeq ($(CONFIG_ARM64_ERRATUM_843419),)
+# https://sourceware.org/bugzilla/show_bug.cgi?id=21491
+LDFLAGS_GOLD	+= --no-fix-cortex-a53-843419
+endif
+
 KBUILD_DEFCONFIG := defconfig
 
 # Check for binutils support for specific extensions
-- 
2.15.0.531.g2ccb3012c9-goog

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 7/7] arm64: add a workaround for GNU gold with ARM64_MODULE_PLTS
  2017-11-29 23:44 [PATCH 0/7] Add support for GNU gold Sami Tolvanen
                   ` (5 preceding siblings ...)
  2017-11-29 23:44 ` [PATCH 6/7] arm64: explicitly pass --no-fix-cortex-a53-843419 to GNU gold Sami Tolvanen
@ 2017-11-29 23:44 ` Sami Tolvanen
  2017-11-30  9:31   ` Ard Biesheuvel
  2017-11-30 23:38 ` [PATCH v2 0/7] Add support for GNU gold Sami Tolvanen
  7 siblings, 1 reply; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-29 23:44 UTC (permalink / raw)
  To: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke, Nicholas Piggin
  Cc: Sami Tolvanen

All current versions of GNU gold crash when linking kernel modules
with ARM64_MODULE_PLTS due to a known bug:

  https://sourceware.org/bugzilla/show_bug.cgi?id=14592

To work around the problem, this change removes NOLOAD from .plt
and .init.plt.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
---
 arch/arm64/kernel/module.lds | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/module.lds b/arch/arm64/kernel/module.lds
index f7c9781a9d48..eacb5c67f61e 100644
--- a/arch/arm64/kernel/module.lds
+++ b/arch/arm64/kernel/module.lds
@@ -1,4 +1,4 @@
 SECTIONS {
-	.plt (NOLOAD) : { BYTE(0) }
-	.init.plt (NOLOAD) : { BYTE(0) }
+	.plt : { BYTE(0) }
+	.init.plt : { BYTE(0) }
 }
-- 
2.15.0.531.g2ccb3012c9-goog

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH 5/7] arm64: keep .altinstructions and .altinstr_replacement
  2017-11-29 23:44 ` [PATCH 5/7] arm64: keep .altinstructions and .altinstr_replacement Sami Tolvanen
@ 2017-11-29 23:57   ` Nick Desaulniers
  2017-11-30  1:58     ` Nicholas Piggin
  0 siblings, 1 reply; 28+ messages in thread
From: Nick Desaulniers @ 2017-11-29 23:57 UTC (permalink / raw)
  To: Sami Tolvanen
  Cc: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, Linux Kbuild mailing list, LKML,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Yury Norov, Matthias Kaehlcke, Nicholas Piggin

On Wed, Nov 29, 2017 at 3:44 PM, Sami Tolvanen <samitolvanen@google.com> wrote:
> Make sure the linker doesn't remove .altinstructions or
> .altinstr_replacement when CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is
> enabled.

This sounds like a bug in the original implementation of
CONFIG_LD_DEAD_CODE_DATA_ELIMINATION? If so, this can likely get
merged regardless of the rest of the patchset, ie. gold support.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 6/7] arm64: explicitly pass --no-fix-cortex-a53-843419 to GNU gold
  2017-11-29 23:44 ` [PATCH 6/7] arm64: explicitly pass --no-fix-cortex-a53-843419 to GNU gold Sami Tolvanen
@ 2017-11-30  0:30   ` Nick Desaulniers
  2017-11-30 17:50     ` Sami Tolvanen
  0 siblings, 1 reply; 28+ messages in thread
From: Nick Desaulniers @ 2017-11-30  0:30 UTC (permalink / raw)
  To: Sami Tolvanen
  Cc: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, Linux Kbuild mailing list, LKML,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Yury Norov, Matthias Kaehlcke, Nicholas Piggin

On Wed, Nov 29, 2017 at 3:44 PM, Sami Tolvanen <samitolvanen@google.com> wrote:
> @@ -26,10 +26,19 @@ ifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
>    ifeq ($(call ld-option, --fix-cortex-a53-843419),)
>  $(warning ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum)
>    else
> +    ifeq ($(call gold-ifversion, -lt, 114000000, y), y)
> +$(warning This version of GNU gold may generate incorrect code with --fix-cortex-a53-843419;\
> +       see https://sourceware.org/bugzilla/show_bug.cgi?id=21491)
> +    endif
>  LDFLAGS_vmlinux        += --fix-cortex-a53-843419
>    endif
>  endif
>
> +ifeq ($(CONFIG_ARM64_ERRATUM_843419),)
> +# https://sourceware.org/bugzilla/show_bug.cgi?id=21491
> +LDFLAGS_GOLD   += --no-fix-cortex-a53-843419
> +endif
> +

Rather than:

if CONFIG_ARM64_ERRATUM_843419 == y:
  ...
if CONFIG_ARM64_ERRATUM_843419 == '':
  ...

could this be:

if CONFIG_ARM64_ERRATUM_843419 == y:
  ...
else
  ...

?

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 1/7] kbuild: add ld-name macro and support for GNU gold
  2017-11-29 23:44 ` [PATCH 1/7] kbuild: add ld-name macro and " Sami Tolvanen
@ 2017-11-30  0:32   ` Nick Desaulniers
  2017-11-30 17:38     ` Sami Tolvanen
  0 siblings, 1 reply; 28+ messages in thread
From: Nick Desaulniers @ 2017-11-30  0:32 UTC (permalink / raw)
  To: Sami Tolvanen
  Cc: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, Linux Kbuild mailing list, LKML,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Yury Norov, Matthias Kaehlcke, Nicholas Piggin

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.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 5/7] arm64: keep .altinstructions and .altinstr_replacement
  2017-11-29 23:57   ` Nick Desaulniers
@ 2017-11-30  1:58     ` Nicholas Piggin
  2017-11-30 17:00       ` Nick Desaulniers
  2017-11-30 17:48       ` Sami Tolvanen
  0 siblings, 2 replies; 28+ messages in thread
From: Nicholas Piggin @ 2017-11-30  1:58 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Sami Tolvanen, Alex Matveev, Andi Kleen, Ard Biesheuvel,
	Greg Hackmann, Kees Cook, linux-arm-kernel,
	Linux Kbuild mailing list, LKML, Mark Rutland, Masahiro Yamada,
	Maxim Kuvyrkov, Michal Marek, Yury Norov, Matthias Kaehlcke

On Wed, 29 Nov 2017 15:57:53 -0800
Nick Desaulniers <ndesaulniers@google.com> wrote:

> On Wed, Nov 29, 2017 at 3:44 PM, Sami Tolvanen <samitolvanen@google.com> wrote:
> > Make sure the linker doesn't remove .altinstructions or
> > .altinstr_replacement when CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is
> > enabled.  
> 
> This sounds like a bug in the original implementation of
> CONFIG_LD_DEAD_CODE_DATA_ELIMINATION? If so, this can likely get
> merged regardless of the rest of the patchset, ie. gold support.

Yes, also patch 3/7 probably (thanks for doing these, btw). The
LD_DCDE option is actually been broken upstream thanks to lack
of time (which is a known issue, this is why no arch enables it).

Basically it just needs a bit more effort to go through and
ensure nothing is discarded incorrectly, and all new sections
are placed into output sections, before each arch is enabled.

(Comparing `readelf -S` before/after is a way to spot bugs.)

So yes please if it's not too much trouble, could you remove
the "gold" name from the generic patch and put it at the front
of the series with this arm64 patch. Possibly then you could
also do a 3rd patch to allow arm64 to select it if it's working
with gcc?

Thanks,
Nick

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 3/7] kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION with GNU gold
  2017-11-29 23:44 ` [PATCH 3/7] kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION with GNU gold Sami Tolvanen
@ 2017-11-30  2:10   ` Nicholas Piggin
  0 siblings, 0 replies; 28+ messages in thread
From: Nicholas Piggin @ 2017-11-30  2:10 UTC (permalink / raw)
  To: Sami Tolvanen
  Cc: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke

On Wed, 29 Nov 2017 15:44:38 -0800
Sami Tolvanen <samitolvanen@google.com> wrote:

> Don't remove .head.text or .exitcall.exit when linking with --gc-sections,
> and include .init.text.* in .init.text and .init.rodata.* in .init.rodata.
> 
> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>

Fine by me, if you consider my other comments.

Reviewed-by: Nicholas Piggin <npiggin@gmail.com>

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 7/7] arm64: add a workaround for GNU gold with ARM64_MODULE_PLTS
  2017-11-29 23:44 ` [PATCH 7/7] arm64: add a workaround for GNU gold with ARM64_MODULE_PLTS Sami Tolvanen
@ 2017-11-30  9:31   ` Ard Biesheuvel
  0 siblings, 0 replies; 28+ messages in thread
From: Ard Biesheuvel @ 2017-11-30  9:31 UTC (permalink / raw)
  To: Sami Tolvanen
  Cc: Alex Matveev, Andi Kleen, Greg Hackmann, Kees Cook,
	linux-arm-kernel, linux-kbuild, linux-kernel, Mark Rutland,
	Masahiro Yamada, Maxim Kuvyrkov, Michal Marek, Nick Desaulniers,
	Yury Norov, Matthias Kaehlcke, Nicholas Piggin

On 29 November 2017 at 23:44, Sami Tolvanen <samitolvanen@google.com> wrote:
> All current versions of GNU gold crash when linking kernel modules
> with ARM64_MODULE_PLTS due to a known bug:
>
>   https://sourceware.org/bugzilla/show_bug.cgi?id=14592
>
> To work around the problem, this change removes NOLOAD from .plt
> and .init.plt.
>
> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>

Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> ---
>  arch/arm64/kernel/module.lds | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/kernel/module.lds b/arch/arm64/kernel/module.lds
> index f7c9781a9d48..eacb5c67f61e 100644
> --- a/arch/arm64/kernel/module.lds
> +++ b/arch/arm64/kernel/module.lds
> @@ -1,4 +1,4 @@
>  SECTIONS {
> -       .plt (NOLOAD) : { BYTE(0) }
> -       .init.plt (NOLOAD) : { BYTE(0) }
> +       .plt : { BYTE(0) }
> +       .init.plt : { BYTE(0) }
>  }
> --
> 2.15.0.531.g2ccb3012c9-goog
>

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 5/7] arm64: keep .altinstructions and .altinstr_replacement
  2017-11-30  1:58     ` Nicholas Piggin
@ 2017-11-30 17:00       ` Nick Desaulniers
  2017-12-01  0:36         ` Nicholas Piggin
  2017-11-30 17:48       ` Sami Tolvanen
  1 sibling, 1 reply; 28+ messages in thread
From: Nick Desaulniers @ 2017-11-30 17:00 UTC (permalink / raw)
  To: Nicholas Piggin
  Cc: Sami Tolvanen, Alex Matveev, Andi Kleen, Ard Biesheuvel,
	Greg Hackmann, Kees Cook, linux-arm-kernel,
	Linux Kbuild mailing list, LKML, Mark Rutland, Masahiro Yamada,
	Maxim Kuvyrkov, Michal Marek, Yury Norov, Matthias Kaehlcke

On Wed, Nov 29, 2017 at 5:58 PM, Nicholas Piggin <npiggin@gmail.com> wrote:
> (Comparing `readelf -S` before/after is a way to spot bugs.)

Do you have a script that can be used to diff 2 `readelf -S`, look for
missing references, and report an error? Might be easier to rerun that
every so often and see what's missing.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 1/7] kbuild: add ld-name macro and support for GNU gold
  2017-11-30  0:32   ` Nick Desaulniers
@ 2017-11-30 17:38     ` Sami Tolvanen
  0 siblings, 0 replies; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-30 17:38 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, Linux Kbuild mailing list, LKML,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Yury Norov, Matthias Kaehlcke, Nicholas Piggin

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

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 5/7] arm64: keep .altinstructions and .altinstr_replacement
  2017-11-30  1:58     ` Nicholas Piggin
  2017-11-30 17:00       ` Nick Desaulniers
@ 2017-11-30 17:48       ` Sami Tolvanen
  1 sibling, 0 replies; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-30 17:48 UTC (permalink / raw)
  To: Nicholas Piggin
  Cc: Nick Desaulniers, Alex Matveev, Andi Kleen, Ard Biesheuvel,
	Greg Hackmann, Kees Cook, linux-arm-kernel,
	Linux Kbuild mailing list, LKML, Mark Rutland, Masahiro Yamada,
	Maxim Kuvyrkov, Michal Marek, Yury Norov, Matthias Kaehlcke

On Thu, Nov 30, 2017 at 11:58:27AM +1000, Nicholas Piggin wrote:
> So yes please if it's not too much trouble, could you remove
> the "gold" name from the generic patch and put it at the front
> of the series with this arm64 patch.

Sure, I'll do this in v2.

> Possibly then you could also do a 3rd patch to allow arm64 to
> select it if it's working with gcc?

These patches only fix the issues I ran into with clang and gold
when testing on a single device.  I feel like more testing would
be needed before enabling this by default for arm64.

Sami

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 6/7] arm64: explicitly pass --no-fix-cortex-a53-843419 to GNU gold
  2017-11-30  0:30   ` Nick Desaulniers
@ 2017-11-30 17:50     ` Sami Tolvanen
  0 siblings, 0 replies; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-30 17:50 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, Linux Kbuild mailing list, LKML,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Yury Norov, Matthias Kaehlcke, Nicholas Piggin

On Wed, Nov 29, 2017 at 04:30:33PM -0800, Nick Desaulniers wrote:
> Rather than:
> 
> if CONFIG_ARM64_ERRATUM_843419 == y:
>   ...
> if CONFIG_ARM64_ERRATUM_843419 == '':
>   ...
> 
> could this be:
> 
> if CONFIG_ARM64_ERRATUM_843419 == y:
>   ...
> else
>   ...
> 
> ?

Sure. I'll clean this up in v2.

Sami

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v2 0/7] Add support for GNU gold
  2017-11-29 23:44 [PATCH 0/7] Add support for GNU gold Sami Tolvanen
                   ` (6 preceding siblings ...)
  2017-11-29 23:44 ` [PATCH 7/7] arm64: add a workaround for GNU gold with ARM64_MODULE_PLTS Sami Tolvanen
@ 2017-11-30 23:38 ` Sami Tolvanen
  2017-11-30 23:38   ` [PATCH v2 1/7] kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION Sami Tolvanen
                     ` (6 more replies)
  7 siblings, 7 replies; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-30 23:38 UTC (permalink / raw)
  To: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke, Nicholas Piggin
  Cc: Sami Tolvanen

These patches add macros for detecting the linker name and version,
and apply fixes and workarounds needed to link the arm64 kernel with
GNU gold.

Changes since v1:
  - moved LD_DEAD_CODE_DATA_ELIMINATION fixes to the beginning of the
    patch set and removed mentions of gold
  - renamed ld-if-name-version to __ld-ifversion for consistency
  - cleaned up the erratum changes in arch/arm64/Makefile

Sami Tolvanen (7):
  kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION
  arm64: keep .altinstructions and .altinstr_replacement
  kbuild: add ld-name macro
  kbuild: add __ld-ifversion and linker-specific macros
  arm64: fix -m for GNU gold
  arm64: explicitly pass --no-fix-cortex-a53-843419 to GNU gold
  arm64: add a workaround for GNU gold with ARM64_MODULE_PLTS

 arch/arm64/Makefile               | 17 +++++++++++++++++
 arch/arm64/kernel/module.lds      |  4 ++--
 arch/arm64/kernel/vmlinux.lds.S   |  4 ++--
 include/asm-generic/vmlinux.lds.h |  8 ++++----
 scripts/Kbuild.include            | 16 ++++++++++++++++
 5 files changed, 41 insertions(+), 8 deletions(-)

-- 
2.15.0.531.g2ccb3012c9-goog

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH v2 1/7] kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION
  2017-11-30 23:38 ` [PATCH v2 0/7] Add support for GNU gold Sami Tolvanen
@ 2017-11-30 23:38   ` Sami Tolvanen
  2017-11-30 23:39   ` [PATCH v2 2/7] arm64: keep .altinstructions and .altinstr_replacement Sami Tolvanen
                     ` (5 subsequent siblings)
  6 siblings, 0 replies; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-30 23:38 UTC (permalink / raw)
  To: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke, Nicholas Piggin
  Cc: Sami Tolvanen

Don't remove .head.text or .exitcall.exit when linking with --gc-sections,
and include .init.text.* in .init.text and .init.rodata.* in .init.rodata.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
---
 include/asm-generic/vmlinux.lds.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index ee8b707d9fa9..eb4199c12bd2 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -515,7 +515,7 @@
 		VMLINUX_SYMBOL(__softirqentry_text_end) = .;
 
 /* Section used for early init (in .S files) */
-#define HEAD_TEXT  *(.head.text)
+#define HEAD_TEXT  KEEP(*(.head.text))
 
 #define HEAD_TEXT_SECTION							\
 	.head.text : AT(ADDR(.head.text) - LOAD_OFFSET) {		\
@@ -560,7 +560,7 @@
 	MEM_DISCARD(init.data)						\
 	KERNEL_CTORS()							\
 	MCOUNT_REC()							\
-	*(.init.rodata)							\
+	*(.init.rodata .init.rodata.*)					\
 	FTRACE_EVENTS()							\
 	TRACE_SYSCALLS()						\
 	KPROBE_BLACKLIST()						\
@@ -579,7 +579,7 @@
 	EARLYCON_TABLE()
 
 #define INIT_TEXT							\
-	*(.init.text)							\
+	*(.init.text .init.text.*)					\
 	*(.text.startup)						\
 	MEM_DISCARD(init.text)
 
@@ -596,7 +596,7 @@
 	MEM_DISCARD(exit.text)
 
 #define EXIT_CALL							\
-	*(.exitcall.exit)
+	KEEP(*(.exitcall.exit))
 
 /*
  * bss (Block Started by Symbol) - uninitialized data
-- 
2.15.0.531.g2ccb3012c9-goog

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 2/7] arm64: keep .altinstructions and .altinstr_replacement
  2017-11-30 23:38 ` [PATCH v2 0/7] Add support for GNU gold Sami Tolvanen
  2017-11-30 23:38   ` [PATCH v2 1/7] kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION Sami Tolvanen
@ 2017-11-30 23:39   ` Sami Tolvanen
  2017-11-30 23:39   ` [PATCH v2 3/7] kbuild: add ld-name macro Sami Tolvanen
                     ` (4 subsequent siblings)
  6 siblings, 0 replies; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-30 23:39 UTC (permalink / raw)
  To: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke, Nicholas Piggin
  Cc: Sami Tolvanen

Make sure the linker doesn't remove .altinstructions or
.altinstr_replacement when CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is
enabled.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
---
 arch/arm64/kernel/vmlinux.lds.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index 7da3e5c366a0..15479995869c 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -138,11 +138,11 @@ SECTIONS
 	. = ALIGN(4);
 	.altinstructions : {
 		__alt_instructions = .;
-		*(.altinstructions)
+		KEEP(*(.altinstructions))
 		__alt_instructions_end = .;
 	}
 	.altinstr_replacement : {
-		*(.altinstr_replacement)
+		KEEP(*(.altinstr_replacement))
 	}
 
 	. = ALIGN(PAGE_SIZE);
-- 
2.15.0.531.g2ccb3012c9-goog

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 3/7] kbuild: add ld-name macro
  2017-11-30 23:38 ` [PATCH v2 0/7] Add support for GNU gold Sami Tolvanen
  2017-11-30 23:38   ` [PATCH v2 1/7] kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION Sami Tolvanen
  2017-11-30 23:39   ` [PATCH v2 2/7] arm64: keep .altinstructions and .altinstr_replacement Sami Tolvanen
@ 2017-11-30 23:39   ` Sami Tolvanen
  2017-11-30 23:39   ` [PATCH v2 4/7] kbuild: add __ld-ifversion and linker-specific macros Sami Tolvanen
                     ` (3 subsequent siblings)
  6 siblings, 0 replies; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-30 23:39 UTC (permalink / raw)
  To: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke, Nicholas Piggin
  Cc: Sami Tolvanen

GNU gold may require different flags than GNU ld. Add a macro for
detecting the linker.

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

diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index eb2cf2780f6e..899863e4cd05 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -273,6 +273,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)
-- 
2.15.0.531.g2ccb3012c9-goog

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 4/7] kbuild: add __ld-ifversion and linker-specific macros
  2017-11-30 23:38 ` [PATCH v2 0/7] Add support for GNU gold Sami Tolvanen
                     ` (2 preceding siblings ...)
  2017-11-30 23:39   ` [PATCH v2 3/7] kbuild: add ld-name macro Sami Tolvanen
@ 2017-11-30 23:39   ` Sami Tolvanen
  2017-11-30 23:39   ` [PATCH v2 5/7] arm64: fix -m for GNU gold Sami Tolvanen
                     ` (2 subsequent siblings)
  6 siblings, 0 replies; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-30 23:39 UTC (permalink / raw)
  To: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke, Nicholas Piggin
  Cc: Sami Tolvanen

Add macros for testing both linker name and version.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
---
 scripts/Kbuild.include | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 899863e4cd05..2991b463b4ce 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -285,6 +285,18 @@ ld-version = $(call shell-cached,$(LD) --version | $(srctree)/scripts/ld-version
 # Usage:  $(call ld-ifversion, -ge, 22252, y)
 ld-ifversion = $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo $(4))
 
+# __ld-ifversion
+# Usage:  $(call __ld-ifversion, gold, -ge, 112000000, y)
+__ld-ifversion = $(shell [ $(ld-name) == $(1) ] && [ $(ld-version) $(2) $(3) ] && echo $(4) || echo $(5))
+
+# bfd-ifversion
+# Usage:  $(call bfd-ifversion, -ge, 227000000, y)
+bfd-ifversion = $(call __ld-ifversion, bfd, $(1), $(2), $(3), $(4))
+
+# gold-ifversion
+# Usage:  $(call gold-ifversion, -ge, 112000000, y)
+gold-ifversion = $(call __ld-ifversion, gold, $(1), $(2), $(3), $(4))
+
 ######
 
 ###
-- 
2.15.0.531.g2ccb3012c9-goog

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 5/7] arm64: fix -m for GNU gold
  2017-11-30 23:38 ` [PATCH v2 0/7] Add support for GNU gold Sami Tolvanen
                     ` (3 preceding siblings ...)
  2017-11-30 23:39   ` [PATCH v2 4/7] kbuild: add __ld-ifversion and linker-specific macros Sami Tolvanen
@ 2017-11-30 23:39   ` Sami Tolvanen
  2017-11-30 23:39   ` [PATCH v2 6/7] arm64: explicitly pass --no-fix-cortex-a53-843419 to " Sami Tolvanen
  2017-11-30 23:39   ` [PATCH v2 7/7] arm64: add a workaround for GNU gold with ARM64_MODULE_PLTS Sami Tolvanen
  6 siblings, 0 replies; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-30 23:39 UTC (permalink / raw)
  To: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke, Nicholas Piggin
  Cc: Sami Tolvanen

GNU gold supports different emulations than bfd. Use aarch64_elf64_*_vec
instead of aarch64linux.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Acked-by: Yury Norov <ynorov@caviumnetworks.com>
---
 arch/arm64/Makefile | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index b35788c909f1..82a0df6e865e 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -64,14 +64,22 @@ KBUILD_CPPFLAGS	+= -mbig-endian
 CHECKFLAGS	+= -D__AARCH64EB__
 AS		+= -EB
 LD		+= -EB
+ifeq ($(ld-name),gold)
+LDFLAGS		+= -maarch64_elf64_be_vec
+else
 LDFLAGS		+= -maarch64linuxb
+endif
 UTS_MACHINE	:= aarch64_be
 else
 KBUILD_CPPFLAGS	+= -mlittle-endian
 CHECKFLAGS	+= -D__AARCH64EL__
 AS		+= -EL
 LD		+= -EL
+ifeq ($(ld-name),gold)
+LDFLAGS		+= -maarch64_elf64_le_vec
+else
 LDFLAGS		+= -maarch64linux
+endif
 UTS_MACHINE	:= aarch64
 endif
 
-- 
2.15.0.531.g2ccb3012c9-goog

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 6/7] arm64: explicitly pass --no-fix-cortex-a53-843419 to GNU gold
  2017-11-30 23:38 ` [PATCH v2 0/7] Add support for GNU gold Sami Tolvanen
                     ` (4 preceding siblings ...)
  2017-11-30 23:39   ` [PATCH v2 5/7] arm64: fix -m for GNU gold Sami Tolvanen
@ 2017-11-30 23:39   ` Sami Tolvanen
  2017-12-01  0:13     ` Nick Desaulniers
  2017-11-30 23:39   ` [PATCH v2 7/7] arm64: add a workaround for GNU gold with ARM64_MODULE_PLTS Sami Tolvanen
  6 siblings, 1 reply; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-30 23:39 UTC (permalink / raw)
  To: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke, Nicholas Piggin
  Cc: Sami Tolvanen

Some versions of GNU gold are known to produce broken code with
--fix-cortex-a53-843419 as explained in this bug:

  https://sourceware.org/bugzilla/show_bug.cgi?id=21491

If ARM64_ERRATUM_843419 is disabled and we're using GNU gold, pass
--no-fix-cortex-a53-843419 to the linker to ensure the erratum
fix is not used even if the linker is configured to enable it by
default.

This change also adds a warning if the erratum fix is enabled and
gold version <1.14 is used.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
---
 arch/arm64/Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 82a0df6e865e..68eed687e468 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -26,8 +26,17 @@ ifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
   ifeq ($(call ld-option, --fix-cortex-a53-843419),)
 $(warning ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum)
   else
+    ifeq ($(call gold-ifversion, -lt, 114000000, y), y)
+$(warning This version of GNU gold may generate incorrect code with --fix-cortex-a53-843419;\
+	see https://sourceware.org/bugzilla/show_bug.cgi?id=21491)
+    endif
 LDFLAGS_vmlinux	+= --fix-cortex-a53-843419
   endif
+else
+  ifeq ($(ld-name),gold)
+# Pass --no-fix-cortex-a53-843419 to ensure the erratum fix is disabled
+LDFLAGS	+= --no-fix-cortex-a53-843419
+  endif
 endif
 
 KBUILD_DEFCONFIG := defconfig
-- 
2.15.0.531.g2ccb3012c9-goog

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH v2 7/7] arm64: add a workaround for GNU gold with ARM64_MODULE_PLTS
  2017-11-30 23:38 ` [PATCH v2 0/7] Add support for GNU gold Sami Tolvanen
                     ` (5 preceding siblings ...)
  2017-11-30 23:39   ` [PATCH v2 6/7] arm64: explicitly pass --no-fix-cortex-a53-843419 to " Sami Tolvanen
@ 2017-11-30 23:39   ` Sami Tolvanen
  6 siblings, 0 replies; 28+ messages in thread
From: Sami Tolvanen @ 2017-11-30 23:39 UTC (permalink / raw)
  To: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, linux-kbuild, linux-kernel,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Nick Desaulniers, Yury Norov, Matthias Kaehlcke, Nicholas Piggin
  Cc: Sami Tolvanen

All current versions of GNU gold crash when linking kernel modules
with ARM64_MODULE_PLTS due to a known bug:

  https://sourceware.org/bugzilla/show_bug.cgi?id=14592

To work around the problem, this change removes NOLOAD from .plt
and .init.plt.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/arm64/kernel/module.lds | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/module.lds b/arch/arm64/kernel/module.lds
index f7c9781a9d48..eacb5c67f61e 100644
--- a/arch/arm64/kernel/module.lds
+++ b/arch/arm64/kernel/module.lds
@@ -1,4 +1,4 @@
 SECTIONS {
-	.plt (NOLOAD) : { BYTE(0) }
-	.init.plt (NOLOAD) : { BYTE(0) }
+	.plt : { BYTE(0) }
+	.init.plt : { BYTE(0) }
 }
-- 
2.15.0.531.g2ccb3012c9-goog

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH v2 6/7] arm64: explicitly pass --no-fix-cortex-a53-843419 to GNU gold
  2017-11-30 23:39   ` [PATCH v2 6/7] arm64: explicitly pass --no-fix-cortex-a53-843419 to " Sami Tolvanen
@ 2017-12-01  0:13     ` Nick Desaulniers
  0 siblings, 0 replies; 28+ messages in thread
From: Nick Desaulniers @ 2017-12-01  0:13 UTC (permalink / raw)
  To: Sami Tolvanen
  Cc: Alex Matveev, Andi Kleen, Ard Biesheuvel, Greg Hackmann,
	Kees Cook, linux-arm-kernel, Linux Kbuild mailing list, LKML,
	Mark Rutland, Masahiro Yamada, Maxim Kuvyrkov, Michal Marek,
	Yury Norov, Matthias Kaehlcke, Nicholas Piggin

Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 5/7] arm64: keep .altinstructions and .altinstr_replacement
  2017-11-30 17:00       ` Nick Desaulniers
@ 2017-12-01  0:36         ` Nicholas Piggin
  0 siblings, 0 replies; 28+ messages in thread
From: Nicholas Piggin @ 2017-12-01  0:36 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Sami Tolvanen, Alex Matveev, Andi Kleen, Ard Biesheuvel,
	Greg Hackmann, Kees Cook, linux-arm-kernel,
	Linux Kbuild mailing list, LKML, Mark Rutland, Masahiro Yamada,
	Maxim Kuvyrkov, Michal Marek, Yury Norov, Matthias Kaehlcke

On Thu, 30 Nov 2017 09:00:35 -0800
Nick Desaulniers <ndesaulniers@google.com> wrote:

> On Wed, Nov 29, 2017 at 5:58 PM, Nicholas Piggin <npiggin@gmail.com> wrote:
> > (Comparing `readelf -S` before/after is a way to spot bugs.)  
> 
> Do you have a script that can be used to diff 2 `readelf -S`, look for
> missing references, and report an error? Might be easier to rerun that
> every so often and see what's missing.

I don't, I was just doing it by hand.

Thanks,
Nick

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2017-12-01  0:36 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-29 23:44 [PATCH 0/7] Add support for GNU gold Sami Tolvanen
2017-11-29 23:44 ` [PATCH 1/7] kbuild: add ld-name macro and " Sami Tolvanen
2017-11-30  0:32   ` Nick Desaulniers
2017-11-30 17:38     ` Sami Tolvanen
2017-11-29 23:44 ` [PATCH 2/7] kbuild: add ld-if-name-version and linker-specific macros Sami Tolvanen
2017-11-29 23:44 ` [PATCH 3/7] kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION with GNU gold Sami Tolvanen
2017-11-30  2:10   ` Nicholas Piggin
2017-11-29 23:44 ` [PATCH 4/7] arm64: fix -m for " Sami Tolvanen
2017-11-29 23:44 ` [PATCH 5/7] arm64: keep .altinstructions and .altinstr_replacement Sami Tolvanen
2017-11-29 23:57   ` Nick Desaulniers
2017-11-30  1:58     ` Nicholas Piggin
2017-11-30 17:00       ` Nick Desaulniers
2017-12-01  0:36         ` Nicholas Piggin
2017-11-30 17:48       ` Sami Tolvanen
2017-11-29 23:44 ` [PATCH 6/7] arm64: explicitly pass --no-fix-cortex-a53-843419 to GNU gold Sami Tolvanen
2017-11-30  0:30   ` Nick Desaulniers
2017-11-30 17:50     ` Sami Tolvanen
2017-11-29 23:44 ` [PATCH 7/7] arm64: add a workaround for GNU gold with ARM64_MODULE_PLTS Sami Tolvanen
2017-11-30  9:31   ` Ard Biesheuvel
2017-11-30 23:38 ` [PATCH v2 0/7] Add support for GNU gold Sami Tolvanen
2017-11-30 23:38   ` [PATCH v2 1/7] kbuild: fix LD_DEAD_CODE_DATA_ELIMINATION Sami Tolvanen
2017-11-30 23:39   ` [PATCH v2 2/7] arm64: keep .altinstructions and .altinstr_replacement Sami Tolvanen
2017-11-30 23:39   ` [PATCH v2 3/7] kbuild: add ld-name macro Sami Tolvanen
2017-11-30 23:39   ` [PATCH v2 4/7] kbuild: add __ld-ifversion and linker-specific macros Sami Tolvanen
2017-11-30 23:39   ` [PATCH v2 5/7] arm64: fix -m for GNU gold Sami Tolvanen
2017-11-30 23:39   ` [PATCH v2 6/7] arm64: explicitly pass --no-fix-cortex-a53-843419 to " Sami Tolvanen
2017-12-01  0:13     ` Nick Desaulniers
2017-11-30 23:39   ` [PATCH v2 7/7] arm64: add a workaround for GNU gold with ARM64_MODULE_PLTS Sami Tolvanen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).