linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] objtool: Fix seg fault with gold linker
@ 2018-01-15 14:17 Josh Poimboeuf
  2018-01-15 14:17 ` [PATCH 2/2] objtool: Improve error message for bad file argument Josh Poimboeuf
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Josh Poimboeuf @ 2018-01-15 14:17 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: x86, linux-kernel, Markus

Objtool seg faults when the gold linker is used with
CONFIG_MODVERSIONS=y and CONFIG_UNWINDER_ORC=y.

With CONFIG_MODVERSIONS=y, the .o file gets passed to the linker before
being passed to objtool.  The gold linker seems to strip unused ELF
symbols by default, which confuses objtool and causes the seg fault when
it's trying to generate ORC metadata.

Objtool should really be running immediately after GCC anyway, without a
linker call in between.  Change the makefile ordering so that objtool is
called before the linker.

Reported-and-tested-by: Markus <M4rkusXXL@web.de>
Fixes: ee9f8fce9964 ("x86/unwind: Add the ORC unwinder")
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 scripts/Makefile.build | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index cb8997ed0149..bc277d7c081d 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -265,12 +265,18 @@ else
 objtool_args += $(call cc-ifversion, -lt, 0405, --no-unreachable)
 endif
 
+ifdef CONFIG_MODVERSIONS
+objtool_o = $(@D)/.tmp_$(@F)
+else
+objtool_o = $(@)
+endif
+
 # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
 cmd_objtool = $(if $(patsubst y%,, \
 	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
-	$(__objtool_obj) $(objtool_args) "$(@)";)
+	$(__objtool_obj) $(objtool_args) "$(objtool_o)";)
 objtool_obj = $(if $(patsubst y%,, \
 	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
 	$(__objtool_obj))
@@ -286,16 +292,16 @@ objtool_dep = $(objtool_obj)					\
 define rule_cc_o_c
 	$(call echo-cmd,checksrc) $(cmd_checksrc)			  \
 	$(call cmd_and_fixdep,cc_o_c)					  \
+	$(call echo-cmd,objtool) $(cmd_objtool)				  \
 	$(cmd_modversions_c)						  \
 	$(cmd_checkdoc)							  \
-	$(call echo-cmd,objtool) $(cmd_objtool)				  \
 	$(call echo-cmd,record_mcount) $(cmd_record_mcount)
 endef
 
 define rule_as_o_S
 	$(call cmd_and_fixdep,as_o_S)					  \
-	$(cmd_modversions_S)						  \
-	$(call echo-cmd,objtool) $(cmd_objtool)
+	$(call echo-cmd,objtool) $(cmd_objtool)				  \
+	$(cmd_modversions_S)
 endef
 
 # List module undefined symbols (or empty line if not enabled)
-- 
2.14.3

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

* [PATCH 2/2] objtool: Improve error message for bad file argument
  2018-01-15 14:17 [PATCH 1/2] objtool: Fix seg fault with gold linker Josh Poimboeuf
@ 2018-01-15 14:17 ` Josh Poimboeuf
  2018-01-16  3:37   ` [tip:x86/pti] " tip-bot for Josh Poimboeuf
  2018-01-16  0:21 ` [PATCH 1/2] objtool: Fix seg fault with gold linker Ingo Molnar
  2018-01-16  3:37 ` [tip:x86/pti] " tip-bot for Josh Poimboeuf
  2 siblings, 1 reply; 7+ messages in thread
From: Josh Poimboeuf @ 2018-01-15 14:17 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: x86, linux-kernel, Markus

If a nonexistent file is supplied to objtool, it complains with a
non-helpful error:

  open: No such file or directory

Improve it to:

  objtool: Can't open 'foo': No such file or directory

Reported-by: Markus <M4rkusXXL@web.de>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/objtool/elf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 24460155c82c..c1c338661699 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include "elf.h"
 #include "warn.h"
@@ -358,7 +359,8 @@ struct elf *elf_open(const char *name, int flags)
 
 	elf->fd = open(name, flags);
 	if (elf->fd == -1) {
-		perror("open");
+		fprintf(stderr, "objtool: Can't open '%s': %s\n",
+			name, strerror(errno));
 		goto err;
 	}
 
-- 
2.14.3

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

* Re: [PATCH 1/2] objtool: Fix seg fault with gold linker
  2018-01-15 14:17 [PATCH 1/2] objtool: Fix seg fault with gold linker Josh Poimboeuf
  2018-01-15 14:17 ` [PATCH 2/2] objtool: Improve error message for bad file argument Josh Poimboeuf
