[PATCH] D70625: [DebugInfo][BPF] Support to emit debugInfo for extern variables

2019-11-25 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song abandoned this revision.
yonghong-song added a comment.

@dblaikie As suggested, just submitted two separate patches:

- https://reviews.llvm.org/D70696 for clang/llvm change to generate debuginfo 
for extern variables
- https://reviews.llvm.org/D70697 for BPF backend to consume such debuginfo.

Please help take a look. Thanks!

I will abandon this patch to avoid confusion.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70625/new/

https://reviews.llvm.org/D70625



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70625: [DebugInfo][BPF] Support to emit debugInfo for extern variables

2019-11-23 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

@dblaikie Thanks for the review. To address your comments below:

> the title talks about global variables
>  the description talks about extern types (guessing that's just a typo?)

The title is "Support to emit debugInfo for extern variables". In the 
description, I am using "extern" variables as well. But in the implementation, 
I am using "GlobalDecl" or "GlobalDeclOnly". I indeed need to make naming 
convention consistent.

>   the patch itself seems to have code that's visiting more functions? ( 
> processFuncPrototypes )

The proceessFuncPrototypes filtered any function without debug info and 
defined. So based on my testing, it only emits extern functions. But do let me 
know if I miss anything here.

>   & also I'd generally still prefer to see two patches for each piece of new 
> debug info - first adding the functionality to LLVM, then second using that 
> functionality in Clang (even though we're in the monorepo - these are still 
> divisible patches that makes code review, revert, root cause analysis, etc, 
> easier)

Agree. I will separate the patch into two separate patches as you suggested, 
add more tests for the clang patch and resubmit.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70625/new/

https://reviews.llvm.org/D70625



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70625: [DebugInfo][BPF] Support to emit debugInfo for extern variables

2019-11-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Seems to have a few things going on

- the title talks about global variables
- the description talks about extern types (guessing that's just a typo?)
- the patch itself seems to have code that's visiting more functions? ( 
processFuncPrototypes )
- & also I'd generally still prefer to see two patches for each piece of new 
debug info - first adding the functionality to LLVM, then second using that 
functionality in Clang (even though we're in the monorepo - these are still 
divisible patches that makes code review, revert, root cause analysis, etc, 
easier)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70625/new/

https://reviews.llvm.org/D70625



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70625: [DebugInfo][BPF] Support to emit debugInfo for extern variables

2019-11-22 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song created this revision.
yonghong-song added reviewers: aprantl, dblaikie, RKSimon, ast.
yonghong-song added a project: debug-info.
Herald added subscribers: llvm-commits, cfe-commits, ormris, hiraditya.
Herald added projects: clang, LLVM.

extern variable usage in BPF is different from traditional
pure user space application. Recent discussion in linux bpf 
mailing list has two use cases where debug info types are 
required to use extern variables:

- extern types are required to have a suitable interface in libbpf (bpf loader) 
to provide kernel config parameters to bpf programs. 
https://lore.kernel.org/bpf/CAEf4BzYCNo5GeVGMhp3fhysQ=_axAf=23ptwazs-yayafmx...@mail.gmail.com/T/#t
- extern types are required so kernel bpf verifier can verify program which 
uses external functions more precisely. This will make later link with actual 
external function no need to reverify. 
https://lore.kernel.org/bpf/87eez4odqp@toke.dk/T/#m8d5c3e87ffe7f2764e02d722cb0d8cbc136880ed

This patch added clang support to emit debuginfo for extern variables,
and bpf support to consume such info into BTF, which can then be used
by bpf loader.

A few more things need to do:

- currently, I added clang EmitGlobalDeclVariable() to emit debuginfo for 
extern variables. It might be possible to reuse existing EmitGlobalVariable(). 
Need double check.
- BPF is C only, so I only tested C. I am not sure whether adding other 
language support is necessary at this point.
- add clang test cases and a few more bpf backend tests.

But some early feedback will be great!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70625

Files:
  clang/include/clang/AST/ASTConsumer.h
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Basic/Targets/BPF.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/DebugInfo.cpp
  llvm/lib/Target/BPF/BTF.h
  llvm/lib/Target/BPF/BTFDebug.cpp
  llvm/lib/Target/BPF/BTFDebug.h
  llvm/test/CodeGen/BPF/BTF/extern-var-func.ll
  llvm/test/CodeGen/BPF/BTF/extern-var-section.ll
  llvm/test/CodeGen/BPF/BTF/extern-var-struct.ll
  llvm/unittests/Transforms/Utils/CloningTest.cpp

Index: llvm/unittests/Transforms/Utils/CloningTest.cpp
===
--- llvm/unittests/Transforms/Utils/CloningTest.cpp
+++ llvm/unittests/Transforms/Utils/CloningTest.cpp
@@ -764,7 +764,7 @@
 
 DBuilder.createGlobalVariableExpression(
 Subprogram, "unattached", "unattached", File, 1,
-DBuilder.createNullPtrType(), false, Expr);
+DBuilder.createNullPtrType(), false, true, Expr);
 
 auto *Entry = BasicBlock::Create(C, "", F);
 IBuilder.SetInsertPoint(Entry);
Index: llvm/test/CodeGen/BPF/BTF/extern-var-struct.ll
===
--- /dev/null
+++ llvm/test/CodeGen/BPF/BTF/extern-var-struct.ll
@@ -0,0 +1,101 @@
+; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
+; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
+;
+; Source code:
+;   typedef struct t1 { int f1; } __t1;
+;   int test() { return global.f1; }
+; Compilation flag:
+;   clang -target bpf -O2 -g -S -emit-llvm test.c
+
+%struct.t1 = type { i32 }
+
+@global = external dso_local local_unnamed_addr global %struct.t1, align 4, !dbg !0
+
+; Function Attrs: norecurse nounwind readonly
+define dso_local i32 @test() local_unnamed_addr #0 !dbg !15 {
+entry:
+  %0 = load i32, i32* getelementptr inbounds (%struct.t1, %struct.t1* @global, i64 0, i32 0), align 4, !dbg !18, !tbaa !19
+  ret i32 %0, !dbg !24
+}
+
+; CHECK: .section.BTF,"",@progbits
+; CHECK-NEXT:.short  60319   # 0xeb9f
+; CHECK-NEXT:.byte   1
+; CHECK-NEXT:.byte   0
+; CHECK-NEXT:.long   24
+; CHECK-NEXT:.long   0
+; CHECK-NEXT:.long   92
+; CHECK-NEXT:.long   92
+; CHECK-NEXT:.long   73
+; CHECK-NEXT:.long   0   # BTF_KIND_FUNC_PROTO(id = 1)
+; CHECK-NEXT:.long   218103808   # 0xd00
+; CHECK-NEXT:.long   2
+; CHECK-NEXT:.long   1   # BTF_KIND_INT(id = 2)
+; CHECK-NEXT:.long   16777216# 0x100
+; CHECK-NEXT:.long   4
+; CHECK-NEXT:.long   16777248# 0x120
+; CHECK-NEXT:.long   5   # BTF_KIND_FUNC(id = 3)
+; CHECK-NEXT:.long   201326592   # 0xc00
+; CHECK-NEXT:.long   1
+; CHECK-NEXT:.long   55  # BTF_KIND_TYPEDEF(id = 4)
+; CHECK-NEXT: