Skip to content
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

[DWARFLinker] Update stmt-seq-macho.test to use update_test_body.py #133363

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alx32
Copy link
Contributor

@alx32 alx32 commented Mar 28, 2025

In this change we update DWARFLinker test llvm/test/tools/dsymutil/ARM/stmt-seq-macho.test to be self-contained and easy to regenerate via update_test_body.py. As relating to this comment - this would be approach nr.2

Updating the test can be done via:

PATH=/path/to/llvm/bin:$PATH llvm/utils/update_test_body.py llvm/test/tools/dsymutil/ARM/stmt-seq-macho.test

--keep-icf-stabs

# Convert executable to YAML for the test
echo "#--- stmt_seq_macho.o.yaml"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MaskRay - We need this test to convert multiple YAML to multiple binaries. Is this the correct pattern to have update_test_body.py generate multiple binaries ?

Copy link
Member

Choose a reason for hiding this comment

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

echo '#--- a.s' looks good. lld/test/ELF/debug-names-type-units.s has an example

#--- gen
echo '#--- a.tu.s'
clang --target=x86_64-linux -S -O1 -g -gpubnames -fdebug-types-section a.cc -o -
echo '#--- a.foreign-tu.s'
clang --target=x86_64-linux -S -O1 -g -gpubnames -fdebug-types-section -gsplit-dwarf a.cc -o -
echo '#--- b.s'
clang --target=x86_64-linux -S -O1 -g -gpubnames b.cc -o -
.endif

(probably should use -fdebug-compilation-dir=. on non-linux systems)

@alx32 alx32 requested a review from ellishg March 28, 2025 04:36
@alx32 alx32 marked this pull request as ready for review March 30, 2025 02:43
@alx32 alx32 requested a review from JDevlieghere as a code owner March 30, 2025 02:44
@llvmbot
Copy link
Member

llvmbot commented Mar 30, 2025

@llvm/pr-subscribers-debuginfo

Author: None (alx32)

Changes

In this change we update DWARFLinker test llvm/test/tools/dsymutil/ARM/stmt-seq-macho.test to be self-contained and easy to regenerate via update_test_body.py. As relating to this comment - this would be approach nr.2

Updating the test can be done via:

PATH=/path/to/llvm/bin:$PATH llvm/utils/update_test_body.py llvm/test/tools/dsymutil/ARM/stmt-seq-macho.test

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

3 Files Affected:

  • (modified) llvm/test/tools/dsymutil/ARM/stmt-seq-macho.test (+1842-20)
  • (removed) llvm/test/tools/dsymutil/Inputs/private/tmp/stmt_seq/stmt_seq_macho.exe ()
  • (removed) llvm/test/tools/dsymutil/Inputs/private/tmp/stmt_seq/stmt_seq_macho.o ()
diff --git a/llvm/test/tools/dsymutil/ARM/stmt-seq-macho.test b/llvm/test/tools/dsymutil/ARM/stmt-seq-macho.test
index 1dd1f61f1f7fb..1e08bc07e14cb 100644
--- a/llvm/test/tools/dsymutil/ARM/stmt-seq-macho.test
+++ b/llvm/test/tools/dsymutil/ARM/stmt-seq-macho.test
@@ -1,5 +1,10 @@
-RUN: dsymutil --flat -oso-prepend-path %p/../Inputs %p/../Inputs/private/tmp/stmt_seq/stmt_seq_macho.exe -o %t.stmt_seq_macho.dSYM
-RUN: llvm-dwarfdump --debug-info --debug-line -v %t.stmt_seq_macho.dSYM | sort | FileCheck %s -check-prefix=CHECK_DSYM
+## Test that verifies DW_AT_LLVM_stmt_sequence attributes are correctly patched in the dSYM
+
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: yaml2obj %t/stmt_seq_macho.exe.yaml -o %t/stmt_seq_macho.exe
+# RUN: yaml2obj %t/stmt_seq_macho.o.yaml   -o %t/stmt_seq_macho.o
+# RUN: dsymutil --flat --verify-dwarf=none -oso-prepend-path %t %t/stmt_seq_macho.exe -o %t/stmt_seq_macho.dSYM
+# RUN: llvm-dwarfdump --debug-info --debug-line -v %t/stmt_seq_macho.dSYM | sort | FileCheck %s -check-prefix=CHECK_DSYM
 
 # CHECK_DSYM: DW_AT_LLVM_stmt_sequence [DW_FORM_sec_offset] ([[OFFSET1:(0x[0-9a-f]+)]])
 # CHECK_DSYM: DW_AT_LLVM_stmt_sequence [DW_FORM_sec_offset] ([[OFFSET2:(0x[0-9a-f]+)]])
@@ -11,27 +16,18 @@ RUN: llvm-dwarfdump --debug-info --debug-line -v %t.stmt_seq_macho.dSYM | sort |
 # CHECK_DSYM: [[OFFSET3]]: 00 DW_LNE_set_address
 # CHECK_DSYM: [[OFFSET4]]: 00 DW_LNE_set_address
 
