[PATCH] D69393: [RFC][DebugInfo] emit user specified address_space in dwarf

Yonghong Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 24 09:58:03 PDT 2019


yonghong-song created this revision.
yonghong-song added reviewers: arsenm, aprantl, Anastasia, ast.
yonghong-song added a project: debug-info.
Herald added subscribers: cfe-commits, wdng.
Herald added a project: clang.

The RFC intends to kick off the discussion on how to support
user defined address_space attributes in dwarf.

The use case:
=============

In linux kernel, under certain make flags, pointers may be
annotated with additional address_space information. The source
code is below:

  https://github.com/torvalds/linux/blob/master/include/linux/compiler_types.h

For example, we have

1. define __user               __attribute__((noderef, address_space(1)))
2. define __kernel     __attribute__((address_space(0)))
3. define __iomem      __attribute__((noderef, address_space(2)))
4. define __percpu     __attribute__((noderef, address_space(3)))
5. define __rcu                __attribute__((noderef, address_space(4)))

Currently, the address_space annotation is not used when compiling
a normal (production) kernel. It is typically used during development
and used by 'sparse' tool to check proper pointer usage.

Now there is a growing need to put address_space info into debug info,
e.g., dwarf, in linux binary to help automatically differentiate
pointers accessing kernel and user memories in order to avoid
explicit user annotations like below:

  http://lkml.iu.edu/hypermail/linux/kernel/1905.1/05750.html

Other tracing tools like bpftrace, bcc would have similar issues.

The current patch
=================

The proposal here is for user specified address_space, just add it
to DebugInfo and then later it will be automatically inserted into
dwarf. For example,

  -bash-4.4$ cat t.c
  #define __user __attribute__((noderef, address_space(3)))
  void __user *g;
  extern int __user *foo(int *a, int __user *b);
  int __user *foo(int *a, int __user *b) { return b; }
  -bash-4.4$ clang -O2 -g -c t.c
  -bash-4.4$ llvm-dwarfdump t.o
  ...
  0x0000002a:   DW_TAG_variable
                DW_AT_name      ("g")
                DW_AT_type      (0x00000042 "*")
  0x00000042:   DW_TAG_pointer_type
                DW_AT_address_class     (0x00000003)
  0x00000060:     DW_TAG_formal_parameter
                  DW_AT_name    ("a")
                  DW_AT_type    (0x00000091 "int*")
  0x00000071:     DW_TAG_formal_parameter
                  DW_AT_name    ("b")
                  DW_AT_type    (0x00000081 "int*")
  0x00000081:   DW_TAG_pointer_type
                DW_AT_type      (0x0000008a "int")
                DW_AT_address_class     (0x00000003)
  0x00000091:   DW_TAG_pointer_type
                DW_AT_type      (0x0000008a "int")
                DW_AT_address_class     (0x00000000)

This patch mixed language address space and user defined address space
in the same debuginfo address_space and in the dwarf final encoding,
it is encoded as address_class which is more tailored into
language address_space.

Question:
=========

This patch probably won't work as it mixed language address_space
and user address_space.

How we should proceed from here? Separate field in
IR DebugInfo and Dwarf for user defined address_space?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69393

Files:
  clang/lib/Basic/Targets/BPF.h
  clang/lib/Basic/Targets/X86.h


Index: clang/lib/Basic/Targets/X86.h
===================================================================
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -257,6 +257,11 @@
     setFeatureEnabledImpl(Features, Name, Enabled);
   }
 
+  Optional<unsigned>
+  getDWARFAddressSpace(unsigned AddressSpace) const override {
+    return AddressSpace;
+  }
+
   // This exists purely to cut down on the number of virtual calls in
   // initFeatureMap which calls this repeatedly.
   static void setFeatureEnabledImpl(llvm::StringMap<bool> &Features,
Index: clang/lib/Basic/Targets/BPF.h
===================================================================
--- clang/lib/Basic/Targets/BPF.h
+++ clang/lib/Basic/Targets/BPF.h
@@ -58,6 +58,11 @@
 
   ArrayRef<Builtin::Info> getTargetBuiltins() const override;
 
+  Optional<unsigned>
+  getDWARFAddressSpace(unsigned AddressSpace) const override {
+    return AddressSpace;
+  }
+
   const char *getClobbers() const override { return ""; }
 
   BuiltinVaListKind getBuiltinVaListKind() const override {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69393.226281.patch
Type: text/x-patch
Size: 1064 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191024/f55e92e0/attachment.bin>


More information about the cfe-commits mailing list