From 24cdd77e84d038b95784b5522c906967303d7c9d Mon Sep 17 00:00:00 2001
From: Nehal J Wani <nehaljw.kkd1@gmail.com>
Date: Sun, 9 May 2021 17:29:26 -0400
Subject: [PATCH 11/21] Reduce number of symbols being exported from mysqld.exe

Due to the export limit (16-bit ordinal field in PE, max val = 2^16-1),
if the number of symbols required to be exported end up to be greater
than 65535, link.exe errors out with:
   LINK : fatal error LNK1189: library limit of 65535 objects exceeded

The number of symbols generated with create_def.cc for 8.0.26 are greater than
65535. This patch filters out the rapidjson and boost symbols since they are
from headers only and if the plugins require them, they are likely to include
them inside the DLL itself. The change brings down the count to approx. 65174,
which is < 65535.
---
 sql/create_def.cc | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/sql/create_def.cc b/sql/create_def.cc
index 24813216df9..94fd456f347 100644
--- a/sql/create_def.cc
+++ b/sql/create_def.cc
@@ -330,6 +330,13 @@ void Unique_symbol_map::insert(const std::string &symbol_line) {
       "<lambda_",    // anything that is lambda-related
       "??$forward",  // std::forward template instantiations
   };
+  // Symbols from 3rd party header only libraries
+  // Plugins will include them if required
+  static const char *third_party_symbols[] = {
+      "@rapidjson@@",
+      "@boost@@"
+  };
+
   if (symbol_line.find("External") == std::string::npos) {
     return;
   }
@@ -379,6 +386,14 @@ void Unique_symbol_map::insert(const std::string &symbol_line) {
       return;
     }
   }
+  // Extract the actual symbol name we care about and check it's not on list of
+  // third party header only libraries.
+  for (auto &third_party_symbol : third_party_symbols) {
+    if (symbol.find(third_party_symbol) != std::string::npos) {
+      return;
+    }
+  }
+
   // Check if we have function or data.
   if (symbol_line.find("notype () ") == std::string::npos) {
     symbol.append(" DATA");
-- 
2.41.0

