Re: [GIT PULL] objtool fixes

2018-11-30 Thread pr-tracker-bot
The pull request you sent on Fri, 30 Nov 2018 07:18:53 +0100:

> git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 
> core-urgent-for-linus

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/575d7d0d6f5c6feb896fae2e70578a1ab6d474b5

Thank you!

-- 
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/prtracker


Re: [GIT PULL] objtool fixes

2018-11-30 Thread pr-tracker-bot
The pull request you sent on Fri, 30 Nov 2018 07:18:53 +0100:

> git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 
> core-urgent-for-linus

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/575d7d0d6f5c6feb896fae2e70578a1ab6d474b5

Thank you!

-- 
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/prtracker


[GIT PULL] objtool fixes

2018-11-29 Thread Ingo Molnar
Linus,

Please pull the latest core-urgent-for-linus git tree from:

   git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 
core-urgent-for-linus

   # HEAD: 22566c1603030f0a036ad564634b064ad1a55db2 objtool: Fix segfault in 
.cold detection with -ffunction-sections

Two fixes for boundary conditions.

 Thanks,

Ingo

-->
Artem Savkov (2):
  objtool: Fix double-free in .cold detection error path
  objtool: Fix segfault in .cold detection with -ffunction-sections


 tools/objtool/elf.c | 19 +++
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 6dbb9fae0f9d..b8f3cca8e58b 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -31,6 +31,8 @@
 #include "elf.h"
 #include "warn.h"
 
