[BPF] Support weak global variables for BTF

Generate types for global variables with "weak" attribute.
Keep allocation scope the same for both weak and non-weak
globals as ELF symbol table can determine whether a global
symbol is weak or not.

Differential Revision: https://reviews.llvm.org/D71162
diff --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp
index b2d5fc3..51a6142 100644
--- a/llvm/lib/Target/BPF/BTFDebug.cpp
+++ b/llvm/lib/Target/BPF/BTFDebug.cpp
@@ -1092,7 +1092,7 @@
 
     // Only support the following globals:
     //  . static variables
-    //  . non-static global variables
+    //  . non-static weak or non-weak global variables
     // Essentially means:
     //  . .bcc/.data/.rodata DataSec entities only contain static data
     //  . Other DataSec entities contain static or initialized global data.
@@ -1101,12 +1101,13 @@
     //    corresponding ELF section flags.
     auto Linkage = Global.getLinkage();
     if (Linkage != GlobalValue::InternalLinkage &&
-        Linkage != GlobalValue::ExternalLinkage)
+        Linkage != GlobalValue::ExternalLinkage &&
+        Linkage != GlobalValue::WeakAnyLinkage)
       continue;
 
-    uint32_t GVarInfo = Linkage == GlobalValue::ExternalLinkage
-                            ? BTF::VAR_GLOBAL_ALLOCATED
-                            : BTF::VAR_STATIC;
+    uint32_t GVarInfo = Linkage == GlobalValue::InternalLinkage
+                            ? BTF::VAR_STATIC
+                            : BTF::VAR_GLOBAL_ALLOCATED;
     auto VarEntry =
         std::make_unique<BTFKindVar>(Global.getName(), GVTypeId, GVarInfo);
     uint32_t VarId = addType(std::move(VarEntry));