[llvm] 166cdc0 - [BPF] generate BTF_KIND_VARs for all non-static globals

Yonghong Song via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 12 14:35:53 PST 2019


Author: Yonghong Song
Date: 2019-11-12T14:34:08-08:00
New Revision: 166cdc02818fd7a6653f76216b4f64cb4b21619e

URL: https://github.com/llvm/llvm-project/commit/166cdc02818fd7a6653f76216b4f64cb4b21619e
DIFF: https://github.com/llvm/llvm-project/commit/166cdc02818fd7a6653f76216b4f64cb4b21619e.diff

LOG: [BPF] generate BTF_KIND_VARs for all non-static globals

Enable to generate BTF_KIND_VARs for non-static
default-section globals which is not allowed previously.
Modified the existing test case to accommodate the new change.

Also removed unused linkage enum members VAR_GLOBAL_TENTATIVE and
VAR_GLOBAL_EXTERNAL.

Differential Revision: https://reviews.llvm.org/D70145

Added: 
    

Modified: 
    llvm/lib/Target/BPF/BTF.h
    llvm/lib/Target/BPF/BTFDebug.cpp
    llvm/test/CodeGen/BPF/BTF/global-var-inited.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/BPF/BTF.h b/llvm/lib/Target/BPF/BTF.h
index a13c862bf840..9f1a9f915b50 100644
--- a/llvm/lib/Target/BPF/BTF.h
+++ b/llvm/lib/Target/BPF/BTF.h
@@ -180,8 +180,6 @@ struct BTFParam {
 enum : uint8_t {
   VAR_STATIC = 0,           ///< Linkage: InternalLinkage
   VAR_GLOBAL_ALLOCATED = 1, ///< Linkage: ExternalLinkage
-  VAR_GLOBAL_TENTATIVE = 2, ///< Linkage: CommonLinkage
-  VAR_GLOBAL_EXTERNAL = 3,  ///< Linkage: ExternalLinkage
 };
 
 /// BTF_KIND_DATASEC are followed by multiple "struct BTFDataSecVar".

diff  --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp
index db551e739bd7..b2d5fc307ad3 100644
--- a/llvm/lib/Target/BPF/BTFDebug.cpp
+++ b/llvm/lib/Target/BPF/BTFDebug.cpp
@@ -1076,6 +1076,11 @@ void BTFDebug::processGlobals(bool ProcessingMapDef) {
 
     SmallVector<DIGlobalVariableExpression *, 1> GVs;
     Global.getDebugInfo(GVs);
+
+    // No type information, mostly internal, skip it.
+    if (GVs.size() == 0)
+      continue;
+
     uint32_t GVTypeId = 0;
     for (auto *GVE : GVs) {
       if (SecName.startswith(".maps"))
@@ -1087,7 +1092,7 @@ void BTFDebug::processGlobals(bool ProcessingMapDef) {
 
     // Only support the following globals:
     //  . static variables
-    //  . non-static global variables with section attributes
+    //  . non-static global variables
     // Essentially means:
     //  . .bcc/.data/.rodata DataSec entities only contain static data
     //  . Other DataSec entities contain static or initialized global data.
@@ -1096,7 +1101,7 @@ void BTFDebug::processGlobals(bool ProcessingMapDef) {
     //    corresponding ELF section flags.
     auto Linkage = Global.getLinkage();
     if (Linkage != GlobalValue::InternalLinkage &&
-        (Linkage != GlobalValue::ExternalLinkage || !Global.hasSection()))
+        Linkage != GlobalValue::ExternalLinkage)
       continue;
 
     uint32_t GVarInfo = Linkage == GlobalValue::ExternalLinkage

diff  --git a/llvm/test/CodeGen/BPF/BTF/global-var-inited.ll b/llvm/test/CodeGen/BPF/BTF/global-var-inited.ll
index 18313b5a2c3f..d5f745076d66 100644
--- a/llvm/test/CodeGen/BPF/BTF/global-var-inited.ll
+++ b/llvm/test/CodeGen/BPF/BTF/global-var-inited.ll
@@ -14,16 +14,30 @@
 ; CHECK-NEXT:        .byte   0
 ; CHECK-NEXT:        .long   24
 ; CHECK-NEXT:        .long   0
-; CHECK-NEXT:        .long   16
-; CHECK-NEXT:        .long   16
-; CHECK-NEXT:        .long   5
+; CHECK-NEXT:        .long   56
+; CHECK-NEXT:        .long   56
+; CHECK-NEXT:        .long   13
 ; CHECK-NEXT:        .long   1                       # BTF_KIND_INT(id = 1)
 ; CHECK-NEXT:        .long   16777216                # 0x1000000
 ; CHECK-NEXT:        .long   4
 ; CHECK-NEXT:        .long   16777248                # 0x1000020
+; CHECK-NEXT:        .long   5                       # BTF_KIND_VAR(id = 2)
+; CHECK-NEXT:        .long   234881024               # 0xe000000
+; CHECK-NEXT:        .long   1
+; CHECK-NEXT:        .long   1
+; CHECK-NEXT:        .long   7                       # BTF_KIND_DATASEC(id = 3)
+; CHECK-NEXT:        .long   251658241               # 0xf000001
+; CHECK-NEXT:        .long   0
+; CHECK-NEXT:        .long   2
+; CHECK-NEXT:        .long   a
+; CHECK-NEXT:        .long   4
 ; CHECK-NEXT:        .byte   0                       # string offset=0
 ; CHECK-NEXT:        .ascii  "int"                   # string offset=1
 ; CHECK-NEXT:        .byte   0
+; CHECK-NEXT:        .byte   97                      # string offset=5
+; CHECK-NEXT:        .byte   0
+; CHECK-NEXT:        .ascii  ".data"                 # string offset=7
+; CHECK-NEXT:        .byte   0
 
 !llvm.dbg.cu = !{!2}
 !llvm.module.flags = !{!7, !8, !9}


        


More information about the llvm-commits mailing list