+#define MAX_NAME_LEN 128
+
 struct section *find_section_by_name(struct elf *elf, const char *name)
 {
struct section *sec;
@@ -298,6 +300,8 @@ static int read_symbols(struct elf *elf)
/* Create parent/child links for any cold subfunctions */
list_for_each_entry(sec, >sections, list) {
list_for_each_entry(sym, >symbol_list, list) {
+   char pname[MAX_NAME_LEN + 1];
+   size_t pnamelen;
if (sym->type != STT_FUNC)
continue;
sym->pfunc = sym->cfunc = sym;
@@ -305,14 +309,21 @@ static int read_symbols(struct elf *elf)
if (!coldstr)
continue;
 
-   coldstr[0] = '\0';
-   pfunc = find_symbol_by_name(elf, sym->name);
-   coldstr[0] = '.';
+   pnamelen = coldstr - sym->name;
+   if (pnamelen > MAX_NAME_LEN) {
+   WARN("%s(): parent function name exceeds 
maximum length of %d characters",
+sym->name, MAX_NAME_LEN);
+   return -1;
+   }
+
+   strncpy(pname, sym->name, pnamelen);
+   pname[pnamelen] = '\0';
+   pfunc = find_symbol_by_name(elf, pname);
 
if (!pfunc) {
WARN("%s(): can't find parent function",
 sym->name);
-   goto err;
+   return -1;
}
 
sym->pfunc = pfunc;


[GIT PULL] objtool fixes

2018-11-29 Thread Ingo Molnar
Linus,

Please pull the latest core-urgent-for-linus git tree from:

   git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 
core-urgent-for-linus

   # HEAD: 22566c1603030f0a036ad564634b064ad1a55db2 objtool: Fix segfault in 
.cold detection with -ffunction-sections

Two fixes for boundary conditions.

 Thanks,

Ingo

-->
Artem Savkov (2):
  objtool: Fix double-free in .cold detection error path
  objtool: Fix segfault in .cold detection with -ffunction-sections


 tools/objtool/elf.c | 19 +++
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 6dbb9fae0f9d..b8f3cca8e58b 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -31,6 +31,8 @@
 #include "elf.h"
 #include "warn.h"
 
+#define MAX_NAME_LEN 128
+
 struct section *find_section_by_name(struct elf *elf, const char *name)
 {
struct section *sec;
@@ -298,6 +300,8 @@ static int read_symbols(struct elf *elf)
/* Create parent/child links for any cold subfunctions */
list_for_each_entry(sec, >sections, list) {
list_for_each_entry(sym, >symbol_list, list) {
+   char pname[MAX_NAME_LEN + 1];
+   size_t pnamelen;
if (sym->type != STT_FUNC)
continue;
sym->pfunc = sym->cfunc = sym;
@@ -305,14 +309,21 @@ static int read_symbols(struct elf *elf)
if (!coldstr)
continue;
 
-   coldstr[0] = '\0';
-   pfunc = find_symbol_by_name(elf, sym->name);
-   coldstr[0] = '.';
+   pnamelen = coldstr - sym->name;
+   if (pnamelen > MAX_NAME_LEN) {
+   WARN("%s(): parent function name exceeds 
maximum length of %d characters",
+sym->name, MAX_NAME_LEN);
+   return -1;
+   }
+
+   strncpy(pname, sym->name, pnamelen);
+   pname[pnamelen] = '\0';
+   pfunc = find_symbol_by_name(elf, pname);
 
if (!pfunc) {
WARN("%s(): can't find parent function",
 sym->name);
-   goto err;
+   return -1;
}
 
sym->pfunc = pfunc;


[GIT PULL] objtool fixes

2017-11-26 Thread Ingo Molnar
Linus,

Please pull the latest core-urgent-for-linus git tree from:

   git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 
core-urgent-for-linus

   # HEAD: a356d2ae50790f49858ebed35da9e206336fafee tools/headers: Sync objtool 
UAPI header

A handful of objtool fixes, most of them related to making the UAPI 
header-syncing 
warnings easier to read and easier to act upon.

 Thanks,

Ingo

-->
Ingo Molnar (1):
  tools/headers: Sync objtool UAPI header

Josh Poimboeuf (5):
  objtool: Add a comment for the unreachable annotation macros
  objtool: Make unreachable annotation inline asms explicitly volatile
  objtool: Move synced files to their original relative locations
  objtool: Move kernel headers/code sync check to a script
  objtool: Fix cross-build


 include/linux/compiler.h   | 21 ++--
 tools/objtool/.gitignore   |  2 +-
 tools/objtool/Makefile | 22 
 tools/objtool/arch/x86/Build   | 10 
 tools/objtool/arch/x86/decode.c|  6 ++---
 .../objtool/arch/x86/{insn => include/asm}/inat.h  | 12 -
 .../arch/x86/{insn => include/asm}/inat_types.h|  0
 .../objtool/arch/x86/{insn => include/asm}/insn.h  |  2 +-
 .../objtool/{ => arch/x86/include/asm}/orc_types.h |  0
 tools/objtool/arch/x86/{insn => lib}/inat.c|  2 +-
 tools/objtool/arch/x86/{insn => lib}/insn.c|  4 +--
 .../arch/x86/{insn => lib}/x86-opcode-map.txt  |  0
 .../arch/x86/{insn => tools}/gen-insn-attr-x86.awk |  0
 tools/objtool/orc.h|  2 +-
 tools/objtool/sync-check.sh| 29 ++
 15 files changed, 72 insertions(+), 40 deletions(-)
 rename tools/objtool/arch/x86/{insn => include/asm}/inat.h (95%)
 rename tools/objtool/arch/x86/{insn => include/asm}/inat_types.h (100%)
 rename tools/objtool/arch/x86/{insn => include/asm}/insn.h (99%)
 rename tools/objtool/{ => arch/x86/include/asm}/orc_types.h (100%)
 rename tools/objtool/arch/x86/{insn => lib}/inat.c (99%)
 rename tools/objtool/arch/x86/{insn => lib}/insn.c (99%)
 rename tools/objtool/arch/x86/{insn => lib}/x86-opcode-map.txt (100%)
 rename tools/objtool/arch/x86/{insn => tools}/gen-insn-attr-x86.awk (100%)
 create mode 100755 tools/objtool/sync-check.sh

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 3672353a0acd..188ed9f65517 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -88,17 +88,22 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int 
val,
 
 /* Unreachable code */
 #ifdef CONFIG_STACK_VALIDATION
+/*
+ * These macros help objtool understand GCC code flow for unreachable code.
+ * The __COUNTER__ based labels are a hack to make each instance of the macros
+ * unique, to convince GCC not to merge duplicate inline asm statements.
+ */
 #define annotate_reachable() ({
\
-   asm("%c0:\n\t"  \
-   ".pushsection .discard.reachable\n\t"   \
-   ".long %c0b - .\n\t"\
-   ".popsection\n\t" : : "i" (__COUNTER__));   \
+   asm volatile("%c0:\n\t" \
+".pushsection .discard.reachable\n\t"  \
+".long %c0b - .\n\t"   \
+".popsection\n\t" : : "i" (__COUNTER__));  \
 })
 #define annotate_unreachable() ({  \
-   asm("%c0:\n\t"  \
-   ".pushsection .discard.unreachable\n\t" \
-   ".long %c0b - .\n\t"\
-   ".popsection\n\t" : : "i" (__COUNTER__));   \
+   asm volatile("%c0:\n\t" \
+".pushsection .discard.unreachable\n\t"\
+".long %c0b - .\n\t"   \
+".popsection\n\t" : : "i" (__COUNTER__));  \
 })
 #define ASM_UNREACHABLE
\
"999:\n\t"  \
diff --git a/tools/objtool/.gitignore b/tools/objtool/.gitignore
index d3102c865a95..914cff12899b 100644
--- a/tools/objtool/.gitignore
+++ b/tools/objtool/.gitignore
@@ -1,3 +1,3 @@
-arch/x86/insn/inat-tables.c
+arch/x86/lib/inat-tables.c
 objtool
 fixdep
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index 424b1965d06f..0f94af3ccaaa 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -25,7 +25,9 @@ OBJTOOL_IN := $(OBJTOOL)-in.o
 
 all: $(OBJTOOL)
 
-INCLUDES := -I$(srctree)/tools/include 

[GIT PULL] objtool fixes

2017-11-26 Thread Ingo Molnar
Linus,

Please pull the latest core-urgent-for-linus git tree from:

   git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 
core-urgent-for-linus

   # HEAD: a356d2ae50790f49858ebed35da9e206336fafee tools/headers: Sync objtool 
UAPI header

A handful of objtool fixes, most of them related to making the UAPI 
header-syncing 
warnings easier to read and easier to act upon.

 Thanks,

Ingo

-->
Ingo Molnar (1):
  tools/headers: Sync objtool UAPI header

Josh Poimboeuf (5):
  objtool: Add a comment for the unreachable annotation macros
  objtool: Make unreachable annotation inline asms explicitly volatile
  objtool: Move synced files to their original relative locations
  objtool: Move kernel headers/code sync check to a script
  objtool: Fix cross-build


 include/linux/compiler.h   | 21 ++--
 tools/objtool/.gitignore   |  2 +-
 tools/objtool/Makefile | 22 
 tools/objtool/arch/x86/Build   | 10 
 tools/objtool/arch/x86/decode.c|  6 ++---
 .../objtool/arch/x86/{insn => include/asm}/inat.h  | 12 -
 .../arch/x86/{insn => include/asm}/inat_types.h|  0
 .../objtool/arch/x86/{insn => include/asm}/insn.h  |  2 +-
 .../objtool/{ => arch/x86/include/asm}/orc_types.h |  0
 tools/objtool/arch/x86/{insn => lib}/inat.c|  2 +-
 tools/objtool/arch/x86/{insn => lib}/insn.c|  4 +--
 .../arch/x86/{insn => lib}/x86-opcode-map.txt  |  0
 .../arch/x86/{insn => tools}/gen-insn-attr-x86.awk |  0
 tools/objtool/orc.h|  2 +-
 tools/objtool/sync-check.sh| 29 ++
 15 files changed, 72 insertions(+), 40 deletions(-)
 rename tools/objtool/arch/x86/{insn => include/asm}/inat.h (95%)
 rename tools/objtool/arch/x86/{insn => include/asm}/inat_types.h (100%)
 rename tools/objtool/arch/x86/{insn => include/asm}/insn.h (99%)
 rename tools/objtool/{ => arch/x86/include/asm}/orc_types.h (100%)
 rename tools/objtool/arch/x86/{insn => lib}/inat.c (99%)
 rename tools/objtool/arch/x86/{insn => lib}/insn.c (99%)
 rename tools/objtool/arch/x86/{insn => lib}/x86-opcode-map.txt (100%)
 rename tools/objtool/arch/x86/{insn => tools}/gen-insn-attr-x86.awk (100%)
 create mode 100755 tools/objtool/sync-check.sh

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 3672353a0acd..188ed9f65517 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -88,17 +88,22 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int 
val,
 
 /* Unreachable code */
 #ifdef CONFIG_STACK_VALIDATION
+/*
+ * These macros help objtool understand GCC code flow for unreachable code.
+ * The __COUNTER__ based labels are a hack to make each instance of the macros
+ * unique, to convince GCC not to merge duplicate inline asm statements.
+ */
 #define annotate_reachable() ({
\
-   asm("%c0:\n\t"  \
-   ".pushsection .discard.reachable\n\t"   \
-   ".long %c0b - .\n\t"\
-   ".popsection\n\t" : : "i" (__COUNTER__));   \
+   asm volatile("%c0:\n\t" \
+".pushsection .discard.reachable\n\t"  \
+".long %c0b - .\n\t"   \
+".popsection\n\t" : : "i" (__COUNTER__));  \
 })
 #define annotate_unreachable() ({  \
-   asm("%c0:\n\t"  \
-   ".pushsection .discard.unreachable\n\t" \
-   ".long %c0b - .\n\t"\
-   ".popsection\n\t" : : "i" (__COUNTER__));   \
+   asm volatile("%c0:\n\t" \
+".pushsection .discard.unreachable\n\t"\
+".long %c0b - .\n\t"   \
+".popsection\n\t" : : "i" (__COUNTER__));  \
 })
 #define ASM_UNREACHABLE
\
"999:\n\t"  \
diff --git a/tools/objtool/.gitignore b/tools/objtool/.gitignore
index d3102c865a95..914cff12899b 100644
--- a/tools/objtool/.gitignore
+++ b/tools/objtool/.gitignore
@@ -1,3 +1,3 @@
-arch/x86/insn/inat-tables.c
+arch/x86/lib/inat-tables.c
 objtool
 fixdep
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index 424b1965d06f..0f94af3ccaaa 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -25,7 +25,9 @@ OBJTOOL_IN := $(OBJTOOL)-in.o
 
 all: $(OBJTOOL)
 
-INCLUDES := -I$(srctree)/tools/include 

[GIT PULL] objtool fixes

2017-03-01 Thread Ingo Molnar
Linus,