@ 2018-01-16  0:21 ` Ingo Molnar
  2018-01-16  4:20   ` Josh Poimboeuf
  2018-01-16  3:37 ` [tip:x86/pti] " tip-bot for Josh Poimboeuf
  2 siblings, 1 reply; 7+ messages in thread
From: Ingo Molnar @ 2018-01-16  0:21 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: x86, linux-kernel, Markus, Thomas Gleixner, Peter Zijlstra,
	Linus Torvalds


* Josh Poimboeuf <jpoimboe@redhat.com> wrote:

> Objtool seg faults when the gold linker is used with
> CONFIG_MODVERSIONS=y and CONFIG_UNWINDER_ORC=y.
> 
> With CONFIG_MODVERSIONS=y, the .o file gets passed to the linker before
> being passed to objtool.  The gold linker seems to strip unused ELF
> symbols by default, which confuses objtool and causes the seg fault when
> it's trying to generate ORC metadata.

BTW., if it's still unfixed, could we fix that segfault as well, and turn it into 
a more useful failure message?

Thanks,

	Ingo

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

* [tip:x86/pti] objtool: Fix seg fault with gold linker
  2018-01-15 14:17 [PATCH 1/2] objtool: Fix seg fault with gold linker Josh Poimboeuf
  2018-01-15 14:17 ` [PATCH 2/2] objtool: Improve error message for bad file argument Josh Poimboeuf
  2018-01-16  0:21 ` [PATCH 1/2] objtool: Fix seg fault with gold linker Ingo Molnar
@ 2018-01-16  3:37 ` tip-bot for Josh Poimboeuf
  2 siblings, 0 replies; 7+ messages in thread
From: tip-bot for Josh Poimboeuf @ 2018-01-16  3:37 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: jpoimboe, hpa, mingo, peterz, linux-kernel, torvalds, tglx, M4rkusXXL

Commit-ID:  2a0098d70640dda192a79966c14d449e7a34d675
Gitweb:     https://git.kernel.org/tip/2a0098d70640dda192a79966c14d449e7a34d675
Author:     Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Mon, 15 Jan 2018 08:17:07 -0600
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 16 Jan 2018 01:27:27 +0100

objtool: Fix seg fault with gold linker

Objtool segfaults when the gold linker is used with
CONFIG_MODVERSIONS=y and CONFIG_UNWINDER_ORC=y.

With CONFIG_MODVERSIONS=y, the .o file gets passed to the linker before
being passed to objtool.  The gold linker seems to strip unused ELF
symbols by default, which confuses objtool and causes the seg fault when
it's trying to generate ORC metadata.

Objtool should really be running immediately after GCC anyway, without a
linker call in between.  Change the makefile ordering so that objtool is
called before the linker.

Reported-and-tested-by: Markus <M4rkusXXL@web.de>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: ee9f8fce9964 ("x86/unwind: Add the ORC unwinder")
Link: http://lkml.kernel.org/r/355f04da33581f4a3bf82e5b512973624a1e23a2.1516025651.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 scripts/Makefile.build | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index e63af4e..6bed45d 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -270,12 +270,18 @@ else
 objtool_args += $(call cc-ifversion, -lt, 0405, --no-unreachable)
 endif
 
