[llvm] [dsymutil] collect pseudoprobe sections from debug map into __LLVM segment (PR #206817)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 7 23:57:45 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-debuginfo

Author: Henry Jiang (mustartt)

<details>
<summary>Changes</summary>

Introduce a new `PseudoProbeLinker` in `dsymutil` that collects `__probes/__probe_descs` sections from the debug map objects and merges the sections under the `__LLVM` segment and places the probes metadata under `ResourceDir` i.e. `Contents/Resources/Profiling/pseudo_probes[-<arch>]`.

Dependent on the revert commit: https://github.com/llvm/llvm-project/pull/206789


---

Patch is 48.33 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/206817.diff


7 Files Affected:

- (added) llvm/test/tools/dsymutil/AArch64/pseudo-probe-universal.test (+439) 
- (modified) llvm/test/tools/dsymutil/AArch64/pseudo-probe.test (+283-236) 
- (modified) llvm/tools/dsymutil/CMakeLists.txt (+1) 
- (modified) llvm/tools/dsymutil/MachOUtils.cpp (+7-65) 
- (added) llvm/tools/dsymutil/PseudoProbeLinker.cpp (+184) 
- (added) llvm/tools/dsymutil/PseudoProbeLinker.h (+55) 
- (modified) llvm/tools/dsymutil/dsymutil.cpp (+5) 


``````````diff
diff --git a/llvm/test/tools/dsymutil/AArch64/pseudo-probe-universal.test b/llvm/test/tools/dsymutil/AArch64/pseudo-probe-universal.test
new file mode 100644
index 0000000000000..6ff9caadf3449
--- /dev/null
+++ b/llvm/test/tools/dsymutil/AArch64/pseudo-probe-universal.test
@@ -0,0 +1,439 @@
+# REQUIRES: aarch64-registered-target
+# REQUIRES: host-byteorder-little-endian
+
+# RUN: rm -rf %t && split-file %s %t
+# RUN: yaml2obj %t/fat.dylib.yaml -o %t/fat.dylib
+# RUN: yaml2obj %t/a.o.yaml -o %t/a.o
+# RUN: yaml2obj %t/e.o.yaml -o %t/e.o
+
+# RUN: dsymutil --linker classic --no-object-timestamp %t/fat.dylib -oso-prepend-path=%t -o %t/classic.dSYM
+# RUN: llvm-readobj --file-headers --sections %t/classic.dSYM/Contents/Resources/Profiling/pseudo_probes-arm64 \
+# RUN:    | FileCheck %s --check-prefix=ARM64
+# RUN: llvm-readobj --file-headers --sections %t/classic.dSYM/Contents/Resources/Profiling/pseudo_probes-arm64e \
+# RUN:    | FileCheck %s --check-prefix=ARM64E
+# RUN: llvm-objdump -s --section=__probes --section=__probe_descs %t/classic.dSYM/Contents/Resources/Profiling/pseudo_probes-arm64 \
+# RUN:    | FileCheck %s --check-prefix=DATA
+
+# RUN: dsymutil --linker parallel --no-object-timestamp %t/fat.dylib -oso-prepend-path=%t -o %t/parallel.dSYM
+# RUN: llvm-readobj --file-headers --sections %t/parallel.dSYM/Contents/Resources/Profiling/pseudo_probes-arm64 \
+# RUN:    | FileCheck %s --check-prefix=ARM64
+# RUN: llvm-readobj --file-headers --sections %t/parallel.dSYM/Contents/Resources/Profiling/pseudo_probes-arm64e \
+# RUN:    | FileCheck %s --check-prefix=ARM64E
+# RUN: llvm-objdump -s --section=__probes --section=__probe_descs %t/parallel.dSYM/Contents/Resources/Profiling/pseudo_probes-arm64 \
+# RUN:    | FileCheck %s --check-prefix=DATA
+
+# ARM64:      CpuType: Arm64
+# ARM64:      CpuSubType: CPU_SUBTYPE_ARM64_ALL
+# ARM64:      Name: __probes
+# ARM64-NEXT: Segment: __LLVM
+# ARM64-NEXT: Address: 0x0
+# ARM64-NEXT: Size: 0x3C
+# ARM64-NEXT: Offset: 368
+# ARM64:      Name: __probe_descs
+# ARM64-NEXT: Segment: __LLVM
+# ARM64-NEXT: Address: 0x3C
+# ARM64-NEXT: Size: 0x27
+# ARM64-NEXT: Offset: 428
+
+# ARM64E:      CpuType: Arm64
+# ARM64E:      CpuSubType: CPU_SUBTYPE_ARM64E
+# ARM64E:      Name: __probes
+# ARM64E-NEXT: Segment: __LLVM
+# ARM64E-NEXT: Address: 0x0
+# ARM64E-NEXT: Size: 0x3C
+# ARM64E-NEXT: Offset: 368
+# ARM64E:      Name: __probe_descs
+# ARM64E-NEXT: Segment: __LLVM
+# ARM64E-NEXT: Address: 0x3C
+# ARM64E-NEXT: Size: 0x27
+# ARM64E-NEXT: Offset: 428
+
+# DATA:      Contents of section __LLVM,__probes:
+# DATA-NEXT: 0000 fad58de7 366495db
+# DATA:      Contents of section __LLVM,__probe_descs:
+# DATA-NEXT: 003c 8fa14cdd 754f91cc
+# DATA:      046d 61696e
+
+
+#--- fat.dylib.yaml
+--- !fat-mach-o
+FatHeader:
+  magic:           0xCAFEBABE
+  nfat_arch:       2
+FatArchs:
+  - cputype:         0x100000C
+    cpusubtype:      0x0
+    offset:          0x4000
+    size:            181
+    align:           14
+  - cputype:         0x100000C
+    cpusubtype:      0x2
+    offset:          0x8000
+    size:            181
+    align:           14
+Slices:
+  - !mach-o
+    FileHeader:
+      magic:           0xFEEDFACF
+      cputype:         0x100000C
+      cpusubtype:      0x0
+      filetype:        0x6
+      ncmds:           3
+      sizeofcmds:      128
+      flags:           0x100085
+      reserved:        0x0
+    LoadCommands:
+      - cmd:             LC_SEGMENT_64
+        cmdsize:         72
+        segname:         __LINKEDIT
+        vmaddr:          16384
+        vmsize:          4096
+        fileoff:         160
+        filesize:        21
+        maxprot:         1
+        initprot:        1
+        nsects:          0
+        flags:           0
+      - cmd:             LC_ID_DYLIB
+        cmdsize:         32
+        dylib:
+          name:            24
+          timestamp:       0
+          current_version: 0
+          compatibility_version: 0
+        Content:         probe
+        ZeroPadBytes:    3
+      - cmd:             LC_SYMTAB
+        cmdsize:         24
+        symoff:          160
+        nsyms:           1
+        stroff:          176
+        strsize:         5
+    LinkEditData:
+      NameList:
+        - n_strx:          1
+          n_type:          0x66
+          n_sect:          0
+          n_desc:          1
+          n_value:         0
+      StringTable:
+        - ''
+        - a.o
+  - !mach-o
+    FileHeader:
+      magic:           0xFEEDFACF
+      cputype:         0x100000C
+      cpusubtype:      0x2
+      filetype:        0x6
+      ncmds:           3
+      sizeofcmds:      128
+      flags:           0x100085
+      reserved:        0x0
+    LoadCommands:
+      - cmd:             LC_SEGMENT_64
+        cmdsize:         72
+        segname:         __LINKEDIT
+        vmaddr:          16384
+        vmsize:          4096
+        fileoff:         160
+        filesize:        21
+        maxprot:         1
+        initprot:        1
+        nsects:          0
+        flags:           0
+      - cmd:             LC_ID_DYLIB
+        cmdsize:         32
+        dylib:
+          name:            24
+          timestamp:       0
+          current_version: 0
+          compatibility_version: 0
+        Content:         probe
+        ZeroPadBytes:    3
+      - cmd:             LC_SYMTAB
+        cmdsize:         24
+        symoff:          160
+        nsyms:           1
+        stroff:          176
+        strsize:         5
+    LinkEditData:
+      NameList:
+        - n_strx:          1
+          n_type:          0x66
+          n_sect:          0
+          n_desc:          1
+          n_value:         0
+      StringTable:
+        - ''
+        - e.o
+...
+
+#--- a.o.yaml
+--- !mach-o
+FileHeader:
+  magic:           0xFEEDFACF
+  cputype:         0x100000C
+  cpusubtype:      0x0
+  filetype:        0x1
+  ncmds:           4
+  sizeofcmds:      440
+  flags:           0x2000
+  reserved:        0x0
+LoadCommands:
+  - cmd:             LC_SEGMENT_64
+    cmdsize:         312
+    segname:         ''
+    vmaddr:          0
+    vmsize:          813
+    fileoff:         472
+    filesize:        115
+    maxprot:         7
+    initprot:        7
+    nsects:          3
+    flags:           0
+    Sections:
+      - sectname:        __text
+        segname:         __TEXT
+        addr:            0x0
+        size:            16
+        offset:          0x1D8
+        align:           2
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x80000400
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         00040011C0035FD640008052C0035FD6
+      - sectname:        __probe_descs
+        segname:         __PSEUDO_PROBE
+        addr:            0x10
+        size:            39
+        offset:          0x1E8
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x12000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         8FA14CDD754F91CCFFFFFFFF000000000166FAD58DE7366495DBFFFFFFFF00000100046D61696E
+      - sectname:        __probes
+        segname:         __PSEUDO_PROBE
+        addr:            0x2F1
+        size:            60
+        offset:          0x20F
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x12000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         FAD58DE7366495DB0201002001411FAE90F57226018000028FA14CDD754F91CC01000180008FA14CDD754F91CC02000020E99036E91302D08B018000
+  - cmd:             LC_BUILD_VERSION
+    cmdsize:         24
+    platform:        1
+    minos:           1703936
+    sdk:             1704960
+    ntools:          0
+  - cmd:             LC_SYMTAB
+    cmdsize:         24
+    symoff:          587
+    nsyms:           5
+    stroff:          667
+    strsize:         32
+  - cmd:             LC_DYSYMTAB
+    cmdsize:         80
+    ilocalsym:       0
+    nlocalsym:       3
+    iextdefsym:      3
+    nextdefsym:      2
+    iundefsym:       5
+    nundefsym:       0
+    tocoff:          0
+    ntoc:            0
+    modtaboff:       0
+    nmodtab:         0
+    extrefsymoff:    0
+    nextrefsyms:     0
+    indirectsymoff:  0
+    nindirectsyms:   0
+    extreloff:       0
+    nextrel:         0
+    locreloff:       0
+    nlocrel:         0
+LinkEditData:
+  NameList:
+    - n_strx:          22
+      n_type:          0xE
+      n_sect:          1
+      n_desc:          0
+      n_value:         0
+    - n_strx:          16
+      n_type:          0xE
+      n_sect:          2
+      n_desc:          0
+      n_value:         16
+    - n_strx:          10
+      n_type:          0xE
+      n_sect:          3
+      n_desc:          0
+      n_value:         753
+    - n_strx:          7
+      n_type:          0xF
+      n_sect:          1
+      n_desc:          0
+      n_value:         0
+    - n_strx:          1
+      n_type:          0xF
+      n_sect:          1
+      n_desc:          0
+      n_value:         8
+  StringTable:
+    - ''
+    - _main
+    - _f
+    - ltmp2
+    - ltmp1
+    - ltmp0
+    - ''
+    - ''
+    - ''
+    - ''
+...
+
+#--- e.o.yaml
+--- !mach-o
+FileHeader:
+  magic:           0xFEEDFACF
+  cputype:         0x100000C
+  cpusubtype:      0x80000002
+  filetype:        0x1
+  ncmds:           4
+  sizeofcmds:      440
+  flags:           0x2000
+  reserved:        0x0
+LoadCommands:
+  - cmd:             LC_SEGMENT_64
+    cmdsize:         312
+    segname:         ''
+    vmaddr:          0
+    vmsize:          813
+    fileoff:         472
+    filesize:        115
+    maxprot:         7
+    initprot:        7
+    nsects:          3
+    flags:           0
+    Sections:
+      - sectname:        __text
+        segname:         __TEXT
+        addr:            0x0
+        size:            16
+        offset:          0x1D8
+        align:           2
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x80000400
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         00040011C0035FD640008052C0035FD6
+      - sectname:        __probe_descs
+        segname:         __PSEUDO_PROBE
+        addr:            0x10
+        size:            39
+        offset:          0x1E8
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x12000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         8FA14CDD754F91CCFFFFFFFF000000000166FAD58DE7366495DBFFFFFFFF00000100046D61696E
+      - sectname:        __probes
+        segname:         __PSEUDO_PROBE
+        addr:            0x2F1
+        size:            60
+        offset:          0x20F
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x12000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         FAD58DE7366495DB0201002001411FAE90F57226018000028FA14CDD754F91CC01000180008FA14CDD754F91CC02000020E99036E91302D08B018000
+  - cmd:             LC_BUILD_VERSION
+    cmdsize:         24
+    platform:        1
+    minos:           1703936
+    sdk:             1704960
+    ntools:          0
+  - cmd:             LC_SYMTAB
+    cmdsize:         24
+    symoff:          587
+    nsyms:           5
+    stroff:          667
+    strsize:         32
+  - cmd:             LC_DYSYMTAB
+    cmdsize:         80
+    ilocalsym:       0
+    nlocalsym:       3
+    iextdefsym:      3
+    nextdefsym:      2
+    iundefsym:       5
+    nundefsym:       0
+    tocoff:          0
+    ntoc:            0
+    modtaboff:       0
+    nmodtab:         0
+    extrefsymoff:    0
+    nextrefsyms:     0
+    indirectsymoff:  0
+    nindirectsyms:   0
+    extreloff:       0
+    nextrel:         0
+    locreloff:       0
+    nlocrel:         0
+LinkEditData:
+  NameList:
+    - n_strx:          22
+      n_type:          0xE
+      n_sect:          1
+      n_desc:          0
+      n_value:         0
+    - n_strx:          16
+      n_type:          0xE
+      n_sect:          2
+      n_desc:          0
+      n_value:         16
+    - n_strx:          10
+      n_type:          0xE
+      n_sect:          3
+      n_desc:          0
+      n_value:         753
+    - n_strx:          7
+      n_type:          0xF
+      n_sect:          1
+      n_desc:          0
+      n_value:         0
+    - n_strx:          1
+      n_type:          0xF
+      n_sect:          1
+      n_desc:          0
+      n_value:         8
+  StringTable:
+    - ''
+    - _main
+    - _f
+    - ltmp2
+    - ltmp1
+    - ltmp0
+    - ''
+    - ''
+    - ''
+    - ''
+...
diff --git a/llvm/test/tools/dsymutil/AArch64/pseudo-probe.test b/llvm/test/tools/dsymutil/AArch64/pseudo-probe.test
index 0bc97eb574eae..bf676af963c81 100644
--- a/llvm/test/tools/dsymutil/AArch64/pseudo-probe.test
+++ b/llvm/test/tools/dsymutil/AArch64/pseudo-probe.test
@@ -1,65 +1,85 @@
-## Test that dsymutil correctly copies pseudoprobe sections and segments
-
-# https://github.com/llvm/llvm-project/issues/190481
+# REQUIRES: aarch64-registered-target
 # REQUIRES: host-byteorder-little-endian
 
-# RUN: rm -rf %t && mkdir -p %t
-# RUN: yaml2obj %s -o %t/main.o
-# RUN: dsymutil --linker classic %t/main.o -o %t/main.dSYM
-# RUN: obj2yaml %t/main.dSYM/Contents/Resources/DWARF/main.o -o %t/out.yaml
-# RUN: FileCheck %s < %t/out.yaml
-# RUN: dsymutil --linker parallel %t/main.o -o %t/main.dSYM
-# RUN: obj2yaml %t/main.dSYM/Contents/Resources/DWARF/main.o -o %t/out.yaml
-# RUN: FileCheck %s < %t/out.yaml
+# RUN: rm -rf %t
+# RUN: split-file %s %t
+# RUN: mkdir -p %t
+# RUN: yaml2obj %t/a.yaml -o %t/a.o
+# RUN: yaml2obj %t/b.yaml -o %t/b.o
+
+# RUN: dsymutil --linker classic -y %t/debug.map -oso-prepend-path=%t -o %t/classic.dSYM
+# RUN: llvm-objdump --section-headers %t/classic.dSYM/Contents/Resources/Profiling/pseudo_probes \
+# RUN:    | FileCheck %s --check-prefix=SIZE
+# RUN: llvm-readobj --sections %t/classic.dSYM/Contents/Resources/Profiling/pseudo_probes \
+# RUN:    | FileCheck %s --check-prefix=SEG
+# RUN: llvm-objdump -s --section=__probes --section=__probe_descs \
+# RUN:    %t/classic.dSYM/Contents/Resources/Profiling/pseudo_probes | FileCheck %s --check-prefix=DATA
+
+# RUN: dsymutil --linker parallel -y %t/debug.map -oso-prepend-path=%t -o %t/parallel.dSYM
+# RUN: llvm-objdump --section-headers %t/parallel.dSYM/Contents/Resources/Profiling/pseudo_probes \
+# RUN:    | FileCheck %s --check-prefix=SIZE
+# RUN: llvm-readobj --sections %t/parallel.dSYM/Contents/Resources/Profiling/pseudo_probes \
+# RUN:    | FileCheck %s --check-prefix=SEG
+# RUN: llvm-objdump -s --section=__probes --section=__probe_descs \
+# RUN:    %t/parallel.dSYM/Contents/Resources/Profiling/pseudo_probes | FileCheck %s --check-prefix=DATA
+
+# SEG:      Name: __probes
+# SEG-NEXT: Segment: __LLVM
+# SEG:      Name: __probe_descs
+# SEG-NEXT: Segment: __LLVM
 
-# CHECK:        segname:         __PSEUDO_PROBE
-# CHECK:        Sections:
-# CHECK-NEXT:     - sectname:        __probe_descs
-# CHECK-NEXT:       segname:         __PSEUDO_PROBE
-# CHECK:            content:         ACBD18DB4CC2F85CFFFFFFFF0000000003666F6F37B51D194A7513E4FFFFFFFF000000000362617273FEFFA4B7F6BB68FFFFFFFF000002000362617AFAD58DE7366495DBFFFFFFFF00000100046D61696E
-# CHECK-NEXT:     - sectname:        __probes
-# CHECK-NEXT:       segname:         __PSEUDO_PROBE
-# CHECK:            content:         37B51D194A7513E402000020A9A7418A5E3E02B5018000FAD58DE7366495DB0200002001411FAE90F5722601800073FEFFA4B7F6BB6802000020DEDF76EC3AE9F50501800037B51D194A7513E402000020DEDF76EC3AE9F505018000ACBD18DB4CC2F85C020000208774C18D504B6E28018000
+# SIZE: __probes      00000040
+# SIZE: __probe_descs 00000024
+
+# DATA:      Contents of section __LLVM,__probes:
+# DATA-NEXT: {{[0-9a-f]+}} 0cc175b9 c0f1b6a8 05000020 5c855e09
+# DATA-NEXT: {{[0-9a-f]+}} 4bdf284e 01800c02 80140380 0c048008
+# DATA-NEXT: {{[0-9a-f]+}} 92eb5ffe e6ae2fec 05000020 c716fb29
+# DATA-NEXT: {{[0-9a-f]+}} 298ad96a 01800c02 80140380 0c048008
+# DATA:      Contents of section __LLVM,__probe_descs:
+# DATA-NEXT: {{[0-9a-f]+}} 0cc175b9 c0f1b6a8 94da52e8 10000000
+# DATA-NEXT: {{[0-9a-f]+}} 016192eb 5ffee6ae 2fec94da 52e81000
+# DATA-NEXT: {{[0-9a-f]+}} 00000162
+
+#--- debug.map
+---
+triple:          'arm64-apple-darwin'
+objects:
+  - filename: a.o
+    symbols:         []
+  - filename: b.o
+    symbols:         []
+...
 
+#--- a.yaml
 --- !mach-o
 FileHeader:
   magic:           0xFEEDFACF
   cputype:         0x100000C
   cpusubtype:      0x0
-  filetype:        0x2
-  ncmds:           17
-  sizeofcmds:      976
-  flags:           0x200085
+  filetype:        0x1
+  ncmds:           4
+  sizeofcmds:      520
+  flags:           0x2000
   reserved:        0x0
 LoadCommands:
   - cmd:             LC_SEGMENT_64
-    cmdsize:         72
-    segname:         __PAGEZERO
+    cmdsize:         392
+    segname:         ''
     vmaddr:          0
-    vmsize:          4294967296
-    fileoff:         0
-    filesize:        0
-    maxprot:         0
-    initprot:        0
-    nsects:          0
-    flags:           0
-  - cmd:             LC_SEGMENT_64
-    cmdsize:         232
-    segname:         __TEXT
-    vmaddr:          4294967296
-    vmsize:          16384
-    fileoff:         0
-    filesize:        16384
-    maxprot:         5
-    initprot:        5
-    nsects:          2
+    vmsize:          144
+    fileoff:         552
+    filesize:        144
+    maxprot:         7
+    initprot:        7
+    nsects:          4
     flags:           0
     Sections:
       - sectname:        __text
         segname:         __TEXT
-        addr:            0x100000410
-        size:            20
-        offset:          0x410
+        addr:            0x0
+        size:            60
+        offset:          0x228
         align:           2
         reloff:          0x0
         nreloc:          0
@@ -67,89 +87,230 @@ LoadCommands:
         reserved1:       0x0
         reserved2:       0x0
         reserved3:       0x0
-        content:         C0035FD6C0035FD6C0035FD600008052C0035FD6
-      - sectname:        __unwind_info
-        segname:         __TEXT
-        addr:            0x100000424
-        size:            88
-        offset:          0x424
-        align:           2
+        content:         FF4300D1E00B00B9E80B40B9C800003401000014E80B40B908050011E80F00B90400001408008052E80F00B901000014E00F40B9FF430091C0035FD6
+      - sectname:        __probe_descs
+        segname:         __LLVM
+        addr:            0x3C
+        size:            18
+        offset:          0x264
+        align:           0
         reloff:          0x0
         nreloc:          0
-        flags:           0x0
+        flags:           0x12000000
         reserved1:       0x0
         reserved2:       0x0
         reserved3:       0x0
-        content:         010000001C000000000000001C000000000000001C00000002000000100400004000000040000000250400000000000040000000000000000000000000000000030000000C00010010000100000000000000000200000000
+        content:         0CC175B9C0F1B6A894DA52E8100000000161
+      - sectname:        __compact_unwind
+        segname:         __LD
+        addr:            0x50
+        size:            32
+        offset:          0x278
+        align:           3
+        reloff:          0x2B8
+        nreloc:          1
+        flags:           0x2000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         00000000000000003C0000000010000200000000000000000000000000000000
+        relocations:
+          - address:         0x0
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+      - sectname:        __probes
+        segname:         __LLVM
+        addr:       ...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/206817


More information about the llvm-commits mailing list