Please pull the latest core-urgent-for-linus git tree from:

   git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 
core-urgent-for-linus

   # HEAD: e390f9a9689a42f477a6073e2e7df530a4c1b740 objtool, modules: Discard 
objtool annotation sections for modules

These two fixes related to the module loading regression introduced by the 
recent 
objtool changes.

 Thanks,

Ingo

-->
Josh Poimboeuf (2):
  objtool, compiler.h: Fix __unreachable section relocation size
  objtool, modules: Discard objtool annotation sections for modules


 arch/x86/kernel/vmlinux.lds.S | 2 --
 include/linux/compiler-gcc.h  | 4 ++--
 include/linux/frame.h | 2 +-
 scripts/mod/modpost.c | 1 +
 scripts/module-common.lds | 5 -
 tools/objtool/builtin-check.c | 6 +++---
 6 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index ad0118fbce90..c74ae9ce8dc4 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -345,8 +345,6 @@ SECTIONS
DISCARDS
/DISCARD/ : {
*(.eh_frame)
-   *(__func_stack_frame_non_standard)
-   *(__unreachable)
}
 }
 
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 76e28c229805..0efef9cf014f 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -200,8 +200,8 @@
 #ifdef CONFIG_STACK_VALIDATION
 #define annotate_unreachable() ({  \
asm("%c0:\t\n"  \
-   ".pushsection __unreachable, \"a\"\t\n" \
-   ".long %c0b\t\n"\
+   ".pushsection .discard.unreachable\t\n" \
+   ".long %c0b - .\t\n"\
".popsection\t\n" : : "i" (__LINE__));  \
 })
 #else
diff --git a/include/linux/frame.h b/include/linux/frame.h
index e6baaba3f1ae..d772c61c31da 100644
--- a/include/linux/frame.h
+++ b/include/linux/frame.h
@@ -11,7 +11,7 @@
  * For more information, see tools/objtool/Documentation/stack-validation.txt.
  */
 #define STACK_FRAME_NON_STANDARD(func) \
-   static void __used __section(__func_stack_frame_non_standard) \
+   static void __used __section(.discard.func_stack_frame_non_standard) \
*__func_stack_frame_non_standard_##func = func
 
 #else /* !CONFIG_STACK_VALIDATION */
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 4dedd0d3d3a7..30d752a4a6a6 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -854,6 +854,7 @@ static const char *const section_white_list[] =
".cmem*",   /* EZchip */
".fmt_slot*",   /* EZchip */
".gnu.lto*",
+   ".discard.*",
NULL
 };
 
diff --git a/scripts/module-common.lds b/scripts/module-common.lds
index 73a2c7da0e55..cf7e52e4781b 100644
--- a/scripts/module-common.lds
+++ b/scripts/module-common.lds
@@ -4,7 +4,10 @@
  * combine them automatically.
  */
 SECTIONS {
-   /DISCARD/ : { *(.discard) }
+   /DISCARD/ : {
+   *(.discard)
+   *(.discard.*)
+   }
 
__ksymtab   0 : { *(SORT(___ksymtab+*)) }
__ksymtab_gpl   0 : { *(SORT(___ksymtab_gpl+*)) }
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index 5fc52ee3264c..4cfdbb5b6967 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -339,13 +339,13 @@ static int add_dead_ends(struct objtool_file *file)
struct instruction *insn;
bool found;
 
-   sec = find_section_by_name(file->elf, ".rela__unreachable");
+   sec = find_section_by_name(file->elf, ".rela.discard.unreachable");
if (!sec)
return 0;
 
list_for_each_entry(rela, >rela_list, list) {
if (rela->sym->type != STT_SECTION) {
-   WARN("unexpected relocation symbol type in 
.rela__unreachable");
+   WARN("unexpected relocation symbol type in %s", 
sec->name);
return -1;
}
insn = find_insn(file, rela->sym->sec, rela->addend);
@@ -1272,7 +1272,7 @@ int cmd_check(int argc, const char **argv)
 
INIT_LIST_HEAD(_list);
hash_init(file.insn_hash);
-   file.whitelist = find_section_by_name(file.elf, 
"__func_stack_frame_non_standard");
+   file.whitelist = find_section_by_name(file.elf, 
".discard.func_stack_frame_non_standard");
file.rodata = find_section_by_name(file.elf, ".rodata");
file.ignore_unreachables = false;
file.c_file = find_section_by_name(file.elf, ".comment");


[GIT PULL] objtool fixes

2017-03-01 Thread Ingo Molnar
Linus,

Please pull the latest core-urgent-for-linus git tree from:

   git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 
core-urgent-for-linus

   # HEAD: e390f9a9689a42f477a6073e2e7df530a4c1b740 objtool, modules: Discard 
objtool annotation sections for modules

These two fixes related to the module loading regression introduced by the 
recent 
objtool changes.

 Thanks,

Ingo

-->
Josh Poimboeuf (2):
  objtool, compiler.h: Fix __unreachable section relocation size
  objtool, modules: Discard objtool annotation sections for modules


 arch/x86/kernel/vmlinux.lds.S | 2 --
 include/linux/compiler-gcc.h  | 4 ++--
 include/linux/frame.h | 2 +-
 scripts/mod/modpost.c | 1 +
 scripts/module-common.lds | 5 -
 tools/objtool/builtin-check.c | 6 +++---
 6 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index ad0118fbce90..c74ae9ce8dc4 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -345,8 +345,6 @@ SECTIONS
DISCARDS
/DISCARD/ : {
*(.eh_frame)
-   *(__func_stack_frame_non_standard)
-   *(__unreachable)
}
 }
 
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 76e28c229805..0efef9cf014f 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -200,8 +200,8 @@
 #ifdef CONFIG_STACK_VALIDATION
 #define annotate_unreachable() ({  \
asm("%c0:\t\n"  \
-   ".pushsection __unreachable, \"a\"\t\n" \
-   ".long %c0b\t\n"\
+   ".pushsection .discard.unreachable\t\n" \
+   ".long %c0b - .\t\n"\
".popsection\t\n" : : "i" (__LINE__));  \
 })
 #else
diff --git a/include/linux/frame.h b/include/linux/frame.h
index e6baaba3f1ae..d772c61c31da 100644
--- a/include/linux/frame.h
+++ b/include/linux/frame.h
@@ -11,7 +11,7 @@
  * For more information, see tools/objtool/Documentation/stack-validation.txt.
  */
 #define STACK_FRAME_NON_STANDARD(func) \
-   static void __used __section(__func_stack_frame_non_standard) \
+   static void __used __section(.discard.func_stack_frame_non_standard) \
*__func_stack_frame_non_standard_##func = func
 
 #else /* !CONFIG_STACK_VALIDATION */
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 4dedd0d3d3a7..30d752a4a6a6 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -854,6 +854,7 @@ static const char *const section_white_list[] =
".cmem*",   /* EZchip */
".fmt_slot*",   /* EZchip */
".gnu.lto*",
+   ".discard.*",
NULL
 };
 
