[lld/mac] Add some comments and asserts
authorNico Weber <thakis@chromium.org>
Thu, 7 Apr 2022 12:48:52 +0000 (08:48 -0400)
committerNico Weber <thakis@chromium.org>
Thu, 7 Apr 2022 19:43:28 +0000 (15:43 -0400)
I was wondering if SymtabSection::emitStabs() should check
defined->includeInSymtab. Add asserts and comments explaining why that's not
necessary.

No behavior change.

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

lld/MachO/SymbolTable.cpp
lld/MachO/SyntheticSections.cpp

index 2b6fb77..a3e3253 100644 (file)
@@ -230,8 +230,9 @@ Defined *SymbolTable::addSynthetic(StringRef name, InputSection *isec,
                                    uint64_t value, bool isPrivateExtern,
                                    bool includeInSymtab,
                                    bool referencedDynamically) {
+  assert(!isec || !isec->getFile()); // See makeSyntheticInputSection().
   Defined *s =
-      addDefined(name, nullptr, isec, value, /*size=*/0,
+      addDefined(name, /*file=*/nullptr, isec, value, /*size=*/0,
                  /*isWeakDef=*/false, isPrivateExtern,
                  /*isThumb=*/false, referencedDynamically,
                  /*noDeadStrip=*/false, /*isWeakDefCanBeHidden=*/false);
index fd6f5e4..8ed6f5c 100644 (file)
@@ -908,6 +908,11 @@ void SymtabSection::emitStabs() {
       ObjFile *file = dyn_cast_or_null<ObjFile>(isec->getFile());
       if (!file || !file->compileUnit)
         continue;
+
+      // All symbols that set includeInSymtab to false are synthetic symbols.
+      // Those have `file` set to nullptr and were already skipped due to that.
+      assert(defined->includeInSymtab);
+
       symbolsNeedingStabs.push_back(defined);
     }
   }