[lld] b8bbb97 - [lld-macho][nfc] Put back shouldOmitFromOutput() asserts

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 16 12:23:27 PDT 2021


Author: Jez Ng
Date: 2021-06-16T15:23:04-04:00
New Revision: b8bbb9723af3ab5bfa11366480ecf42b45680101

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

LOG: [lld-macho][nfc] Put back shouldOmitFromOutput() asserts

I removed them in rG5de7467e982 but @thakis pointed out that
they were useful to keep, so here they are again. I've also converted
the `!isCoalescedWeak()` asserts into `!shouldOmitFromOutput()` asserts,
since the latter check subsumes the former.

Reviewed By: #lld-macho, thakis

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

Added: 
    

Modified: 
    lld/MachO/InputSection.cpp
    lld/MachO/InputSection.h
    lld/MachO/MapFile.cpp
    lld/MachO/UnwindInfoSection.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp
index 9ae9ca34286f0..b56e496f15670 100644
--- a/lld/MachO/InputSection.cpp
+++ b/lld/MachO/InputSection.cpp
@@ -64,6 +64,7 @@ void ConcatInputSection::writeTo(uint8_t *buf) {
         minuendVA = toSym->getVA() + minuend.addend;
       else {
         auto *referentIsec = minuend.referent.get<InputSection *>();
+        assert(!::shouldOmitFromOutput(referentIsec));
         minuendVA = referentIsec->getVA(minuend.addend);
       }
       referentVA = minuendVA - fromSym->getVA();
@@ -82,6 +83,7 @@ void ConcatInputSection::writeTo(uint8_t *buf) {
           referentVA -= firstTLVDataSection->addr;
       }
     } else if (auto *referentIsec = r.referent.dyn_cast<InputSection *>()) {
+      assert(!::shouldOmitFromOutput(referentIsec));
       referentVA = referentIsec->getVA(r.addend);
     }
     target->relocateOne(loc, r, referentVA, getVA() + r.offset);

diff  --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h
index dabf30a5e1135..e0d463ea30bc0 100644
--- a/lld/MachO/InputSection.h
+++ b/lld/MachO/InputSection.h
@@ -110,6 +110,18 @@ class ConcatInputSection final : public InputSection {
   uint64_t outSecOff = 0;
 };
 
+// Helper functions to make it easy to sprinkle asserts.
+
+inline bool shouldOmitFromOutput(InputSection *isec) {
+  return isa<ConcatInputSection>(isec) &&
+         cast<ConcatInputSection>(isec)->shouldOmitFromOutput();
+}
+
+inline bool isCoalescedWeak(InputSection *isec) {
+  return isa<ConcatInputSection>(isec) &&
+         cast<ConcatInputSection>(isec)->isCoalescedWeak();
+}
+
 // We allocate a lot of these and binary search on them, so they should be as
 // compact as possible. Hence the use of 31 rather than 64 bits for the hash.
 struct StringPiece {

diff  --git a/lld/MachO/MapFile.cpp b/lld/MachO/MapFile.cpp
index 1b516bbef646f..26db02d1e7a2c 100644
--- a/lld/MachO/MapFile.cpp
+++ b/lld/MachO/MapFile.cpp
@@ -65,8 +65,10 @@ static std::vector<Defined *> getSymbols() {
     if (isa<ObjFile>(file))
       for (Symbol *sym : file->symbols)
         if (auto *d = dyn_cast_or_null<Defined>(sym))
-          if (d->isLive() && d->isec && d->getFile() == file)
+          if (d->isLive() && d->isec && d->getFile() == file) {
+            assert(!shouldOmitFromOutput(d->isec));
             v.push_back(d);
+          }
   return v;
 }
 
@@ -142,6 +144,7 @@ void macho::writeMapFile() {
   os << "# Address\t    File  Name\n";
   for (InputSection *isec : inputSections) {
     auto symsIt = sectionSyms.find(isec);
+    assert(!shouldOmitFromOutput(isec) || (symsIt == sectionSyms.end()));
     if (symsIt == sectionSyms.end())
       continue;
     for (Symbol *sym : symsIt->second) {

diff  --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp
index 8b3db310ca152..309e5ce64d73c 100644
--- a/lld/MachO/UnwindInfoSection.cpp
+++ b/lld/MachO/UnwindInfoSection.cpp
@@ -174,6 +174,7 @@ void UnwindInfoSectionImpl<Ptr>::prepareRelocations(ConcatInputSection *isec) {
     }
 
     if (auto *referentIsec = r.referent.dyn_cast<InputSection *>()) {
+      assert(!isCoalescedWeak(referentIsec));
       // Personality functions can be referenced via section relocations
       // if they live in the same object file. Create placeholder synthetic
       // symbols for them in the GOT.


        


More information about the llvm-commits mailing list