diff --git a/scripts/module-common.lds b/scripts/module-common.lds
index 73a2c7da0e55..cf7e52e4781b 100644
--- a/scripts/module-common.lds
+++ b/scripts/module-common.lds
@@ -4,7 +4,10 @@
  * combine them automatically.
  */
 SECTIONS {
-   /DISCARD/ : { *(.discard) }
+   /DISCARD/ : {
+   *(.discard)
+   *(.discard.*)
+   }
 
__ksymtab   0 : { *(SORT(___ksymtab+*)) }
__ksymtab_gpl   0 : { *(SORT(___ksymtab_gpl+*)) }
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index 5fc52ee3264c..4cfdbb5b6967 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -339,13 +339,13 @@ static int add_dead_ends(struct objtool_file *file)
struct instruction *insn;
bool found;
 
-   sec = find_section_by_name(file->elf, ".rela__unreachable");
+   sec = find_section_by_name(file->elf, ".rela.discard.unreachable");
if (!sec)
return 0;
 
list_for_each_entry(rela, >rela_list, list) {
if (rela->sym->type != STT_SECTION) {
-   WARN("unexpected relocation symbol type in 
.rela__unreachable");
+   WARN("unexpected relocation symbol type in %s", 
sec->name);
return -1;
}
insn = find_insn(file, rela->sym->sec, rela->addend);
@@ -1272,7 +1272,7 @@ int cmd_check(int argc, const char **argv)
 
INIT_LIST_HEAD(_list);
hash_init(file.insn_hash);
-   file.whitelist = find_section_by_name(file.elf, 
"__func_stack_frame_non_standard");
+   file.whitelist = find_section_by_name(file.elf, 
".discard.func_stack_frame_non_standard");
file.rodata = find_section_by_name(file.elf, ".rodata");
file.ignore_unreachables = false;
file.c_file = find_section_by_name(file.elf, ".comment");


Re: [GIT PULL] objtool fixes

2017-02-28 Thread Josh Poimboeuf
On Tue, Feb 28, 2017 at 05:55:11PM -0800, Linus Torvalds wrote:
> Guys,
>  the recent 'objtool' pull request broke things.
> 
> I haven't bisected it, but I'm pretty sure that this part is pure garbage:
> 
> On Mon, Feb 27, 2017 at 11:53 PM, Ingo Molnar  wrote:
> >
> > diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> > index e79f15f108a8..ad0118fbce90 100644
> > --- a/arch/x86/kernel/vmlinux.lds.S
> > +++ b/arch/x86/kernel/vmlinux.lds.S
> > @@ -346,6 +346,7 @@ SECTIONS
> > /DISCARD/ : {
> > *(.eh_frame)
> > *(__func_stack_frame_non_standard)
> > +   *(__unreachable)
> > }
> >  }
> >
> > diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
> > index 0444b1336268..f457b520ead6 100644
> > --- a/include/linux/compiler-gcc.h
> > +++ b/include/linux/compiler-gcc.h
> > @@ -195,6 +195,17 @@
> >  #endif
> >  #endif
> >
> > +#ifdef CONFIG_STACK_VALIDATION
> > +#define annotate_unreachable() ({  \
> > +   asm("%c0:\t\n"  \
> > +   ".pushsection __unreachable, \"a\"\t\n" \
> > +   ".long %c0b\t\n"\
> > +   ".popsection\t\n" : : "i" (__LINE__));  \
> > +})
> > +#else
> > +#define annotate_unreachable()
> > +#endif
> 
> and I think the above is what breaks module loading for me right now
> on my laptop.
> 
> I get this during bootup:
> 
> module: overflow in relocation type 10 val c02afc81
> module: 'nvme' likely not compiled with -mcmodel=kernel
> 
> (and similar errors for other modules too), but those modules very
> much *are* compiled with all the normal kernel build flags, including
> -mcmodel=kernel.
> 
> Now, relocation type 10 is R_X86_64_32, so the warning is very true:
> that address would fit in a _signed_ 32-bit value, but that's
> supposedly a 32-bit unsigned relocation.
> 
> Trying to figure out what the hell is going on, I do:
> 
> objdump -r nvme.ko | grep 64_32
> 
> and what do I find? I find
> 
>   RELOCATION RECORDS FOR [__unreachable]:
>   OFFSET   TYPE  VALUE
>    R_X86_64_32   .text+0x0c81
>   0004 R_X86_64_32   .text+0x0cb5
>   0008 R_X86_64_32   .text+0x1a18
>   000c R_X86_64_32   .text+0x1a36
>   0010 R_X86_64_32   .text+0x1e38
>   0014 R_X86_64_32   .text+0x1ec2
>   0018 R_X86_64_32   .text+0x34e2
>   001c R_X86_64_32   .text+0x3536
> 
> and then when I look more closely (objdump --disassemble), I see that
> the offset 000c81 in the module refers to this:
> 
>   0c60 :
> 
>  c7f:   0f 0b   ud2
>  c81:   0f 1f 44 00 00  nopl   0x0(%rax,%rax,1)
> 
> so it very much looks like those relocations are still around on
> modules, and so module loading fails.
> 
> Anyway, those annotations are completely bogus anyway, it looks. You
> guys should use relative offsets in order to be able to specify a
> kernel address. So doing
> 
> .long %c0
> 
> is garbage - either it needs to be a .quad, or it needs to be relative
> to the text section to fit in a .long.
> 
> Hmm? Revert or fix, but please quickly...

Yuck, sorry about that.  Patch to fix it below.

This also highlights another (minor) issue: the '__unreachable' section
is meant to be a compile-time-only thing.  It's supposed to be discarded
at link time, but apparently that isn't happening for modules.

I tried excluding it from linking with the .pushsection "e" flag, but no
luck.  I'll try to figure out how to fix that shortly.

In the meantime, here's the fix you need.  It now uses X86_64_64
relocations.



From: Josh Poimboeuf 
Subject: [PATCH] objtool: fix __unreachable section relocation size

Linus reported the following commit broke module loading on his laptop:

  d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")

It showed errors like the following:

  module: overflow in relocation type 10 val c02afc81
  module: 'nvme' likely not compiled with -mcmodel=kernel

The problem is that the __unreachable section addresses are stored using
the '.long' asm directive, which isn't big enough for .text section
relative kernel addresses.  Use '.quad' instead.

Reported-by: Linus Torvalds 
Suggested-by: Linus Torvalds 
Fixes: d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")
Signed-off-by: Josh Poimboeuf 
---
 include/linux/compiler-gcc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/compiler-gcc.h 

Re: [GIT PULL] objtool fixes

