From fe015a6df72349c3cf654ea3eb80b46e52b10e1e Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 24 Sep 2021 18:16:35 +0000 Subject: core: Add forward declaration for IRQ handler routine clang warns when attribute declarations do not precede definitions: error: attribute declaration must precede definition [-Werror,-Wignored-attributes] The cortex-m/irq_handler.h file uses the "__keep" attribute on "routine". The declaration with the attribute must come before the definition or the compiler will ignore it. This results in link errors when using LTO with lld since it is optimized out. In order to fix this, the DECLARE_IRQ instances must be moved before the function definitions. However, if DECLARE_IRQ instances are moved without this change, we will get an implicit declaration compiler error: error: implicit declaration of function 'uart_interrupt' This change does not change the resulting output as verified by the "compare_builds.sh" script. BRANCH=none BUG=b:172020503 TEST=./util/compare_builds.sh -b all -j 70 Signed-off-by: Tom Hughes Change-Id: Icb282cb0f0a0557d6bc1d184378c5923d0e3a72d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3182634 Reviewed-by: Eric Yilun Lin --- core/cortex-m0/irq_handler.h | 2 ++ core/host/irq_handler.h | 1 + core/nds32/irq_handler.h | 1 + core/riscv-rv32i/irq_handler.h | 1 + 4 files changed, 5 insertions(+) diff --git a/core/cortex-m0/irq_handler.h b/core/cortex-m0/irq_handler.h index 1ad033ab2d..de36ef7623 100644 --- a/core/cortex-m0/irq_handler.h +++ b/core/cortex-m0/irq_handler.h @@ -21,6 +21,7 @@ #define DECLARE_IRQ(irq, routine, priority) DECLARE_IRQ_(irq, routine, priority) #ifdef CONFIG_TASK_PROFILING #define DECLARE_IRQ_(irq, routine, priority) \ + void routine(void); \ void IRQ_HANDLER(irq)(void) \ { \ void *ret = __builtin_return_address(0); \ @@ -34,6 +35,7 @@ #else /* CONFIG_TASK_PROFILING */ /* No Profiling : connect directly the IRQ vector */ #define DECLARE_IRQ_(irq, routine, priority) \ + void routine(void); \ void IRQ_HANDLER(irq)(void) __attribute__((alias(STRINGIFY(routine))));\ const struct irq_priority __keep IRQ_PRIORITY(irq) \ __attribute__((section(".rodata.irqprio"))) \ diff --git a/core/host/irq_handler.h b/core/host/irq_handler.h index 9ff5d9979c..f905f463c1 100644 --- a/core/host/irq_handler.h +++ b/core/host/irq_handler.h @@ -16,6 +16,7 @@ * ensure it is enabled in the interrupt controller with the right priority. */ #define DECLARE_IRQ(irq, routine, priority) \ + void routine(void); \ void IRQ_HANDLER(irq)(void) \ { \ void *ret = __builtin_return_address(0); \ diff --git a/core/nds32/irq_handler.h b/core/nds32/irq_handler.h index b37b7927ef..eb55d9e233 100644 --- a/core/nds32/irq_handler.h +++ b/core/nds32/irq_handler.h @@ -16,6 +16,7 @@ * ensure it is enabled in the interrupt controller with the right priority. */ #define DECLARE_IRQ(irq, routine, priority) \ + void routine(void); \ void IRQ_HANDLER(CPU_INT(irq))(void) \ __attribute__ ((alias(STRINGIFY(routine)))); \ const struct irq_priority __keep IRQ_PRIORITY(CPU_INT(irq)) \ diff --git a/core/riscv-rv32i/irq_handler.h b/core/riscv-rv32i/irq_handler.h index 8d26ae6474..6414f90c7f 100644 --- a/core/riscv-rv32i/irq_handler.h +++ b/core/riscv-rv32i/irq_handler.h @@ -21,6 +21,7 @@ * ensure it is enabled in the interrupt controller with the right priority. */ #define DECLARE_IRQ(irq, routine, priority) \ + void routine(void); \ void IRQ_HANDLER(CPU_INT(irq))(void) \ __attribute__ ((alias(STRINGIFY(routine)))); \ const struct irq_priority __keep IRQ_PRIORITY(CPU_INT(irq)) \ -- cgit v1.2.1