As reported in PR80993, enabling lto causes interrupt handlers to be
removed. This patch marks interrupt handlers as used, preventing them
from being optimized out.

If the attached patch is acceptable, I would appreciate if someone could
commit it for me, as I do not have write access.

Thanks,
Jozef
From 44b14ffae0e8956f40cd5356a9f00f5d055709c7 Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <joze...@somniumtech.com>
Date: Thu, 24 Aug 2017 11:10:24 +0000
Subject: [PATCH] MSP430: Prevent lto removing interrupt handlers

2017-08-XX      Jozef Lawrynowicz       <joze...@somniumtech.com>
        
        PR target/80993
        * gcc/config/msp430/msp430.c (msp430_attr): Mark interrupt handlers as
        used.
        
gcc/testsuite
2017-08-XX      Jozef Lawrynowicz       <joze...@somniumtech.com>
        
        PR target/80993
        * gcc.target/msp430/pr80993.c: New test.
---
 gcc/config/msp430/msp430.c                |  4 ++++
 gcc/testsuite/gcc.target/msp430/pr80993.c | 13 +++++++++++++
 2 files changed, 17 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/msp430/pr80993.c

diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c
index 2b4427d..48fc12d 100644
--- a/gcc/config/msp430/msp430.c
+++ b/gcc/config/msp430/msp430.c
@@ -1904,6 +1904,10 @@ msp430_attr (tree * node,
 
       if (! TREE_PUBLIC (* node))
        message = "interrupt handlers cannot be static";
+
+      /* Ensure interrupt handlers never get optimised out.  */
+      TREE_USED (* node) = 1;
+      DECL_PRESERVE_P (* node) = 1;
     }
   else if (TREE_NAME_EQ (name, ATTR_REENT))
     {
diff --git a/gcc/testsuite/gcc.target/msp430/pr80993.c 
b/gcc/testsuite/gcc.target/msp430/pr80993.c
new file mode 100644
index 0000000..4da5cf9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/msp430/pr80993.c
@@ -0,0 +1,13 @@
+/* { dg-do link } */
+/* { dg-options "--save-temps -msim -flto -Os" } */
+/* { dg-final { scan-file "pr80993.exe.ltrans0.s" no_ref_handler } } */
+
+void __attribute__((interrupt)) no_ref_handler (void)
+{
+  while (1);
+}
+
+int main (void)
+{
+  return 0;
+}
-- 
1.8.3.1

Reply via email to