2017-02-28 Thread Josh Poimboeuf
On Tue, Feb 28, 2017 at 05:55:11PM -0800, Linus Torvalds wrote:
> Guys,
>  the recent 'objtool' pull request broke things.
> 
> I haven't bisected it, but I'm pretty sure that this part is pure garbage:
> 
> On Mon, Feb 27, 2017 at 11:53 PM, Ingo Molnar  wrote:
> >
> > diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> > index e79f15f108a8..ad0118fbce90 100644
> > --- a/arch/x86/kernel/vmlinux.lds.S
> > +++ b/arch/x86/kernel/vmlinux.lds.S
> > @@ -346,6 +346,7 @@ SECTIONS
> > /DISCARD/ : {
> > *(.eh_frame)
> > *(__func_stack_frame_non_standard)
> > +   *(__unreachable)
> > }
> >  }
> >
> > diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
> > index 0444b1336268..f457b520ead6 100644
> > --- a/include/linux/compiler-gcc.h
> > +++ b/include/linux/compiler-gcc.h
> > @@ -195,6 +195,17 @@
> >  #endif
> >  #endif
> >
> > +#ifdef CONFIG_STACK_VALIDATION
> > +#define annotate_unreachable() ({  \
> > +   asm("%c0:\t\n"  \
> > +   ".pushsection __unreachable, \"a\"\t\n" \
> > +   ".long %c0b\t\n"\
> > +   ".popsection\t\n" : : "i" (__LINE__));  \
> > +})
> > +#else
> > +#define annotate_unreachable()
> > +#endif
> 
> and I think the above is what breaks module loading for me right now
> on my laptop.
> 
> I get this during bootup:
> 
> module: overflow in relocation type 10 val c02afc81
> module: 'nvme' likely not compiled with -mcmodel=kernel
> 
> (and similar errors for other modules too), but those modules very
> much *are* compiled with all the normal kernel build flags, including
> -mcmodel=kernel.
> 
> Now, relocation type 10 is R_X86_64_32, so the warning is very true:
> that address would fit in a _signed_ 32-bit value, but that's
> supposedly a 32-bit unsigned relocation.
> 
> Trying to figure out what the hell is going on, I do:
> 
> objdump -r nvme.ko | grep 64_32
> 
> and what do I find? I find
> 
>   RELOCATION RECORDS FOR [__unreachable]:
>   OFFSET   TYPE  VALUE
>    R_X86_64_32   .text+0x0c81
>   0004 R_X86_64_32   .text+0x0cb5
>   0008 R_X86_64_32   .text+0x1a18
>   000c R_X86_64_32   .text+0x1a36
>   0010 R_X86_64_32   .text+0x1e38
>   0014 R_X86_64_32   .text+0x1ec2
>   0018 R_X86_64_32   .text+0x34e2
>   001c R_X86_64_32   .text+0x3536
> 
> and then when I look more closely (objdump --disassemble), I see that
> the offset 000c81 in the module refers to this:
> 
>   0c60 :
> 
>  c7f:   0f 0b   ud2
>  c81:   0f 1f 44 00 00  nopl   0x0(%rax,%rax,1)
> 
> so it very much looks like those relocations are still around on
> modules, and so module loading fails.
> 
> Anyway, those annotations are completely bogus anyway, it looks. You
> guys should use relative offsets in order to be able to specify a
> kernel address. So doing
> 
> .long %c0
> 
> is garbage - either it needs to be a .quad, or it needs to be relative
> to the text section to fit in a .long.
> 
> Hmm? Revert or fix, but please quickly...

Yuck, sorry about that.  Patch to fix it below.

This also highlights another (minor) issue: the '__unreachable' section
is meant to be a compile-time-only thing.  It's supposed to be discarded
at link time, but apparently that isn't happening for modules.

I tried excluding it from linking with the .pushsection "e" flag, but no
luck.  I'll try to figure out how to fix that shortly.

In the meantime, here's the fix you need.  It now uses X86_64_64
relocations.



From: Josh Poimboeuf 
Subject: [PATCH] objtool: fix __unreachable section relocation size

Linus reported the following commit broke module loading on his laptop:

  d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")

It showed errors like the following:

  module: overflow in relocation type 10 val c02afc81
  module: 'nvme' likely not compiled with -mcmodel=kernel

The problem is that the __unreachable section addresses are stored using
the '.long' asm directive, which isn't big enough for .text section
relative kernel addresses.  Use '.quad' instead.

Reported-by: Linus Torvalds 
Suggested-by: Linus Torvalds 
Fixes: d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")
Signed-off-by: Josh Poimboeuf 
---
 include/linux/compiler-gcc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index f457b520..7bd21e8 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ 

Re: [GIT PULL] objtool fixes

2017-02-28 Thread Linus Torvalds
Guys,
 the recent 'objtool' pull request broke things.

I haven't bisected it, but I'm pretty sure that this part is pure garbage:

On Mon, Feb 27, 2017 at 11:53 PM, Ingo Molnar  wrote:
>
> diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> index e79f15f108a8..ad0118fbce90 100644
> --- a/arch/x86/kernel/vmlinux.lds.S
> +++ b/arch/x86/kernel/vmlinux.lds.S
> @@ -346,6 +346,7 @@ SECTIONS
> /DISCARD/ : {
> *(.eh_frame)
> *(__func_stack_frame_non_standard)
> +   *(__unreachable)
> }
>  }
>
> diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
> index 0444b1336268..f457b520ead6 100644
> --- a/include/linux/compiler-gcc.h
> +++ b/include/linux/compiler-gcc.h
> @@ -195,6 +195,17 @@
>  #endif
>  #endif
>
> +#ifdef CONFIG_STACK_VALIDATION
> +#define annotate_unreachable() ({  \
> +   asm("%c0:\t\n"  \
> +   ".pushsection __unreachable, \"a\"\t\n" \
> +   ".long %c0b\t\n"\
> +   ".popsection\t\n" : : "i" (__LINE__));  \
> +})
> +#else
> +#define annotate_unreachable()
> +#endif

and I think the above is what breaks module loading for me right now
on my laptop.

I get this during bootup:

module: overflow in relocation type 10 val c02afc81
module: 'nvme' likely not compiled with -mcmodel=kernel

(and similar errors for other modules too), but those modules very
much *are* compiled with all the normal kernel build flags, including
-mcmodel=kernel.

Now, relocation type 10 is R_X86_64_32, so the warning is very true:
that address would fit in a _signed_ 32-bit value, but that's
supposedly a 32-bit unsigned relocation.

Trying to figure out what the hell is going on, I do:

objdump -r nvme.ko | grep 64_32

and what do I find? I find

  RELOCATION RECORDS FOR [__unreachable]:
  OFFSET   TYPE  VALUE
   R_X86_64_32   .text+0x0c81
  0004 R_X86_64_32   .text+0x0cb5
  0008 R_X86_64_32   .text+0x1a18
  000c R_X86_64_32   .text+0x1a36
  0010 R_X86_64_32   .text+0x1e38
  0014 R_X86_64_32   .text+0x1ec2
  0018 R_X86_64_32   .text+0x34e2
  001c R_X86_64_32   .text+0x3536

and then when I look more closely (objdump --disassemble), I see that
the offset 000c81 in the module refers to this:

  0c60 :

 c7f:   0f 0b   ud2
 c81:   0f 1f 44 00 00  nopl   0x0(%rax,%rax,1)

so it very much looks like those relocations are still around on
modules, and so module loading fails.

Anyway, those annotations are completely bogus anyway, it looks. You
guys should use relative offsets in order to be able to specify a
kernel address. So doing

.long %c0

is garbage - either it needs to be a .quad, or it needs to be relative
to the text section to fit in a .long.

Hmm? Revert or fix, but please quickly...

   Linus


Re: [GIT PULL] objtool fixes

2017-02-28 Thread Linus Torvalds
Guys,
 the recent 'objtool' pull request broke things.

I haven't bisected it, but I'm pretty sure that this part is pure garbage:

