[lld] f2c7f75 - [lld-macho] Support creating N_SO stab for DWARF5 compile units

Daniel Bertalan via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 28 01:00:24 PDT 2022


Author: Daniel Bertalan
Date: 2022-07-28T09:58:26+02:00
New Revision: f2c7f75f61bdc1009129ee33600d574cac9214d9

URL: https://github.com/llvm/llvm-project/commit/f2c7f75f61bdc1009129ee33600d574cac9214d9
DIFF: https://github.com/llvm/llvm-project/commit/f2c7f75f61bdc1009129ee33600d574cac9214d9.diff

LOG: [lld-macho] Support creating N_SO stab for DWARF5 compile units

In DWARF5, the `DW_AT_name` and `DW_AT_comp_dir` attributes are encoded
using the `strx*` forms, which specify an index into `__debug_str_offs`.
This commit adds that section to DwarfObject, so the debug info parser
can resolve these references.

The test case was manually adapted from stabs-icf.s.

Fixes #51668

Differential Revision: https://reviews.llvm.org/D130559

Added: 
    lld/test/MachO/stabs-dwarf5.s

Modified: 
    lld/MachO/Dwarf.cpp
    lld/MachO/Dwarf.h
    lld/MachO/InputSection.h

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Dwarf.cpp b/lld/MachO/Dwarf.cpp
index 357503a655cd1..47dc51e6196d1 100644
--- a/lld/MachO/Dwarf.cpp
+++ b/lld/MachO/Dwarf.cpp
@@ -30,6 +30,7 @@ std::unique_ptr<DwarfObject> DwarfObject::create(ObjFile *obj) {
             StringSwitch<StringRef *>(isec->getName())
                 .Case(section_names::debugInfo, &dObj->infoSection.Data)
                 .Case(section_names::debugLine, &dObj->lineSection.Data)
+                .Case(section_names::debugStrOffs, &dObj->strOffsSection.Data)
                 .Case(section_names::debugAbbrev, &dObj->abbrevSection)
                 .Case(section_names::debugStr, &dObj->strSection)
                 .Default(nullptr)) {

diff  --git a/lld/MachO/Dwarf.h b/lld/MachO/Dwarf.h
index 6a18fa143f029..d1f40844181f5 100644
--- a/lld/MachO/Dwarf.h
+++ b/lld/MachO/Dwarf.h
@@ -41,6 +41,10 @@ class DwarfObject final : public llvm::DWARFObject {
     return lineSection;
   }
 
+  llvm::DWARFSection const &getStrOffsetsSection() const override {
+    return strOffsSection;
+  }
+
   // Returns an instance of DwarfObject if the given object file has the
   // relevant DWARF debug sections.
   static std::unique_ptr<DwarfObject> create(ObjFile *);
@@ -48,6 +52,7 @@ class DwarfObject final : public llvm::DWARFObject {
 private:
   llvm::DWARFSection infoSection;
   llvm::DWARFSection lineSection;
+  llvm::DWARFSection strOffsSection;
   llvm::StringRef abbrevSection;
   llvm::StringRef strSection;
 };

diff  --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h
index afe76c56b5362..3982cbf309861 100644
--- a/lld/MachO/InputSection.h
+++ b/lld/MachO/InputSection.h
@@ -302,6 +302,7 @@ constexpr const char debugAbbrev[] = "__debug_abbrev";
 constexpr const char debugInfo[] = "__debug_info";
 constexpr const char debugLine[] = "__debug_line";
 constexpr const char debugStr[] = "__debug_str";
+constexpr const char debugStrOffs[] = "__debug_str_offs";
 constexpr const char ehFrame[] = "__eh_frame";
 constexpr const char gccExceptTab[] = "__gcc_except_tab";
 constexpr const char export_[] = "__export";

diff  --git a/lld/test/MachO/stabs-dwarf5.s b/lld/test/MachO/stabs-dwarf5.s
new file mode 100644
index 0000000000000..61a0986e67d50
--- /dev/null
+++ b/lld/test/MachO/stabs-dwarf5.s
@@ -0,0 +1,72 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin -dwarf-version=5 %s -o %t.o
+
+# RUN: %lld -lSystem %t.o -o %t
+# RUN: dsymutil -s %t | FileCheck %s -DDIR=%t -DSRC_PATH=%t.o
+
+# CHECK:      (N_SO         ) 00      0000   0000000000000000   '/tmp{{[/\\]}}test.cpp'
+# CHECK-NEXT: (N_OSO        ) 03      0001   {{.*}} '[[SRC_PATH]]'
+# CHECK-NEXT: (N_FUN        ) 01      0000   [[#%.16x,MAIN:]]   '_main'
+# CHECK-NEXT: (N_FUN        ) 00      0000   0000000000000001{{$}}
+# CHECK-DAG:  (     SECT EXT) 01      0000   [[#MAIN]]           '_main'
+# CHECK-DAG:  (       {{.*}}) {{[0-9]+}}                 0010   {{[0-9a-f]+}}      '__mh_execute_header'
+# CHECK-DAG:  (       {{.*}}) {{[0-9]+}}                 0100   0000000000000000   'dyld_stub_binder'
+# CHECK-EMPTY:
+
+.text
+.globl _main
+
+.subsections_via_symbols
+
+_main:
+Lfunc_begin0:
+  retq
+Lfunc_end0:
+
+.section  __DWARF,__debug_str_offs,regular,debug
+Lsection_str_off:
+  .long   12                     ## Length of String Offsets Set
+  .short  5
+  .short  0
+Lstr_offsets_base0:
+.section  __DWARF,__debug_str,regular,debug
+  .asciz  "test.cpp"             ## string offset=0
+  .asciz  "/tmp"                 ## string offset=9
+.section __DWARF,__debug_str_offs,regular,debug
+  .long  0
+  .long  9
+.section  __DWARF,__debug_abbrev,regular,debug
+Lsection_abbrev:
+  .byte  1                       ## Abbreviation Code
+  .byte  17                      ## DW_TAG_compile_unit
+  .byte  1                       ## DW_CHILDREN_yes
+  .byte  17                      ## DW_AT_low_pc
+  .byte  1                       ## DW_FORM_addr
+  .byte  18                      ## DW_AT_high_pc
+  .byte  6                       ## DW_FORM_data4
+  .byte  3                       ## DW_AT_name
+  .byte  37                      ## DW_FORM_strx1
+  .byte  27                      ## DW_AT_comp_dir
+  .byte  37                      ## DW_FORM_strx1
+  .byte  114                     ## DW_AT_str_offsets_base
+  .byte  23                      ## DW_FORM_sec_offset
+  .byte  0                       ## EOM(1)
+.section  __DWARF,__debug_info,regular,debug
+.set Lset0, Ldebug_info_end0-Ldebug_info_start0 ## Length of Unit
+  .long  Lset0
+Ldebug_info_start0:
+  .short  5                       ## DWARF version number
+  .byte   1                       ## DWARF Unit Type
+  .byte   8                       ## Address Size (in bytes)
+.set Lset1, Lsection_abbrev-Lsection_abbrev ## Offset Into Abbrev. Section
+  .long  Lset1
+  .byte  1                       ## Abbrev [1] 0xb:0x48 DW_TAG_compile_unit
+  .quad  Lfunc_begin0            ## DW_AT_low_pc
+.set Lset3, Lfunc_end0-Lfunc_begin0     ## DW_AT_high_pc
+  .long  Lset3
+  .byte  0                       ## DW_AT_name
+  .byte  1                       ## DW_AT_comp_dir
+.set Lset4, Lstr_offsets_base0-Lsection_str_off  ## DW_AT_str_offsets_base
+  .long Lset4
+  .byte  0                       ## End Of Children Mark
+Ldebug_info_end0:


        


More information about the llvm-commits mailing list