-
-########  Generate stmt_seq_macho.exe & stmt_seq_macho.o via script:  ##########
-# ------------------------------------------------------------------------------
-#!/bin/bash
-TOOLCHAIN=/path/to/llvm/bin
-
-# ------------------------------------------------------------------------------
-# Create the stmt_seq_macho.cpp source file
-# ------------------------------------------------------------------------------
-cat > stmt_seq_macho.cpp << 'EOF'
+#--- stmt_seq_macho.cpp
 #define ATTRIB extern "C" __attribute__((noinline))
 
 ATTRIB int function3_copy1(int a) {
     int b = a + 3;
     return b + 1;
 }
- 
+
 ATTRIB int function2_copy1(int a) {
     return a - 22;
 }
- 
+
 ATTRIB int function3_copy2(int a) {
     int b = a + 3;
     return b + 1;
@@ -45,11 +41,11 @@ ATTRIB int function2_copy2(int a) {
 struct logic_error {
     logic_error(const char* s) {}
 };
- 
+
 struct length_error : public logic_error {
     __attribute__((noinline)) explicit length_error(const char* s) : logic_error(s) {}
 };
- 
+
 int main() {
     int sum = 0;
     sum += function2_copy2(3);
@@ -58,11 +54,12 @@ int main() {
     length_error e("test");
     return sum;
 }
-EOF
 
-"$TOOLCHAIN/clang" \
-  --target=arm64-apple-macos11 \
+#--- gen
+# Compile to an object file
+clang --target=arm64-apple-macos11 \
   -c \
+  -fdebug-compilation-dir=/private/tmp/stmt_seq \
   -g \
   -gdwarf-4 \
   -fno-unwind-tables \
@@ -73,11 +70,1836 @@ EOF
   stmt_seq_macho.cpp \
   -o stmt_seq_macho.o
 
-"$TOOLCHAIN/ld64.lld" \
+# Link into an executable
+ld64.lld \
   -arch arm64 \
   -platform_version macos 11.0.0 11.0.0 \
   -o stmt_seq_macho.exe \
   stmt_seq_macho.o \
   -dead_strip \
   --icf=all \
+  -oso_prefix $(pwd)/ \
   --keep-icf-stabs
+
+# Convert executable to YAML for the test
+echo "#--- stmt_seq_macho.o.yaml"
+obj2yaml stmt_seq_macho.o
+echo ""
+echo "#--- stmt_seq_macho.exe.yaml"
+obj2yaml stmt_seq_macho.exe
+
+#--- stmt-seq-macho.yaml
+#--- stmt_seq_macho.o.yaml
+--- !mach-o
+FileHeader:
+  magic:           0xFEEDFACF
+  cputype:         0x100000C
+  cpusubtype:      0x0
+  filetype:        0x1
+  ncmds:           5
+  sizeofcmds:      1176
+  flags:           0x2000
+  reserved:        0x0
+LoadCommands:
+  - cmd:             LC_SEGMENT_64
+    cmdsize:         1032
+    segname:         ''
+    vmaddr:          0
+    vmsize:          2793
+    fileoff:         1208
+    filesize:        2793
+    maxprot:         7
+    initprot:        7
+    nsects:          12
+    flags:           0
+    Sections:
+      - sectname:        __text
+        segname:         __TEXT
+        addr:            0x0
+        size:            128
+        offset:          0x4B8
+        align:           2
+        reloff:          0xFA8
+        nreloc:          7
+        flags:           0x80000400
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         00100011C0035FD600580051C0035FD600100011C0035FD600580051C0035FD6FFC300D1F44F01A9FD7B02A9FD8300916000805200000094F30300AA20058052000000941400130B6001805200000094F30300AA0100009021000091E03F0091000000948002130BFD7B42A9F44F41A9FFC30091C0035FD600000014C0035FD6
+        relocations:
+          - address:         0x78
+            symbolnum:       4
+            pcrel:           true
+            length:          2
+            extern:          true
+            type:            2
+            scattered:       false
+            value:           0
+          - address:         0x60
+            symbolnum:       3
+            pcrel:           true
+            length:          2
+            extern:          true
+            type:            2
+            scattered:       false
+            value:           0
+          - address:         0x58
+            symbolnum:       1
+            pcrel:           false
+            length:          2
+            extern:          true
+            type:            4
+            scattered:       false
+            value:           0
+          - address:         0x54
+            symbolnum:       1
+            pcrel:           true
+            length:          2
+            extern:          true
+            type:            3
+            scattered:       false
+            value:           0
+          - address:         0x4C
+            symbolnum:       5
+            pcrel:           true
+            length:          2
+            extern:          true
+            type:            2
+            scattered:       false
+            value:           0
+          - address:         0x40
+            symbolnum:       8
+            pcrel:           true
+            length:          2
+            extern:          true
+            type:            2
+            scattered:       false
+            value:           0
+          - address:         0x34
+            symbolnum:       6
+            pcrel:           true
+            length:          2
+            extern:          true
+            type:            2
+            scattered:       false
+            value:           0
+      - sectname:        __cstring
+        segname:         __TEXT
+        addr:            0x80
+        size:            5
+        offset:          0x538
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x2
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         '7465737400'
+      - sectname:        __debug_loc
+        segname:         __DWARF
+        addr:            0x85
+        size:            412
+        offset:          0x53D
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x2000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         00000000000000000400000000000000010050040000000000000008000000000000000400A301509F0000000000000000000000000000000000000000000000000400000000000000030070039F0000000000000000000000000000000008000000000000000C000000000000000100500C0000000000000010000000000000000400A301509F0000000000000000000000000000000010000000000000001400000000000000010050140000000000000018000000000000000400A301509F0000000000000000000000000000000010000000000000001400000000000000030070039F0000000000000000000000000000000018000000000000001C000000000000000100501C0000000000000020000000000000000400A301509F000000000000000000000000000000001C0000000000000020000000000000000100500000000000000000000000000000000030000000000000003C00000000000000030011009F3C0000000000000048000000000000000100634800000000000000540000000000000001006400000000000000000000000000000000
+      - sectname:        __debug_abbrev
+        segname:         __DWARF
+        addr:            0x221
+        size:            359
+        offset:          0x6D9
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x2000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+      - sectname:        __debug_info
+        segname:         __DWARF
+        addr:            0x388
+        size:            686
+        offset:          0x840
+        align:           0
+        reloff:          0xFE0
+        nreloc:          14
+        flags:           0x2000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        relocations:
+          - address:         0x26A
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x251
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x216
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x1B8
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x1A5
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x191
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x17E
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x140
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x104
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0xC8
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x9B
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x5F
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x37
+            symbolnum:       2
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x22
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+      - sectname:        __debug_str
+        segname:         __DWARF
+        addr:            0x636
+        size:            239
+        offset:          0xAEE
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x2000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+      - sectname:        __apple_names
+        segname:         __DWARF
+        addr:            0x725
+        size:            260
+        offset:          0xBDD
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x2000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         485341480100000008000000080000000C000000000000000100000001000600000000000200000005000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF90D9F86F88CB36CF4908311CD1125E5389CB36CF4A08311C522B70536A7F9A7C8000000094000000A4000000B4000000C4000000D4000000E4000000F40000008A0000000200000015020000690200000000000055000000010000009A0000000000000045000000010000005E00000000000000A3000000010000001502000000000000750000000100000003010000000000006500000001000000C700000000000000BB00000001000000690200000000000085000000010000003F01000000000000
+      - sectname:        __apple_objc
+        segname:         __DWARF
+        addr:            0x829
+        size:            36
+        offset:          0xCE1
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x2000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         485341480100000001000000000000000C000000000000000100000001000600FFFFFFFF
+      - sectname:        __apple_namespac
+        segname:         __DWARF
+        addr:            0x84D
+        size:            36
+        offset:          0xD05
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x2000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         485341480100000001000000000000000C000000000000000100000001000600FFFFFFFF
+      - sectname:        __apple_types
+        segname:         __DWARF
+        addr:            0x871
+        size:            195
+        offset:          0xD29
+        align:           0
+        reloff:          0x0
+        nreloc:          0
+        flags:           0x2000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         48534148010000000500000005000000140000000000000003000000010006000300050004000B000000000002000000FFFFFFFF03000000040000007CA8F05D90D9F86F5B738CDC3080880B6320957C64000000770000008A0000009D000000B00000009700000001000000EA010000130000000000008A00000001000000C80100001300000000000031000000010000005700000024000000000000D300000001000000A1020000240000000000002C000000010000005000000024000000000000
+      - sectname:        __debug_frame
+        segname:         __DWARF
+        addr:            0x938
+        size:            208
+        offset:          0xDF0
+        align:           3
+        reloff:          0x1050
+        nreloc:          7
+        flags:           0x2000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        content:         14000000FFFFFFFF0400080001781E0C1F00000000000000140000000000000000000000000000000800000000000000140000000000000008000000000000000800000000000000140000000000000010000000000000000800000000000000140000000000000018000000000000000800000000000000240000000000000020000000000000005800000000000000500C1D109E019D02930394040000000014000000000000007800000000000000040000000000000014000000000000007C000000000000000400000000000000
+        relocations:
+          - address:         0xC0
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0xA8
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x80
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x68
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x50
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x38
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x20
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+      - sectname:        __debug_line
+        segname:         __DWARF
+        addr:            0xA08
+        size:            225
+        offset:          0xEC0
+        align:           0
+        reloff:          0x1088
+        nreloc:          7
+        flags:           0x2000000
+        reserved1:       0x0
+        reserved2:       0x0
+        reserved3:       0x0
+        relocations:
+          - address:         0xD1
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0xBD
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x92
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x7E
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x66
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+            type:            0
+            scattered:       false
+            value:           0
+          - address:         0x50
+            symbolnum:       1
+            pcrel:           false
+            length:          3
+            extern:          false
+ ...
[truncated]

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.

3 participants