On Mon, Feb 27, 2017 at 11:53 PM, Ingo Molnar  wrote:
>
> diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> index e79f15f108a8..ad0118fbce90 100644
> --- a/arch/x86/kernel/vmlinux.lds.S
> +++ b/arch/x86/kernel/vmlinux.lds.S
> @@ -346,6 +346,7 @@ SECTIONS
> /DISCARD/ : {
> *(.eh_frame)
> *(__func_stack_frame_non_standard)
> +   *(__unreachable)
> }
>  }
>
> diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
> index 0444b1336268..f457b520ead6 100644
> --- a/include/linux/compiler-gcc.h
> +++ b/include/linux/compiler-gcc.h
> @@ -195,6 +195,17 @@
>  #endif
>  #endif
>
> +#ifdef CONFIG_STACK_VALIDATION
> +#define annotate_unreachable() ({  \
> +   asm("%c0:\t\n"  \
> +   ".pushsection __unreachable, \"a\"\t\n" \
> +   ".long %c0b\t\n"\
> +   ".popsection\t\n" : : "i" (__LINE__));  \
> +})
> +#else
> +#define annotate_unreachable()
> +#endif

and I think the above is what breaks module loading for me right now
on my laptop.

I get this during bootup:

module: overflow in relocation type 10 val c02afc81
module: 'nvme' likely not compiled with -mcmodel=kernel

(and similar errors for other modules too), but those modules very
much *are* compiled with all the normal kernel build flags, including
-mcmodel=kernel.

Now, relocation type 10 is R_X86_64_32, so the warning is very true:
that address would fit in a _signed_ 32-bit value, but that's
supposedly a 32-bit unsigned relocation.

Trying to figure out what the hell is going on, I do:

objdump -r nvme.ko | grep 64_32

and what do I find? I find

  RELOCATION RECORDS FOR [__unreachable]:
  OFFSET   TYPE  VALUE
   R_X86_64_32   .text+0x0c81
  0004 R_X86_64_32   .text+0x0cb5
  0008 R_X86_64_32   .text+0x1a18
  000c R_X86_64_32   .text+0x1a36
  0010 R_X86_64_32   .text+0x1e38
  0014 R_X86_64_32   .text+0x1ec2
  0018 R_X86_64_32   .text+0x34e2
  001c R_X86_64_32   .text+0x3536

and then when I look more closely (objdump --disassemble), I see that
the offset 000c81 in the module refers to this:

  0c60 :

 c7f:   0f 0b   ud2
 c81:   0f 1f 44 00 00  nopl   0x0(%rax,%rax,1)

so it very much looks like those relocations are still around on
modules, and so module loading fails.

Anyway, those annotations are completely bogus anyway, it looks. You
guys should use relative offsets in order to be able to specify a
kernel address. So doing

.long %c0

is garbage - either it needs to be a .quad, or it needs to be relative
to the text section to fit in a .long.

Hmm? Revert or fix, but please quickly...

   Linus


[GIT PULL] objtool fixes

2017-02-27 Thread Ingo Molnar
Linus,

Please pull the latest core-urgent-for-linus git tree from:

   git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 
core-urgent-for-linus

   # HEAD: 4e4636cf981b5b629fbfb78aa9f232e015f7d521 objtool: Enclose contents 
of unreachable() macro in a block

A handful of objtool fixes related to unreachable code, plus a build fix for 
out 
of tree modules.

 Thanks,

Ingo

-->
Josh Poimboeuf (4):
  objtool: Fix CONFIG_STACK_VALIDATION=y warning for out-of-tree modules
  objtool: Improve detection of BUG() and other dead ends
  objtool: Prevent GCC from merging annotate_unreachable()
  objtool: Enclose contents of unreachable() macro in a block


 Makefile| 24 -
 arch/x86/kernel/vmlinux.lds.S   |  1 +
 include/linux/compiler-gcc.h| 14 +-
 tools/objtool/arch.h|  5 ++--
 tools/objtool/arch/x86/decode.c |  3 ---
 tools/objtool/builtin-check.c   | 60 ++---
 6 files changed, 84 insertions(+), 23 deletions(-)

diff --git a/Makefile b/Makefile
index f1e6a02a0c19..32c84577aa93 100644
--- a/Makefile
+++ b/Makefile
@@ -908,6 +908,18 @@ mod_sign_cmd = true
 endif
 export mod_sign_cmd
 
+ifdef CONFIG_STACK_VALIDATION
+  has_libelf := $(call try-run,\
+   echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -,1,0)
+  ifeq ($(has_libelf),1)
+objtool_target := tools/objtool FORCE
+  else
+$(warning "Cannot use CONFIG_STACK_VALIDATION, please install libelf-dev, 
libelf-devel or elfutils-libelf-devel")
+SKIP_STACK_VALIDATION := 1
+export SKIP_STACK_VALIDATION
+  endif
+endif
+
 
 ifeq ($(KBUILD_EXTMOD),)
 core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/
@@ -1035,18 +1047,6 @@ prepare0: archprepare gcc-plugins
 # All the preparing..
 prepare: prepare0 prepare-objtool
 
-ifdef CONFIG_STACK_VALIDATION
-  has_libelf := $(call try-run,\
-   echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -,1,0)
-  ifeq ($(has_libelf),1)
-objtool_target := tools/objtool FORCE
-  else
-$(warning "Cannot use CONFIG_STACK_VALIDATION, please install libelf-dev, 
libelf-devel or elfutils-libelf-devel")
-SKIP_STACK_VALIDATION := 1
-export SKIP_STACK_VALIDATION
-  endif
-endif
-
 PHONY += prepare-objtool
 prepare-objtool: $(objtool_target)
 
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index e79f15f108a8..ad0118fbce90 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -346,6 +346,7 @@ SECTIONS
/DISCARD/ : {
*(.eh_frame)
*(__func_stack_frame_non_standard)
+   *(__unreachable)
}
 }
 
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 0444b1336268..f457b520ead6 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -195,6 +195,17 @@
 #endif
 #endif
 
+#ifdef CONFIG_STACK_VALIDATION
+#define annotate_unreachable() ({  \
+   asm("%c0:\t\n"  \
+   ".pushsection __unreachable, \"a\"\t\n" \
+   ".long %c0b\t\n"\
+   ".popsection\t\n" : : "i" (__LINE__));  \
+})
+#else
+#define annotate_unreachable()
+#endif
+
 /*
  * Mark a position in code as unreachable.  This can be used to
  * suppress control flow warnings after asm blocks that transfer
@@ -204,7 +215,8 @@
  * this in the preprocessor, but we can live with this because they're
  * unreleased.  Really, we need to have autoconf for the kernel.
  */
-#define unreachable() __builtin_unreachable()
+#define unreachable() \
+   do { annotate_unreachable(); __builtin_unreachable(); } while (0)
 
 /* Mark a function definition as prohibited from being cloned. */
 #define __noclone  __attribute__((__noclone__, __optimize__("no-tracer")))
diff --git a/tools/objtool/arch.h b/tools/objtool/arch.h
index f7350fcedc70..a59e061c0b4a 100644
--- a/tools/objtool/arch.h
+++ b/tools/objtool/arch.h
@@ -31,9 +31,8 @@
 #define INSN_CALL_DYNAMIC  8
 #define INSN_RETURN9
 #define INSN_CONTEXT_SWITCH10
