$OpenBSD: patch-tools_lld_ELF_SymbolTable_cpp,v 1.2 2017/09/01 06:40:28 ajacoutot Exp $

Work around a problem where linker-generated symbols are not properly
versioned and end up as local symbols despite being explicitly listed as
global in the version script.  This breaks our brk()/sbrk() implementation.

The diff is only a partial solution and unlikely to be accepted as-is
upstream.  We'll keep it as a local diff until a better solution is found.

Index: tools/lld/ELF/SymbolTable.cpp
--- tools/lld/ELF/SymbolTable.cpp.orig
+++ tools/lld/ELF/SymbolTable.cpp
@@ -145,6 +145,12 @@ DefinedRegular *SymbolTable<ELFT>::addIgnored(StringRe
   SymbolBody *S = find(Name);
   if (!S || S->isInCurrentDSO())
     return nullptr;
+  if (Visibility == STV_DEFAULT) {
+    for (SymbolVersion &Ver : Config->VersionScriptGlobals) {
+      if (!Ver.HasWildcard && Ver.Name == S->getName())
+        S->symbol()->VersionId = VER_NDX_GLOBAL;
+    }
+  }
   return addAbsolute(Name, Visibility);
 }
 