+ifdef CONFIG_MODVERSIONS
+objtool_o = $(@D)/.tmp_$(@F)
+else
+objtool_o = $(@)
+endif
+
 # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
 cmd_objtool = $(if $(patsubst y%,, \
 	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
-	$(__objtool_obj) $(objtool_args) "$(@)";)
+	$(__objtool_obj) $(objtool_args) "$(objtool_o)";)
 objtool_obj = $(if $(patsubst y%,, \
 	$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
 	$(__objtool_obj))
@@ -291,15 +297,15 @@ objtool_dep = $(objtool_obj)					\
 define rule_cc_o_c
 	$(call echo-cmd,checksrc) $(cmd_checksrc)			  \
 	$(call cmd_and_fixdep,cc_o_c)					  \
-	$(cmd_modversions_c)						  \
 	$(call echo-cmd,objtool) $(cmd_objtool)				  \
+	$(cmd_modversions_c)						  \
 	$(call echo-cmd,record_mcount) $(cmd_record_mcount)
 endef
 
 define rule_as_o_S
 	$(call cmd_and_fixdep,as_o_S)					  \
-	$(cmd_modversions_S)						  \
-	$(call echo-cmd,objtool) $(cmd_objtool)
+	$(call echo-cmd,objtool) $(cmd_objtool)				  \
+	$(cmd_modversions_S)
 endef
 
 # List module undefined symbols (or empty line if not enabled)

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

* [tip:x86/pti] objtool: Improve error message for bad file argument
  2018-01-15 14:17 ` [PATCH 2/2] objtool: Improve error message for bad file argument Josh Poimboeuf
@ 2018-01-16  3:37   ` tip-bot for Josh Poimboeuf
  0 siblings, 0 replies; 7+ messages in thread
From: tip-bot for Josh Poimboeuf @ 2018-01-16  3:37 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, hpa, jpoimboe, torvalds, mingo, M4rkusXXL, linux-kernel, tglx

Commit-ID:  385d11b152c4eb638eeb769edcb3249533bb9a00
Gitweb:     https://git.kernel.org/tip/385d11b152c4eb638eeb769edcb3249533bb9a00
Author:     Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Mon, 15 Jan 2018 08:17:08 -0600
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 16 Jan 2018 01:27:27 +0100

objtool: Improve error message for bad file argument

If a nonexistent file is supplied to objtool, it complains with a
non-helpful error:

  open: No such file or directory

Improve it to:

  objtool: Can't open 'foo': No such file or directory

Reported-by: Markus <M4rkusXXL@web.de>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/406a3d00a21225eee2819844048e17f68523ccf6.1516025651.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 tools/objtool/elf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 2446015..c1c3386 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include "elf.h"
 #include "warn.h"
@@ -358,7 +359,8 @@ struct elf *elf_open(const char *name, int flags)
 
 	elf->fd = open(name, flags);
 	if (elf->fd == -1) {
-		perror("open");
+		fprintf(stderr, "objtool: Can't open '%s': %s\n",
+			name, strerror(errno));
 		goto err;
 	}
 

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

* Re: [PATCH 1/2] objtool: Fix seg fault with gold linker
  2018-01-16  0:21 ` [PATCH 1/2] objtool: Fix seg fault with gold linker Ingo Molnar
@ 2018-01-16  4:20   ` Josh Poimboeuf
  2018-01-16  8:30     ` Ingo Molnar
  0 siblings, 1 reply; 7+ messages in thread
From: Josh Poimboeuf @ 2018-01-16  4:20 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: x86, linux-kernel, Markus, Thomas Gleixner, Peter Zijlstra,
	Linus Torvalds

On Tue, Jan 16, 2018 at 01:21:44AM +0100, Ingo Molnar wrote:
> 
> * Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> 
> > Objtool seg faults when the gold linker is used with
> > CONFIG_MODVERSIONS=y and CONFIG_UNWINDER_ORC=y.
> > 
> > With CONFIG_MODVERSIONS=y, the .o file gets passed to the linker before
> > being passed to objtool.  The gold linker seems to strip unused ELF
> > symbols by default, which confuses objtool and causes the seg fault when
> > it's trying to generate ORC metadata.
> 
> BTW., if it's still unfixed, could we fix that segfault as well, and turn it into 
> a more useful failure message?

Good point.  I'll fix up this seg fault, and the other one
found/introduced when adding retpoline support.

-- 
Josh

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

* Re: [PATCH 1/2] objtool: Fix seg fault with gold linker
  2018-01-16  4:20   ` Josh Poimboeuf
@ 2018-01-16  8:30     ` Ingo Molnar
  0 siblings, 0 replies; 7+ messages in thread
From: Ingo Molnar @ 2018-01-16  8:30 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: x86, linux-kernel, Markus, Thomas Gleixner, Peter Zijlstra,
	Linus Torvalds


* Josh Poimboeuf <jpoimboe@redhat.com> wrote:

> On Tue, Jan 16, 2018 at 01:21:44AM +0100, Ingo Molnar wrote:
> > 
> > * Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> > 
> > > Objtool seg faults when the gold linker is used with
> > > CONFIG_MODVERSIONS=y and CONFIG_UNWINDER_ORC=y.
> > > 
> > > With CONFIG_MODVERSIONS=y, the .o file gets passed to the linker before
> > > being passed to objtool.  The gold linker seems to strip unused ELF
> > > symbols by default, which confuses objtool and causes the seg fault when
> > > it's trying to generate ORC metadata.
> > 
> > BTW., if it's still unfixed, could we fix that segfault as well, and turn it into 
> > a more useful failure message?
> 
> Good point.  I'll fix up this seg fault, and the other one
> found/introduced when adding retpoline support.

Thanks!

	Ingo

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

end of thread, other threads:[~2018-01-16  8:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-15 14:17 [PATCH 1/2] objtool: Fix seg fault with gold linker Josh Poimboeuf
2018-01-15 14:17 ` [PATCH 2/2] objtool: Improve error message for bad file argument Josh Poimboeuf
2018-01-16  3:37   ` [tip:x86/pti] " tip-bot for Josh Poimboeuf
2018-01-16  0:21 ` [PATCH 1/2] objtool: Fix seg fault with gold linker Ingo Molnar
2018-01-16  4:20   ` Josh Poimboeuf
2018-01-16  8:30     ` Ingo Molnar
2018-01-16  3:37 ` [tip:x86/pti] " tip-bot for Josh Poimboeuf

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).