From 663ddf8f17c06717d0b223ab3b133fea996a7afb Mon Sep 17 00:00:00 2001
From: Felix Fietkau <nbd@openwrt.org>
Date: Sun, 19 Oct 2014 16:18:56 +0000
Subject: [PATCH] gcc: backport an upstream fix for extern vars with local weak
 definitions

Signed-off-by: Felix Fietkau <nbd@openwrt.org>

SVN-Revision: 42962
---
 .../patches/4.9-linaro/020-fix_pr61144.patch  | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 toolchain/gcc/patches/4.9-linaro/020-fix_pr61144.patch

diff --git a/toolchain/gcc/patches/4.9-linaro/020-fix_pr61144.patch b/toolchain/gcc/patches/4.9-linaro/020-fix_pr61144.patch
new file mode 100644
index 0000000000..a6b320d881
--- /dev/null
+++ b/toolchain/gcc/patches/4.9-linaro/020-fix_pr61144.patch
@@ -0,0 +1,21 @@
+--- a/gcc/varpool.c
++++ b/gcc/varpool.c
+@@ -329,8 +329,16 @@ ctor_for_folding (tree decl)
+ 
+   /* Variables declared 'const' without an initializer
+      have zero as the initializer if they may not be
+-     overridden at link or run time.  */
+-  if (!DECL_INITIAL (real_decl)
++     overridden at link or run time.
++
++     It is actually requirement for C++ compiler to optimize const variables
++     consistently. As a GNU extension, do not enfore this rule for user defined
++     weak variables, so we support interposition on:
++     static const int dummy = 0;
++     extern const int foo __attribute__((__weak__, __alias__("dummy"))); 
++   */
++  if ((!DECL_INITIAL (real_decl)
++       || (DECL_WEAK (decl) && !DECL_COMDAT (decl)))
+       && (DECL_EXTERNAL (decl) || decl_replaceable_p (decl)))
+     return error_mark_node;
+ 
-- 
GitLab