-#define INSN_BUG   11
-#define INSN_NOP   12
-#define INSN_OTHER 13
+#define INSN_NOP   11
+#define INSN_OTHER 12
 #define INSN_LAST  INSN_OTHER
 
 int arch_decode_instruction(struct elf *elf, struct section *sec,
diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index 039636ffb6c8..6ac99e3266eb 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -118,9 +118,6 @@ int arch_decode_instruction(struct elf *elf, struct section 
*sec,
 op2 == 0x35)
/* sysenter, sysret */
*type = INSN_CONTEXT_SWITCH;
-

[GIT PULL] objtool fixes

2017-02-27 Thread Ingo Molnar
Linus,

Please pull the latest core-urgent-for-linus git tree from:

   git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 
core-urgent-for-linus

   # HEAD: 4e4636cf981b5b629fbfb78aa9f232e015f7d521 objtool: Enclose contents 
of unreachable() macro in a block

A handful of objtool fixes related to unreachable code, plus a build fix for 
out 
of tree modules.

 Thanks,

Ingo

-->
Josh Poimboeuf (4):
  objtool: Fix CONFIG_STACK_VALIDATION=y warning for out-of-tree modules
  objtool: Improve detection of BUG() and other dead ends
  objtool: Prevent GCC from merging annotate_unreachable()
  objtool: Enclose contents of unreachable() macro in a block


 Makefile| 24 -
 arch/x86/kernel/vmlinux.lds.S   |  1 +
 include/linux/compiler-gcc.h| 14 +-
 tools/objtool/arch.h|  5 ++--
 tools/objtool/arch/x86/decode.c |  3 ---
 tools/objtool/builtin-check.c   | 60 ++---
 6 files changed, 84 insertions(+), 23 deletions(-)

diff --git a/Makefile b/Makefile
index f1e6a02a0c19..32c84577aa93 100644
--- a/Makefile
+++ b/Makefile
@@ -908,6 +908,18 @@ mod_sign_cmd = true
 endif
 export mod_sign_cmd
 
+ifdef CONFIG_STACK_VALIDATION
+  has_libelf := $(call try-run,\
+   echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -,1,0)
+  ifeq ($(has_libelf),1)
+objtool_target := tools/objtool FORCE
+  else
+$(warning "Cannot use CONFIG_STACK_VALIDATION, please install libelf-dev, 
libelf-devel or elfutils-libelf-devel")
+SKIP_STACK_VALIDATION := 1
+export SKIP_STACK_VALIDATION
+  endif
+endif
+
 
 ifeq ($(KBUILD_EXTMOD),)
 core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/
@@ -1035,18 +1047,6 @@ prepare0: archprepare gcc-plugins
 # All the preparing..
 prepare: prepare0 prepare-objtool
 
-ifdef CONFIG_STACK_VALIDATION
-  has_libelf := $(call try-run,\
-   echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -,1,0)
-  ifeq ($(has_libelf),1)
-objtool_target := tools/objtool FORCE
-  else
-$(warning "Cannot use CONFIG_STACK_VALIDATION, please install libelf-dev, 
libelf-devel or elfutils-libelf-devel")
-SKIP_STACK_VALIDATION := 1
-export SKIP_STACK_VALIDATION
-  endif
-endif
-
 PHONY += prepare-objtool
 prepare-objtool: $(objtool_target)
 
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index e79f15f108a8..ad0118fbce90 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -346,6 +346,7 @@ SECTIONS
/DISCARD/ : {
*(.eh_frame)
*(__func_stack_frame_non_standard)
+   *(__unreachable)
}
 }
 
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 0444b1336268..f457b520ead6 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -195,6 +195,17 @@
 #endif
 #endif
 
+#ifdef CONFIG_STACK_VALIDATION
+#define annotate_unreachable() ({  \
+   asm("%c0:\t\n"  \
+   ".pushsection __unreachable, \"a\"\t\n" \
+   ".long %c0b\t\n"\
+   ".popsection\t\n" : : "i" (__LINE__));  \
+})
+#else
+#define annotate_unreachable()
+#endif
+
 /*
  * Mark a position in code as unreachable.  This can be used to
  * suppress control flow warnings after asm blocks that transfer
@@ -204,7 +215,8 @@
  * this in the preprocessor, but we can live with this because they're
  * unreleased.  Really, we need to have autoconf for the kernel.
  */
-#define unreachable() __builtin_unreachable()
+#define unreachable() \
+   do { annotate_unreachable(); __builtin_unreachable(); } while (0)
 
 /* Mark a function definition as prohibited from being cloned. */
 #define __noclone  __attribute__((__noclone__, __optimize__("no-tracer")))
diff --git a/tools/objtool/arch.h b/tools/objtool/arch.h
index f7350fcedc70..a59e061c0b4a 100644
--- a/tools/objtool/arch.h
+++ b/tools/objtool/arch.h
@@ -31,9 +31,8 @@
 #define INSN_CALL_DYNAMIC  8
 #define INSN_RETURN9
 #define INSN_CONTEXT_SWITCH10
-#define INSN_BUG   11
-#define INSN_NOP   12
-#define INSN_OTHER 13
+#define INSN_NOP   11
+#define INSN_OTHER 12
 #define INSN_LAST  INSN_OTHER
 
 int arch_decode_instruction(struct elf *elf, struct section *sec,
diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index 039636ffb6c8..6ac99e3266eb 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -118,9 +118,6 @@ int arch_decode_instruction(struct elf *elf, struct section 
*sec,
 op2 == 0x35)
/* sysenter, sysret */
*type = INSN_CONTEXT_SWITCH;
-

[GIT PULL] objtool fixes

2016-04-23 Thread Ingo Molnar
Linus,

Please pull the latest core-urgent-for-linus git tree from:

   git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 
core-urgent-for-linus

   # HEAD: c2bb9e32e2315971a8535fee77335c04a739d71d objtool: Fix Makefile to 
properly see if libelf is supported

A handful of objtool fixes: two improvements to how warnings are printed plus a 
false positive warning fix, and build environment fix.

 Thanks,

Ingo

-->
Josh Poimboeuf (2):
  objtool: Add workaround for GCC switch jump table bug
  objtool: Detect falling through to the next function

Steven Rostedt (1):
  objtool: Fix Makefile to properly see if libelf is supported


 Makefile |  3 +-
 tools/objtool/Documentation/stack-validation.txt | 38 +++---
 tools/objtool/builtin-check.c| 97 ++--
 3 files changed, 103 insertions(+), 35 deletions(-)

diff --git a/Makefile b/Makefile
index 1d0aef03eae7..70ca38ef9f4b 100644
--- a/Makefile
+++ b/Makefile
@@ -1008,7 +1008,8 @@ prepare0: archprepare FORCE
 prepare: prepare0 prepare-objtool
 
 ifdef CONFIG_STACK_VALIDATION
-  has_libelf := $(shell echo "int main() {}" | $(HOSTCC) -xc -o /dev/null 
-lelf - &> /dev/null && echo 1 || echo 0)
+  has_libelf := $(call try-run,\
+   echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -,1,0)
   ifeq ($(has_libelf),1)
 objtool_target := tools/objtool FORCE
   else
diff --git a/tools/objtool/Documentation/stack-validation.txt 
b/tools/objtool/Documentation/stack-validation.txt
index 5a95896105bc..55a60d331f47 100644
--- a/tools/objtool/Documentation/stack-validation.txt
+++ b/tools/objtool/Documentation/stack-validation.txt
@@ -299,18 +299,38 @@ they mean, and suggestions for how to fix them.
 Errors in .c files
 --
 
-If you're getting an objtool error in a compiled .c file, chances are
-the file uses an asm() statement which has a "call" instruction.  An
-asm() statement with a call instruction must declare the use of the
-stack pointer in its output operand.  For example, on x86_64:
+1. c_file.o: warning: objtool: funcA() falls through to next function funcB()
 
-   register void *__sp asm("rsp");
-   asm volatile("call func" : "+r" (__sp));
+   This means that funcA() doesn't end with a return instruction or an
+   unconditional jump, and that objtool has determined that the function
+   can fall through into the next function.  There could be different
+   reasons for this:
 
-Otherwise the stack frame may not get created before the call.
+   1) funcA()'s last instruction is a call to a "noreturn" function like
+  panic().  In this case the noreturn function needs to be added to
+  objtool's hard-coded global_noreturns array.  Feel free to bug the
+  objtool maintainer, or you can submit a patch.
 
