Skip to content

[llvm-gsymutil] Fix dumping of call sites for merged functions #119759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 13, 2024

Conversation

alx32
Copy link
Contributor

@alx32 alx32 commented Dec 12, 2024

Currently, when dumping the contents of a GSYM there are three issues:

  • Callsite information is not displayed for merged functions - this is because of a bug in CallSiteInfoLoader::buildFunctionMap where when enumerating through Func.MergedFunctions - we enumerate by value instead of by reference.
  • There is no variable indent for printing callsite info - meaning that when printing callsites for merged functions, the indent will be different than the other info of the merged function. To address this we add configurable indent for printing callsite info
  • Callsite info is printed right after merged function info. Meaning that if the merged function also has call site information, the parent's callsite info will appear right after the merged function's callsite info - leading to confusion. To address this we print the callsite info first, then the merged functions info.

This change addresses all the above 3 issues.
Example of old vs new:

image

@alx32 alx32 force-pushed the 04_gsymutil_callsite_align branch from 1b8b974 to 1aa9dea Compare December 12, 2024 22:14
@llvm llvm deleted a comment from github-actions bot Dec 12, 2024
@alx32 alx32 changed the title [llvm-gsymutil] Improve dumping of call sites for merged functions [llvm-gsymutil] Fix dumping of call sites for merged functions Dec 13, 2024
@alx32 alx32 force-pushed the 04_gsymutil_callsite_align branch from 1aa9dea to cd9e6f0 Compare December 13, 2024 01:42
@alx32 alx32 force-pushed the 04_gsymutil_callsite_align branch from cd9e6f0 to 1961138 Compare December 13, 2024 01:43
@alx32 alx32 marked this pull request as ready for review December 13, 2024 01:46
@llvmbot
Copy link
Member

llvmbot commented Dec 13, 2024

@llvm/pr-subscribers-debuginfo

Author: None (alx32)

Changes

Currently, when dumping the contents of a GSYM there are three issues:

  • Callsite information is not displayed for merged functions - this is because of a bug in CallSiteInfoLoader::buildFunctionMap where when enumerating through Func.MergedFunctions - we enumerate by value instead of by reference.
  • There is no variable indent for printing callsite info - meaning that when printing callsites for merged functions, the indent will be different than the other info of the merged function. To address this we add configurable indent for printing callsite info
  • Callsite info is printed right after merged function info. Meaning that if the merged function also has call site information, the parent's callsite info will appear right after the merged function's callsite info - leading to confusion. To address this we print the callsite info first, then the merged functions info.

This change addresses all the above 3 issues.
Example of old vs new:

<img width="1074" alt="image" src="https://github.com/user-attachments/assets/d039ad69-fa79-4abb-9816-eda9cc2eda53" />


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

4 Files Affected:

  • (modified) llvm/include/llvm/DebugInfo/GSYM/GsymReader.h (+5-1)
  • (modified) llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp (+1-1)
  • (modified) llvm/lib/DebugInfo/GSYM/GsymReader.cpp (+8-5)
  • (added) llvm/test/tools/llvm-gsymutil/ARM_AArch64/macho-gsym-merged-callsites-dsym.yaml (+1525)
