[PATCH] D104681: [lld/mac] Add explicit "no unwind info" entries for functions without unwind info

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 21 20:06:08 PDT 2021


thakis updated this revision to Diff 353538.
thakis added a comment.

clang-format


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104681/new/

https://reviews.llvm.org/D104681

Files:
  lld/MachO/UnwindInfoSection.cpp
  lld/test/MachO/tools/validate-unwind-info.py


Index: lld/test/MachO/tools/validate-unwind-info.py
===================================================================
--- lld/test/MachO/tools/validate-unwind-info.py
+++ lld/test/MachO/tools/validate-unwind-info.py
@@ -37,9 +37,12 @@
   if not object_encodings_map:
     sys.exit("no object encodings found in input")
 
+  # generate-cfi-funcs.py doesn't generate unwind info for _main.
+  object_encodings_map['_main'] = '00000000'
+
   program_symbols_map = {address:symbol
     for address, symbol in
-    re.findall(r"^%s(%s) g\s+F __TEXT,__text (x\1)$" % (hex8, hex8),
+    re.findall(r"^%s(%s) g\s+F __TEXT,__text (x\1|_main)$" % (hex8, hex8),
                objdump_string, re.MULTILINE)}
   if not program_symbols_map:
     sys.exit("no program symbols found in input")
Index: lld/MachO/UnwindInfoSection.cpp
===================================================================
--- lld/MachO/UnwindInfoSection.cpp
+++ lld/MachO/UnwindInfoSection.cpp
@@ -256,9 +256,9 @@
 // There should only be a handful of unique personality pointers, so we can
 // encode them as 2-bit indices into a small array.
 template <class Ptr>
-void encodePersonalities(
-    const std::vector<CompactUnwindEntry<Ptr> *> &cuPtrVector,
-    std::vector<uint32_t> &personalities) {
+static void
+encodePersonalities(const std::vector<CompactUnwindEntry<Ptr> *> &cuPtrVector,
+                    std::vector<uint32_t> &personalities) {
   for (CompactUnwindEntry<Ptr> *cu : cuPtrVector) {
     if (cu->personality == 0)
       continue;
@@ -280,6 +280,34 @@
           ") for compact unwind to encode");
 }
 
+template <class Ptr>
+static void addEntriesForFunctionsWithoutUnwindInfo(
+    std::vector<CompactUnwindEntry<Ptr>> &cuVector) {
+  DenseSet<Ptr> hasUnwindInfo;
+  for (CompactUnwindEntry<Ptr> &cuEntry : cuVector)
+    if (cuEntry.functionAddress != UINT64_MAX)
+      hasUnwindInfo.insert(cuEntry.functionAddress);
+
+  // Add explicit "has no unwind info" entries for all global and local symbols
+  // without unwind info.
+  auto markNoUnwindInfo = [&cuVector, &hasUnwindInfo](const Defined *d) {
+    if (d->isLive() && isCodeSection(d->isec)) {
+      Ptr ptr = d->getVA();
+      if (!hasUnwindInfo.count(ptr))
+        cuVector.push_back({ptr, 0, 0, 0, 0});
+    }
+  };
+  for (Symbol *sym : symtab->getSymbols())
+    if (auto *d = dyn_cast<Defined>(sym))
+      markNoUnwindInfo(d);
+  for (const InputFile *file : inputFiles)
+    if (auto *objFile = dyn_cast<ObjFile>(file))
+      for (Symbol *sym : objFile->symbols)
+        if (auto *d = dyn_cast_or_null<Defined>(sym))
+          if (!d->isExternal())
+            markNoUnwindInfo(d);
+}
+
 // Scan the __LD,__compact_unwind entries and compute the space needs of
 // __TEXT,__unwind_info and __TEXT,__eh_frame
 template <class Ptr> void UnwindInfoSectionImpl<Ptr>::finalize() {
@@ -301,6 +329,8 @@
   cuVector.resize(cuCount);
   relocateCompactUnwind(compactUnwindSection, cuVector);
 
+  addEntriesForFunctionsWithoutUnwindInfo(cuVector);
+
   // Rather than sort & fold the 32-byte entries directly, we create a
   // vector of pointers to entries and sort & fold that instead.
   cuPtrVector.reserve(cuCount);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104681.353538.patch
Type: text/x-patch
Size: 3182 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210622/2383989e/attachment.bin>


More information about the llvm-commits mailing list