-Another possible cause for errors in C code is if the Makefile removes
--fno-omit-frame-pointer or adds -fomit-frame-pointer to the gcc options.
+   2) funcA() uses the unreachable() annotation in a section of code
+  that is actually reachable.
+
+   3) If funcA() calls an inline function, the object code for funcA()
+  might be corrupt due to a gcc bug.  For more details, see:
+  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70646
+
+2. If you're getting any other objtool error in a compiled .c file, it
+   may be because the file uses an asm() statement which has a "call"
+   instruction.  An asm() statement with a call instruction must declare
+   the use of the stack pointer in its output operand.  For example, on
+   x86_64:
+
+ register void *__sp asm("rsp");
+ asm volatile("call func" : "+r" (__sp));
+
+   Otherwise the stack frame may not get created before the call.
+
+3. Another possible cause for errors in C code is if the Makefile removes
+   -fno-omit-frame-pointer or adds -fomit-frame-pointer to the gcc options.
 
 Also see the above section for .S file errors for more information what
 the individual error messages mean.
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index 7515cb2e879a..e8a1e69eb92c 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -54,6 +54,7 @@ struct instruction {
struct symbol *call_dest;
struct instruction *jump_dest;
struct list_head alts;
+   struct symbol *func;
 };
 
 struct alternative {
@@ -66,6 +67,7 @@ struct objtool_file {
struct list_head insn_list;
DECLARE_HASHTABLE(insn_hash, 16);
struct section *rodata, *whitelist;
+   bool ignore_unreachables, c_file;
 };
 
 const char *objname;
@@ -228,7 +230,7 @@ static int __dead_end_function(struct objtool_file *file, 
struct symbol *func,
}
}
 
-   if (insn->type == INSN_JUMP_DYNAMIC)
+   if (insn->type == INSN_JUMP_DYNAMIC && list_empty(>alts))
/* sibling call */

[GIT PULL] objtool fixes

2016-04-23 Thread Ingo Molnar
Linus,

Please pull the latest core-urgent-for-linus git tree from:

   git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 
core-urgent-for-linus

   # HEAD: c2bb9e32e2315971a8535fee77335c04a739d71d objtool: Fix Makefile to 
properly see if libelf is supported

A handful of objtool fixes: two improvements to how warnings are printed plus a 
false positive warning fix, and build environment fix.

 Thanks,

Ingo

-->
Josh Poimboeuf (2):
  objtool: Add workaround for GCC switch jump table bug
  objtool: Detect falling through to the next function

Steven Rostedt (1):
  objtool: Fix Makefile to properly see if libelf is supported


 Makefile |  3 +-
 tools/objtool/Documentation/stack-validation.txt | 38 +++---
 tools/objtool/builtin-check.c| 97 ++--
 3 files changed, 103 insertions(+), 35 deletions(-)

diff --git a/Makefile b/Makefile
index 1d0aef03eae7..70ca38ef9f4b 100644
--- a/Makefile
+++ b/Makefile
@@ -1008,7 +1008,8 @@ prepare0: archprepare FORCE
 prepare: prepare0 prepare-objtool
 
 ifdef CONFIG_STACK_VALIDATION
-  has_libelf := $(shell echo "int main() {}" | $(HOSTCC) -xc -o /dev/null 
-lelf - &> /dev/null && echo 1 || echo 0)
+  has_libelf := $(call try-run,\
+   echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -,1,0)
   ifeq ($(has_libelf),1)
 objtool_target := tools/objtool FORCE
   else
diff --git a/tools/objtool/Documentation/stack-validation.txt 
b/tools/objtool/Documentation/stack-validation.txt
index 5a95896105bc..55a60d331f47 100644
--- a/tools/objtool/Documentation/stack-validation.txt
+++ b/tools/objtool/Documentation/stack-validation.txt
@@ -299,18 +299,38 @@ they mean, and suggestions for how to fix them.
 Errors in .c files
 --
 
-If you're getting an objtool error in a compiled .c file, chances are
-the file uses an asm() statement which has a "call" instruction.  An
-asm() statement with a call instruction must declare the use of the
-stack pointer in its output operand.  For example, on x86_64:
+1. c_file.o: warning: objtool: funcA() falls through to next function funcB()
 
-   register void *__sp asm("rsp");
-   asm volatile("call func" : "+r" (__sp));
+   This means that funcA() doesn't end with a return instruction or an
+   unconditional jump, and that objtool has determined that the function
+   can fall through into the next function.  There could be different
+   reasons for this:
 
-Otherwise the stack frame may not get created before the call.
+   1) funcA()'s last instruction is a call to a "noreturn" function like
+  panic().  In this case the noreturn function needs to be added to
+  objtool's hard-coded global_noreturns array.  Feel free to bug the
+  objtool maintainer, or you can submit a patch.
 
-Another possible cause for errors in C code is if the Makefile removes
--fno-omit-frame-pointer or adds -fomit-frame-pointer to the gcc options.
+   2) funcA() uses the unreachable() annotation in a section of code
+  that is actually reachable.
+
+   3) If funcA() calls an inline function, the object code for funcA()
+  might be corrupt due to a gcc bug.  For more details, see:
+  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70646
+
+2. If you're getting any other objtool error in a compiled .c file, it
+   may be because the file uses an asm() statement which has a "call"
+   instruction.  An asm() statement with a call instruction must declare
+   the use of the stack pointer in its output operand.  For example, on
+   x86_64:
+
+ register void *__sp asm("rsp");
+ asm volatile("call func" : "+r" (__sp));
+
+   Otherwise the stack frame may not get created before the call.
+
+3. Another possible cause for errors in C code is if the Makefile removes
+   -fno-omit-frame-pointer or adds -fomit-frame-pointer to the gcc options.
 
 Also see the above section for .S file errors for more information what
 the individual error messages mean.
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index 7515cb2e879a..e8a1e69eb92c 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -54,6 +54,7 @@ struct instruction {
struct symbol *call_dest;
struct instruction *jump_dest;
struct list_head alts;
+   struct symbol *func;
 };
 
 struct alternative {
@@ -66,6 +67,7 @@ struct objtool_file {
struct list_head insn_list;
DECLARE_HASHTABLE(insn_hash, 16);
struct section *rodata, *whitelist;
+   bool ignore_unreachables, c_file;
 };
 
 const char *objname;
@@ -228,7 +230,7 @@ static int __dead_end_function(struct objtool_file *file, 
struct symbol *func,
}
}
 
-   if (insn->type == INSN_JUMP_DYNAMIC)
+   if (insn->type == INSN_JUMP_DYNAMIC && list_empty(>alts))
/* sibling call */