diff --git a/llvm/include/llvm/DebugInfo/GSYM/GsymReader.h b/llvm/include/llvm/DebugInfo/GSYM/GsymReader.h
index 72b7f3e7bfc42e..3d532588a70234 100644
--- a/llvm/include/llvm/DebugInfo/GSYM/GsymReader.h
+++ b/llvm/include/llvm/DebugInfo/GSYM/GsymReader.h
@@ -199,7 +199,11 @@ class GsymReader {
   /// \param OS The output stream to dump to.
   ///
   /// \param CSIC The CallSiteInfoCollection object to dump.
-  void dump(raw_ostream &OS, const CallSiteInfoCollection &CSIC);
+  ///
+  /// \param Indent The indentation as number of spaces. Used when dumping as an
+  /// item from within MergedFunctionsInfo.
+  void dump(raw_ostream &OS, const CallSiteInfoCollection &CSIC,
+            uint32_t Indent = 0);
 
   /// Dump a LineTable object.
   ///
diff --git a/llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp b/llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp
index cf4c64e5e85ca6..85b41e28991316 100644
--- a/llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp
+++ b/llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp
@@ -181,7 +181,7 @@ StringMap<FunctionInfo *> CallSiteInfoLoader::buildFunctionMap() {
   StringMap<FunctionInfo *> FuncMap;
   for (auto &Func : Funcs) {
     FuncMap.try_emplace(GCreator.getString(Func.Name), &Func);
-    if (auto MFuncs = Func.MergedFunctions)
+    if (auto &MFuncs = Func.MergedFunctions)
       for (auto &MFunc : MFuncs->MergedFunctions)
         FuncMap.try_emplace(GCreator.getString(MFunc.Name), &MFunc);
   }
diff --git a/llvm/lib/DebugInfo/GSYM/GsymReader.cpp b/llvm/lib/DebugInfo/GSYM/GsymReader.cpp
index 7979f1f5d51928..fa5476db191ec4 100644
--- a/llvm/lib/DebugInfo/GSYM/GsymReader.cpp
+++ b/llvm/lib/DebugInfo/GSYM/GsymReader.cpp
@@ -406,13 +406,13 @@ void GsymReader::dump(raw_ostream &OS, const FunctionInfo &FI,
   if (FI.Inline)
     dump(OS, *FI.Inline, Indent);
 
+  if (FI.CallSites)
+    dump(OS, *FI.CallSites, Indent);
+
   if (FI.MergedFunctions) {
     assert(Indent == 0 && "MergedFunctionsInfo should only exist at top level");
     dump(OS, *FI.MergedFunctions);
   }
-
-  if (FI.CallSites)
-    dump(OS, *FI.CallSites);
 }
 
 void GsymReader::dump(raw_ostream &OS, const MergedFunctionsInfo &MFI) {
@@ -454,10 +454,13 @@ void GsymReader::dump(raw_ostream &OS, const CallSiteInfo &CSI) {
   }
 }
 
-void GsymReader::dump(raw_ostream &OS, const CallSiteInfoCollection &CSIC) {
+void GsymReader::dump(raw_ostream &OS, const CallSiteInfoCollection &CSIC,
+                      uint32_t Indent) {
+  OS.indent(Indent);
   OS << "CallSites (by relative return offset):\n";
   for (const auto &CS : CSIC.CallSites) {
-    OS.indent(2);
+    OS.indent(Indent);
+    OS << "  ";
     dump(OS, CS);
     OS << "\n";
   }
diff --git a/llvm/test/tools/llvm-gsymutil/ARM_AArch64/macho-gsym-merged-callsites-dsym.yaml b/llvm/test/tools/llvm-gsymutil/ARM_AArch64/macho-gsym-merged-callsites-dsym.yaml
new file mode 100644
index 00000000000000..2b4d09c99a0d09
--- /dev/null
+++ b/llvm/test/tools/llvm-gsymutil/ARM_AArch64/macho-gsym-merged-callsites-dsym.yaml
@@ -0,0 +1,1525 @@
+## Test that reconstructs a dSYM file from YAML and generates a gsym from it. The gsym has callsite info and merged functions.
+
+# RUN: split-file %s %t
+# RUN: yaml2obj %t/merged_callsites.dSYM.yaml -o %t/merged_callsites.dSYM
+
+# RUN: llvm-gsymutil --convert=%t/merged_callsites.dSYM --merged-functions --callsites-yaml-file=%t/callsites.yaml -o %t/call_sites_dSYM.gsym
+
+# Dump the GSYM file and check the output for callsite information
+# RUN: llvm-gsymutil %t/call_sites_dSYM.gsym | FileCheck --check-prefix=CHECK-MERGED-CALLSITES %s
+
+# CHECK-MERGED-CALLSITES:      FunctionInfo @ 0x[[#%x,FUNC4_1:]]: [0x[[#%x,FUNC4_1_START:]] - 0x[[#%x,FUNC4_1_END:]]) "function4_copy1"
+# CHECK-MERGED-CALLSITES:      ++ Merged FunctionInfos[0]:
+# CHECK-MERGED-CALLSITES-NEXT:     [0x[[#%x,FUNC4_2_START:]] - 0x[[#%x,FUNC4_2_END:]]) "function4_copy2"
+ 
+# CHECK-MERGED-CALLSITES:      FunctionInfo @ 0x[[#%x,FUNC3_1:]]: [0x[[#%x,FUNC3_1_START:]] - 0x[[#%x,FUNC3_1_END:]]) "function3_copy1"
+# CHECK-MERGED-CALLSITES:      CallSites (by relative return offset):
+# CHECK-MERGED-CALLSITES-NEXT:   0x[[#%.4x,]] Flags[None] MatchRegex[function4_copy1]
+# CHECK-MERGED-CALLSITES:      ++ Merged FunctionInfos[0]:
+# CHECK-MERGED-CALLSITES-NEXT:     [0x[[#%x,FUNC3_2_START:]] - 0x[[#%x,FUNC3_2_END:]]) "function3_copy2"
+# CHECK-MERGED-CALLSITES:          CallSites (by relative return offset):
+# CHECK-MERGED-CALLSITES-NEXT:       0x[[#%.4x,]] Flags[None] MatchRegex[function4_copy2]
+ 
+# CHECK-MERGED-CALLSITES:      FunctionInfo @ 0x[[#%x,FUNC2_1:]]: [0x[[#%x,FUNC2_1_START:]] - 0x[[#%x,FUNC2_1_END:]]) "function2_copy1"
+# CHECK-MERGED-CALLSITES:      CallSites (by relative return offset):
+# CHECK-MERGED-CALLSITES-NEXT:   0x[[#%.4x,]] Flags[None] MatchRegex[function3_copy1]
+# CHECK-MERGED-CALLSITES:      ++ Merged FunctionInfos[0]:
+# CHECK-MERGED-CALLSITES-NEXT:     [0x[[#%x,FUNC2_2_START:]] - 0x[[#%x,FUNC2_2_END:]]) "function2_copy2"
+# CHECK-MERGED-CALLSITES:          CallSites (by relative return offset):
+# CHECK-MERGED-CALLSITES-NEXT:       0x[[#%.4x,]] Flags[None] MatchRegex[function3_copy1]
+ 
+# CHECK-MERGED-CALLSITES:      FunctionInfo @ 0x[[#%x,FUNC1:]]: [0x[[#%x,FUNC1_START:]] - 0x[[#%x,FUNC1_END:]]) "function1"
+# CHECK-MERGED-CALLSITES:      CallSites (by relative return offset):
+# CHECK-MERGED-CALLSITES-NEXT:   0x[[#%.4x,]] Flags[None] MatchRegex[function2_copy1]
+ 
+# CHECK-MERGED-CALLSITES:      FunctionInfo @ 0x[[#%x,MAIN:]]: [0x[[#%x,MAIN_START:]] - 0x[[#%x,MAIN_END:]]) "main"
+# CHECK-MERGED-CALLSITES:      CallSites (by relative return offset):
+# CHECK-MERGED-CALLSITES-NEXT:   0x[[#%.4x,]] Flags[None] MatchRegex[function1]
+# CHECK-MERGED-CALLSITES-NEXT:   0x[[#%.4x,]] Flags[None] MatchRegex[function2_copy2]
+# CHECK-MERGED-CALLSITES-NEXT:   0x[[#%.4x,]] Flags[None] MatchRegex[function4_copy2]
+# CHECK-MERGED-CALLSITES-NEXT:   0x[[#%.4x,]] Flags[None] MatchRegex[function3_copy2]
+# CHECK-MERGED-CALLSITES-NEXT:   0x[[#%.4x,]] Flags[None] MatchRegex[function2_copy1]
+
+
+#--- repro-script.sh
+#!/bin/bash
+set -ex
+
+# Set TOOLCHAIN_DIR to point to the llvm bin directory
+TOOLCHAIN_DIR="llvm-project/build/Debug/bin"  # Replace with the actual path to your LLVM bin directory
+SCRIPT_DIR="$(cd "$(dirname "$0")"; pwd)"
+OUT_DIR="$SCRIPT_DIR/out"
+cd $SCRIPT_DIR
+rm -rf "$OUT_DIR" && mkdir -p "$OUT_DIR"
+
+cat > "$OUT_DIR/merged_funcs_test.cpp" << EOF
+#define ATTRIB extern "C" __attribute__((noinline))
+volatile int global_result = 0;
+
+ATTRIB int function4_copy1(int a) {
+    int b = a * 4;
+    int result = b + 4;
+    global_result = result;
+    return result;
+}
+
+ATTRIB int function4_copy2(int a) {
+    int b = a * 4;
+    int result = b + 4;
+    global_result = result;
+    return result;
+}
+
+ATTRIB int function3_copy1(int a) {
+    int b = a + 3;
+    int result = function4_copy1(b);
+    global_result = result;
+    return result;
+}
+
+ATTRIB int function3_copy2(int a) {
+    int b = a + 3;
+    int result = function4_copy2(b);
+    global_result = result;
+    return result;
+}
+
+extern "C" inline int function_inlined(int a) {
+    int b = a + 3;
+    int result = function3_copy1(b);
+    global_result = result;
+    return result;
+}
+
+ATTRIB int function2_copy1(int a) {
+    int b = a - 2;
+    int result = function_inlined(b);
+    global_result = result;
+    return result;
+}
+
+ATTRIB int function2_copy2(int a) {
+    int b = a - 2;
+    int result = function_inlined(b);
+    global_result = result;
+    return result;
+}
+
+ATTRIB int function1(int a) {
+    int b = a + 1;
+    int result = function2_copy1(b);
+    global_result = result;
+    return result;
+}
+
+int main() {
+    int sum = 0;
+    sum += function1(1);
+    sum += function2_copy2(3);
+    sum += function4_copy2(4);
+    sum += function3_copy2(41);
+    sum += function2_copy1(11);
+    return sum;
+}
+EOF
+
+# Compile merged_funcs_test.cpp to merged_funcs_test.o with flags -g -O3 for MachO / arm64
+"$TOOLCHAIN_DIR/clang++" --target=arm64-apple-macos11 -c  -g -gdwarf-4 -fno-unwind-tables \
+    -mllvm -emit-func-debug-line-table-offsets -fno-exceptions -mno-outline \
+    -O3 "$OUT_DIR/merged_funcs_test.cpp" -o "$OUT_DIR/merged_funcs_test.o"
+
+# Link using ld64.lld directly with flags "--icf=all --keep-icf-stabs"
+"$TOOLCHAIN_DIR/ld64.lld" \
+    -arch arm64 \
+    -platform_version macos 11.0.0 11.0.0 \
+    -o "$OUT_DIR/merged_funcs_test.exe" \
+    "$OUT_DIR/merged_funcs_test.o" \
+    -dead_strip \
+    --icf=all \
+    --keep-icf-stabs
+
+# Create merged_funcs_test.dSYM from merged_funcs_test.exe
+"$TOOLCHAIN_DIR/dsymutil" --flat "$OUT_DIR/merged_funcs_test.exe" --verify-dwarf=none -o "$OUT_DIR/merged_funcs_test.dSYM"
+"$TOOLCHAIN_DIR/obj2yaml" "$OUT_DIR/merged_funcs_test.dSYM" -o "$OUT_DIR/merged_funcs_test.dSYM.yaml"
+
+
+
+
+#--- callsites.yaml
+functions:
+  - name: function3_copy1
+    callsites:
+      - return_offset: 0x10
+        match_regex: ["function4_copy1"]
+  - name: function3_copy2
+    callsites:
+      - return_offset: 0x10
+        match_regex: ["function4_copy2"]
+  - name: function2_copy1
+    callsites:
+      - return_offset: 0x10
+        match_regex: ["function3_copy1"]
+  - name: function2_copy2
+    callsites:
+      - return_offset: 0x10
+        match_regex: ["function3_copy1"]
+  - name: function1
+    callsites:
+      - return_offset: 0x10
+        match_regex: ["function2_copy1"]
+  - name: main
+    callsites:
+      - return_offset: 0x14
+        match_regex: ["function1"]
+      - return_offset: 0x20
+        match_regex: ["function2_copy2"]
+      - return_offset: 0x2c
+        match_regex: ["function4_copy2"]
+      - return_offset: 0x38
+        match_regex: ["function3_copy2"]
+      - return_offset: 0x48
+        match_regex: ["function2_copy1"]
+
+
+
+#--- merged_callsites.dSYM.yaml
+--- !mach-o
+FileHeader:
+  magic:           0xFEEDFACF
+  cputype:         0x100000C
+  cpusubtype:      0x0
+  filetype:        0xA
+  ncmds:           8
+  sizeofcmds:      1472
+  flags:           0x0
+  reserved:        0x0
+LoadCommands:
+  - cmd:             LC_UUID
+    cmdsize:         24
+    uuid:            4C4C442F-5555-3144-A1E4-99C5508F990D
+  - cmd:             LC_BUILD_VERSION
+    cmdsize:         24
+    platform:        1
+    minos:           720896
+    sdk:             720896
+    ntools:          0
+  - cmd:             LC_SYMTAB
+    cmdsize:         24
+    symoff:          4096
+    nsyms:           10
+    stroff:          4256
+    strsize:         156
+  - cmd:             LC_SEGMENT_64
+    cmdsize:         72
+    segname:         __PAGEZERO
+    vmaddr:          0
+    vmsize:          4294967296
+    fileoff:         0
+    filesize:        0
+    maxprot:         0
+    initprot:        0
+    nsects:          0
+    flags:           0
+  - cmd:             LC_SEGMENT_64
+    cmdsize:         152
+    segname:         __TEXT
+    vmaddr:          4294967296
+    vmsize:          16384
+    fileoff:         0
+    filesize:        0
+    maxprot:         5
+    initprot:        5
+    nsects:          1
+    flags:           0
+    Sections:
+      - sectname:        __text
+        segname:         __TEXT
+        addr:            0x100000338
+        size:            208
+        offset:          0x0
+        align:           2
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x80000400
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         CFFAEDFE0C000001000000000A00000008000000C005000000000000000000001B000000180000004C4C442F55553144A1E499C5508F990D32000000180000000100000000000B0000000B00000000000200000018000000001000000A000000A01000009C00000019000000480000005F5F504147455A45524F00000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000019000000980000005F5F54455854000000000000000000000000000001000000
+  - cmd:             LC_SEGMENT_64
+    cmdsize:         152
+    segname:         __DATA
+    vmaddr:          4294983680
+    vmsize:          16384
+    fileoff:         0
+    filesize:        0
+    maxprot:         3
+    initprot:        3
+    nsects:          1
+    flags:           0
+    Sections:
+      - sectname:        __common
+        segname:         __DATA
+        addr:            0x100004000
+        size:            4
+        offset:          0x0
+        align:           2
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x1
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+  - cmd:             LC_SEGMENT_64
+    cmdsize:         72
+    segname:         __LINKEDIT
+    vmaddr:          4295000064
+    vmsize:          4096
+    fileoff:         4096
+    filesize:        316
+    maxprot:         1
+    initprot:        1
+    nsects:          0
+    flags:           0
+  - cmd:             LC_SEGMENT_64
+    cmdsize:         952
+    segname:         __DWARF
+    vmaddr:          4295004160
+    vmsize:          4096
+    fileoff:         8192
+    filesize:        3640
+    maxprot:         7
+    initprot:        3
+    nsects:          11
+    flags:           0
+    Sections:
+      - sectname:        __debug_line
+        segname:         __DWARF
+        addr:            0x100009000
+        size:            327
+        offset:          0x2000
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x0
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+      - sectname:        __debug_aranges
+        segname:         __DWARF
+        addr:            0x100009147
+        size:            48
+        offset:          0x2147
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x0
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+      - sectname:        __debug_loc
+        segname:         __DWARF
+        addr:            0x100009177
+        size:            1026
+        offset:          0x2177
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x0
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         00000000000000000800000000000000010050080000000000000014000000000000000400A301509F0000000000000000000000000000000004000000000000000C0000000000000001005800000000000000000000000000000000080000000000000014000000000000000100500000000000000000000000000000000000000000000000000800000000000000010050080000000000000014000000000000000400A301509F0000000000000000000000000000000004000000000000000C0000000000000001005800000000000000000000000000000000080000000000000014000000000000000100500000000000000000000000000000000014000000000000002000000000000000010050200000000000000034000000000000000400A301509F00000000000000000000000000000000240000000000000034000000000000000100500000000000000000000000000000000014000000000000002000000000000000010050200000000000000034000000000000000400A301509F00000000000000000000000000000000240000000000000034000000000000000100500000000000000000000000000000000034000000000000004000000000000000010050400000000000000058000000000000000400A301509F000000000000000000000000000000003C0000000000000040000000000000000300707E9F000000000000000000000000000000004400000000000000580000000000000001005000000000000000000000000000000000340000000000000040000000000000000300707E9F00000000000000000000000000000000440000000000000058000000000000000100500000000000000000000000000000000034000000000000004000000000000000010050400000000000000058000000000000000400A301509F000000000000000000000000000000003C0000000000000040000000000000000300707E9F000000000000000000000000000000004400000000000000580000000000000001005000000000000000000000000000000000340000000000000040000000000000000300707E9F00000000000000000000000000000000440000000000000058000000000000000100500000000000000000000000000000000058000000000000006400000000000000010050640000000000000078000000000000000400A301509F00000000000000000000000000000000680000000000000078000000000000000100500000000000000000000000000000000084000000000000009000000000000000030011009F90000000000000009C000000000000000100639C00000000000000A800000000000000010064B800000000000000C00000000000000001006300000000000000000000000000000000
+      - sectname:        __debug_info
+        segname:         __DWARF
+        addr:            0x100009579
+        size:            923
+        offset:          0x2579
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x0
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+      - sectname:        __debug_frame
+        segname:         __DWARF
+        addr:            0x100009914
+        size:            272
+        offset:          0x2914
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x0
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         14000000FFFFFFFF0400080001781E0C1F000000000000001400000000000000380300000100000014000000000000001400000000000000380300000100000014000000000000001C000000000000004C030000010000002000000000000000480C1D109E019D021C000000000000004C030000010000002000000000000000480C1D109E019D021C000000000000006C030000010000002400000000000000480C1D109E019D021C000000000000006C030000010000002400000000000000480C1D109E019D021C0000000000000090030000010000002000000000000000480C1D109E019D022400000000000000B00300000100000058000000000000004C0C1D109E019D029303940400000000
+      - sectname:        __debug_abbrev
+        segname:         __DWARF
+        addr:            0x100009A24
+        size:            260
+        offset:          0x2A24
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x0
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+      - sectname:        __debug_str
+        segname:         __DWARF
+        addr:            0x100009B28
+        size:            317
+        offset:          0x2B28
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x0
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+      - sectname:        __apple_namespac
+        segname:         __DWARF
+        addr:            0x100009C65
+        size:            36
+        offset:          0x2C65
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x0
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         485341480100000001000000000000000C000000000000000100000001000600FFFFFFFF
+      - sectname:        __apple_names
+        segname:         __DWARF
+        addr:            0x100009C89
+        size:            316
+        offset:          0x2C89
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x0
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         48534148010000000A0000000A0000000C0000000000000001000000010006000000000002000000030000000400000006000000FFFFFFFF0800000009000000FFFFFFFFFFFFFFFF88CB36CFF4B03BD389CB36CF0A452B694908311C0B452B694A08311CDC41AB586A7F9A7CAD7ED75898000000A8000000B8000000C8000000D8000000E8000000F80000000801000018010000280100000A01000001000000BB010000000000009C000000010000002E000000000000001A010000010000003A02000000000000AE000000010000004F00000000000000D900000001000000E500000000000000C9000000010000009A00000000000000E90000000100000039010000000000002A01000001000000B90200000000000034010000010000000D03000000000000F900000002000000050200008402000000000000
+      - sectname:        __apple_types
+        segname:         __DWARF
+        addr:            0x100009DC5
+        size:            79
+        offset:          0x2DC5
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x0
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+  ...
[truncated]

Copy link
Contributor

@kyulee-com kyulee-com left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Just curious about what 0x10 (relative address) means in this example. Does it refer to the relative address (an offset within the function) of the next instruction following the call instruction?

For each call-site of a function, all the merged functions and their call-site infos seem displayed. If there are multiple call-sites within a function, are the same merged functions and their call-sites displayed repetitively?

Comment on lines 44 to 53
#--- repro-script.sh
#!/bin/bash
set -ex

# Set TOOLCHAIN_DIR to point to the llvm bin directory
TOOLCHAIN_DIR="llvm-project/build/Debug/bin" # Replace with the actual path to your LLVM bin directory
SCRIPT_DIR="$(cd "$(dirname "$0")"; pwd)"
OUT_DIR="$SCRIPT_DIR/out"
cd $SCRIPT_DIR
rm -rf "$OUT_DIR" && mkdir -p "$OUT_DIR"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recently have a framework, llvm/utils/update_test_body.py, to autogenerate test bodies that can do what this script is doing.

Copy link
Contributor

@ellishg ellishg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@alx32 alx32 merged commit d015578 into llvm:main Dec 13, 2024
8 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Dec 14, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-expensive-checks-ubuntu running on as-builder-4 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/187/builds/3161

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: tools/llvm-gsymutil/ARM_AArch64/macho-gsym-merged-callsites-dsym.yaml' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
Input file: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/test/tools/llvm-gsymutil/ARM_AArch64/Output/macho-gsym-merged-callsites-dsym.yaml.tmp/merged_callsites.dSYM
Output file (aarch64): /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/test/tools/llvm-gsymutil/ARM_AArch64/Output/macho-gsym-merged-callsites-dsym.yaml.tmp/call_sites_dSYM.gsym
error: line table has addresses that do not monotonically increase:
0x0000000100000338     12     15      1   0             0       0  is_stmt prologue_end
0x000000010000033c     13     20      1   0             0       0  is_stmt
0x0000000100000340     14     19      1   0             0       0  is_stmt
0x0000000100000348     15      5      1   0             0       0  is_stmt
0x0000000100000348     15      5      1   0             0       0  is_stmt end_sequence
0x0000000100000338      5     15      1   0             0       0  is_stmt prologue_end
0x000000010000033c      6     20      1   0             0       0  is_stmt
0x0000000100000340      7     19      1   0             0       0  is_stmt
0x0000000100000348      8      5      1   0             0       0  is_stmt
0x0000000100000348      8      5      1   0             0       0  is_stmt end_sequence

0x0000004f: DW_TAG_subprogram
              DW_AT_low_pc	(0x0000000100000338)
              DW_AT_high_pc	(0x000000010000034c)
              DW_AT_APPLE_omit_frame_ptr	(true)
              DW_AT_LLVM_stmt_sequence	(0x0000003b)
              DW_AT_frame_base	(DW_OP_reg31)
              DW_AT_call_all_calls	(true)
              DW_AT_name	("function4_copy1")
              DW_AT_decl_file	("/tmp/tst/out/merged_funcs_test.cpp")
              DW_AT_decl_line	(4)
              DW_AT_type	(0x0000000000000048 "int")
              DW_AT_external	(true)
              DW_AT_APPLE_optimized	(true)
error: line table has addresses that do not monotonically increase:
0x0000000100000338     12     15      1   0             0       0  is_stmt prologue_end
0x000000010000033c     13     20      1   0             0       0  is_stmt
0x0000000100000340     14     19      1   0             0       0  is_stmt
0x0000000100000348     15      5      1   0             0       0  is_stmt
0x0000000100000348     15      5      1   0             0       0  is_stmt end_sequence
0x0000000100000338      5     15      1   0             0       0  is_stmt prologue_end
0x000000010000033c      6     20      1   0             0       0  is_stmt
0x0000000100000340      7     19      1   0             0       0  is_stmt
0x0000000100000348      8      5      1   0             0       0  is_stmt
0x0000000100000348      8      5      1   0             0       0  is_stmt end_sequence

0x0000009a: DW_TAG_subprogram
              DW_AT_low_pc	(0x0000000100000338)
              DW_AT_high_pc	(0x000000010000034c)
              DW_AT_APPLE_omit_frame_ptr	(true)
              DW_AT_LLVM_stmt_sequence	(0x00000056)
              DW_AT_frame_base	(DW_OP_reg31)
...

@llvm-ci
Copy link
Collaborator

llvm-ci commented Dec 14, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-expensive-checks-debian running on gribozavr4 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/16/builds/10670

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: tools/llvm-gsymutil/ARM_AArch64/macho-gsym-merged-callsites-dsym.yaml' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
Input file: /b/1/llvm-clang-x86_64-expensive-checks-debian/build/test/tools/llvm-gsymutil/ARM_AArch64/Output/macho-gsym-merged-callsites-dsym.yaml.tmp/merged_callsites.dSYM
Output file (aarch64): /b/1/llvm-clang-x86_64-expensive-checks-debian/build/test/tools/llvm-gsymutil/ARM_AArch64/Output/macho-gsym-merged-callsites-dsym.yaml.tmp/call_sites_dSYM.gsym
error: line table has addresses that do not monotonically increase:
0x0000000100000338      5     15      1   0             0       0  is_stmt prologue_end
0x000000010000033c      6     20      1   0             0       0  is_stmt
0x0000000100000340      7     19      1   0             0       0  is_stmt
0x0000000100000348      8      5      1   0             0       0  is_stmt
0x0000000100000348      8      5      1   0             0       0  is_stmt end_sequence
0x0000000100000338     12     15      1   0             0       0  is_stmt prologue_end
0x000000010000033c     13     20      1   0             0       0  is_stmt
0x0000000100000340     14     19      1   0             0       0  is_stmt
0x0000000100000348     15      5      1   0             0       0  is_stmt
0x0000000100000348     15      5      1   0             0       0  is_stmt end_sequence

0x0000004f: DW_TAG_subprogram
              DW_AT_low_pc	(0x0000000100000338)
              DW_AT_high_pc	(0x000000010000034c)
              DW_AT_APPLE_omit_frame_ptr	(true)
              DW_AT_LLVM_stmt_sequence	(0x0000003b)
              DW_AT_frame_base	(DW_OP_reg31)
              DW_AT_call_all_calls	(true)
              DW_AT_name	("function4_copy1")
              DW_AT_decl_file	("/tmp/tst/out/merged_funcs_test.cpp")
              DW_AT_decl_line	(4)
              DW_AT_type	(0x0000000000000048 "int")
              DW_AT_external	(true)
              DW_AT_APPLE_optimized	(true)
error: line table has addresses that do not monotonically increase:
0x0000000100000338      5     15      1   0             0       0  is_stmt prologue_end
0x000000010000033c      6     20      1   0             0       0  is_stmt
0x0000000100000340      7     19      1   0             0       0  is_stmt
0x0000000100000348      8      5      1   0             0       0  is_stmt
0x0000000100000348      8      5      1   0             0       0  is_stmt end_sequence
0x0000000100000338     12     15      1   0             0       0  is_stmt prologue_end
0x000000010000033c     13     20      1   0             0       0  is_stmt
0x0000000100000340     14     19      1   0             0       0  is_stmt
0x0000000100000348     15      5      1   0             0       0  is_stmt
0x0000000100000348     15      5      1   0             0       0  is_stmt end_sequence

0x0000009a: DW_TAG_subprogram
              DW_AT_low_pc	(0x0000000100000338)
              DW_AT_high_pc	(0x000000010000034c)
              DW_AT_APPLE_omit_frame_ptr	(true)
              DW_AT_LLVM_stmt_sequence	(0x00000056)
              DW_AT_frame_base	(DW_OP_reg31)
...

@alx32 alx32 deleted the 04_gsymutil_callsite_align branch December 18, 2024 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants