All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mikulas Patocka <mpatocka@redhat.com>
To: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Brian Gerst <brgerst@gmail.com>,
	Denys Vlasenko <dvlasenk@redhat.com>,
	"H. Peter Anvin" <hpa@zytor.com>, Jiri Slaby <jslaby@suse.cz>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	live-patching@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] objtool: fix build of 64-bit kernel with 32-bit userspace
Date: Mon, 6 Nov 2017 18:27:53 -0500 (EST)	[thread overview]
Message-ID: <alpine.LRH.2.02.1711061812460.18820@file01.intranet.prod.int.rdu2.redhat.com> (raw)

This patch fixes building of 64-bit kernel on 32-bit userspace (I tested 
it on RHEL-6-i686 and Debian-Sid-x32).

There are still some more bugs - when building 64-bit kernel on 32-bit
Debian 7 distribution, objtool corrupts object files so that the linker
doesn't recognize them (ld doesn't recognize the format of the file at all
and gold prints a lot of errors).

Another problem - when building 32-bit kernel, why do you force frame
pointers on and why did you hide CONFIG_GUESS_UNWINDER behind
CONFIG_EXPERT? Frame pointers increase code size and register pressure,
most users don't need precise stacktraces, so CONFIG_GUESS_UNWINDER should
be default for non-expert users just like it was before.

Is there some technical reason why do you want to avoid 
CONFIG_GUESS_UNWINDER?





From: Mikulas Patocka <mpatocka@redhat.com>
Subject: [PATCH] objtool: fix build of 64-bit kernel with 32-bit userspace

The new orc unwinder breaks building 64-bit kernel with 32-bit userspace.
Building the kernel with i386 or x32 userspace fails with this error:

  CC       /usr/src/git/linux-2.6/tools/objtool/orc_dump.o
orc_dump.c: In function 'orc_dump':
orc_dump.c:105:26: error: passing argument 2 of 'elf_getshdrnum' from incompatible pointer type [-Werror=incompatible-pointer-types]
  if (elf_getshdrnum(elf, &nr_sections)) {
                          ^
In file included from /usr/local/include/gelf.h:32:0,
                 from elf.h:22,
                 from warn.h:26,
                 from orc_dump.c:20:
/usr/local/include/libelf.h:304:12: note: expected 'size_t * {aka unsigned int *}' but argument is of type 'long unsigned int *'
 extern int elf_getshdrnum (Elf *__elf, size_t *__dst);
            ^~~~~~~~~~~~~~
orc_dump.c:190:17: error: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'Elf64_Sxword {aka long long int}' [-Werror=format=]
    printf("%s+%lx:", name, rela.r_addend);
               ~~^          ~~~~~~~~~~~~~
               %llx
cc1: all warnings being treated as errors

This patch fixes the build failure.

Another problem is that if the user specifies HOSTCC or HOSTLD variables,
they are ignored in the makefile tools/objtool/Makefile. This patch
changes the makefile so that it respects these variables.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
 tools/objtool/Makefile   |    5 +++--
 tools/objtool/orc_dump.c |    7 ++++---
 2 files changed, 7 insertions(+), 5 deletions(-)

Index: linux-2.6/tools/objtool/orc_dump.c
===================================================================
--- linux-2.6.orig/tools/objtool/orc_dump.c
+++ linux-2.6/tools/objtool/orc_dump.c
@@ -76,7 +76,8 @@ int orc_dump(const char *_objname)
 	int fd, nr_entries, i, *orc_ip = NULL, orc_size = 0;
 	struct orc_entry *orc = NULL;
 	char *name;
-	unsigned long nr_sections, orc_ip_addr = 0;
+	size_t nr_sections;
+	Elf64_Addr orc_ip_addr = 0;
 	size_t shstrtab_idx;
 	Elf *elf;
 	Elf_Scn *scn;
@@ -187,10 +188,10 @@ int orc_dump(const char *_objname)
 				return -1;
 			}
 
-			printf("%s+%lx:", name, rela.r_addend);
+			printf("%s+%llx:", name, (unsigned long long)rela.r_addend);
 
 		} else {
-			printf("%lx:", orc_ip_addr + (i * sizeof(int)) + orc_ip[i]);
+			printf("%llx:", (unsigned long long)(orc_ip_addr + (i * sizeof(int)) + orc_ip[i]));
 		}
 
 
Index: linux-2.6/tools/objtool/Makefile
===================================================================
--- linux-2.6.orig/tools/objtool/Makefile
+++ linux-2.6/tools/objtool/Makefile
@@ -7,8 +7,9 @@ ARCH := x86
 endif
 
 # always use the host compiler
-CC = gcc
-LD = ld
+CC = $(HOSTCC)
+HOSTLD ?= ld
+LD = $(HOSTLD)
 AR = ar
 
 ifeq ($(srctree),)

             reply	other threads:[~2017-11-06 23:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-06 23:27 Mikulas Patocka [this message]
2017-11-07 17:55 ` [PATCH] objtool: fix build of 64-bit kernel with 32-bit userspace Josh Poimboeuf
2017-11-07 21:25   ` Mikulas Patocka
2017-11-08  8:07     ` Peter Zijlstra
2017-11-27 17:32   ` Sven Joachim
2017-11-27 19:27     ` Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LRH.2.02.1711061812460.18820@file01.intranet.prod.int.rdu2.redhat.com \
    --to=mpatocka@redhat.com \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=dvlasenk@redhat.com \
    --cc=hpa@zytor.com \
    --cc=jpoimboe@redhat.com \
    --cc=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.