Reland "[llvm][dsymutil] Add DW_TAG_imported_declaration to accelerator table"
authorMichael Buch <michaelbuch12@gmail.com>
Fri, 10 Feb 2023 12:43:42 +0000 (12:43 +0000)
committerMichael Buch <michaelbuch12@gmail.com>
Fri, 10 Feb 2023 17:19:07 +0000 (17:19 +0000)
This relands the commit previously reverted in
`8570bee53a8ce0c5d04bc11f288e19a457474c4c` due to failures on linux.

The problem was that the test executable was built with absolute
OSO prefix paths. This re-commit adds a modified version of the
executable that strips the absolute OSO prefix paths and makes
sure the test appends the OSO prefix appropriately (via the appropriate
dsymutil flags).

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

llvm/lib/DWARFLinker/DWARFLinker.cpp
llvm/test/tools/dsymutil/ARM/accel-imported-declarations.test [new file with mode: 0644]
llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.cpp [new file with mode: 0644]
llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.macho-arm64 [new file with mode: 0755]
llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.macho-arm64.o [new file with mode: 0644]

index d302d61..6d6bd33 100644 (file)
@@ -1589,6 +1589,8 @@ DIE *DWARFLinker::DIECloner::cloneDIE(const DWARFDie &InputDIE,
     if (!AttrInfo.Name)
       AttrInfo.Name = StringPool.getEntry("(anonymous namespace)");
     Unit.addNamespaceAccelerator(Die, AttrInfo.Name);
+  } else if (Tag == dwarf::DW_TAG_imported_declaration && AttrInfo.Name) {
+    Unit.addNamespaceAccelerator(Die, AttrInfo.Name);
   } else if (isTypeTag(Tag) && !AttrInfo.IsDeclaration &&
              getDIENames(InputDIE, AttrInfo, StringPool) && AttrInfo.Name &&
              AttrInfo.Name.getString()[0]) {
diff --git a/llvm/test/tools/dsymutil/ARM/accel-imported-declarations.test b/llvm/test/tools/dsymutil/ARM/accel-imported-declarations.test
new file mode 100644 (file)
index 0000000..cdd938b
--- /dev/null
@@ -0,0 +1,47 @@
+RUN: dsymutil -accelerator=Dwarf -oso-prepend-path=%p/../Inputs %p/../Inputs/accel-imported-declaration.macho-arm64 -o %t.dwarf.dSYM
+RUN: dsymutil -accelerator=Apple -oso-prepend-path=%p/../Inputs %p/../Inputs/accel-imported-declaration.macho-arm64 -o %t.apple.dSYM
+
+RUN: llvm-dwarfdump -v %t.dwarf.dSYM | FileCheck %s -check-prefixes=DWARF,COMMON
+RUN: llvm-dwarfdump -v %t.apple.dSYM | FileCheck %s -check-prefixes=APPLE,COMMON
+
+COMMON: .debug_info contents
+COMMON: {{.*}}DW_TAG_namespace
+COMMON:   DW_AT_name{{.*}}"A"
+COMMON: {{.*}}DW_TAG_namespace
+COMMON:   DW_AT_name{{.*}}"B"
+COMMON: [[NAMESPACE:0x[0-9a-f]*]]:{{.*}}DW_TAG_namespace
+COMMON:   DW_AT_name{{.*}}"C"
+COMMON: [[IMPORTED:0x[0-9a-f]*]]:{{.*}}DW_TAG_imported_declaration
+COMMON:   DW_AT_name{{.*}}"C"
+
+DWARF:      .debug_names contents:
+DWARF:      Bucket 0 [
+DWARF-NEXT:   Name {{.*}} {
+DWARF-NEXT:     Hash: {{.*}}
+DWARF-NEXT:     String: {{.*}} "C"
+DWARF-NEXT:     Entry {{.*}} {
+DWARF-NEXT:       Abbrev: {{.*}}
+DWARF-NEXT:       Tag: DW_TAG_namespace
+DWARF-NEXT:       DW_IDX_die_offset: [[NAMESPACE]]
+DWARF-NEXT:     }
+DWARF-NEXT:     Entry {{.*}} {
+DWARF-NEXT:       Abbrev: {{.*}}
+DWARF-NEXT:       Tag: DW_TAG_imported_declaration
+DWARF-NEXT:       DW_IDX_die_offset: [[IMPORTED]]
+DWARF-NEXT:     }
+DWARF-NEXT:   }
+
+APPLE:      .apple_namespaces contents:
+APPLE:      Bucket 1 [
+APPLE-NEXT:   Hash {{.*}} [
+APPLE-NEXT:     Name@{{.*}} {
+APPLE-NEXT:       String: {{.*}} "C"
+APPLE-NEXT:       Data 0 [
+APPLE-NEXT:         Atom[0]: [[NAMESPACE]]
+APPLE-NEXT:       ]
+APPLE-NEXT:       Data 1 [
+APPLE-NEXT:         Atom[0]: [[IMPORTED]]
+APPLE-NEXT:       ]
+APPLE-NEXT:     }
+APPLE-NEXT:   ]
+APPLE-NEXT: ]
diff --git a/llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.cpp b/llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.cpp
new file mode 100644 (file)
index 0000000..31f4b8b
--- /dev/null
@@ -0,0 +1,22 @@
+// Compiled on macOS using:
+// 1. clang++ -c -std=c++2a -gdwarf-4 -O0 -o accel-imported-declaration.macho-arm64.o
+// 2. clang++ -Wl,-oso_prefix=$PWD accel-imported-declaration.macho-arm64.o -o accel-imported-declaration.macho-arm64
+//
+// In step 2 it's important to strip the absolute object file paths
+//
+// Verify that the OSO path isn't absolute using `nm -ap accel-imported-declaration.macho-arm64`
+
+namespace A {
+namespace B {
+namespace C {
+int a = -1;
+} // namespace C
+} // namespace B
+
+namespace C = B::C;
+
+using namespace B::C;
+using B::C::a;
+} // namespace A
+
+int main() { return A::a; }
diff --git a/llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.macho-arm64 b/llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.macho-arm64
new file mode 100755 (executable)
index 0000000..671ef7d
Binary files /dev/null and b/llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.macho-arm64 differ
diff --git a/llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.macho-arm64.o b/llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.macho-arm64.o
new file mode 100644 (file)
index 0000000..9bcf3b4
Binary files /dev/null and b/llvm/test/tools/dsymutil/Inputs/accel-imported-declaration.macho-arm64.o differ