[PATCH] D97597: [lld/mac] Simplify encodeDylibOrdinal() a bit

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 28 06:17:09 PST 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG860e862f34ce: [lld/mac] Simplify encodeDylibOrdinal() a bit (authored by thakis).
Herald added a project: LLVM.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97597

Files:
  lld/MachO/SyntheticSections.cpp


Index: lld/MachO/SyntheticSections.cpp
===================================================================
--- lld/MachO/SyntheticSections.cpp
+++ lld/MachO/SyntheticSections.cpp
@@ -279,28 +279,21 @@
 }
 
 // Non-weak bindings need to have their dylib ordinal encoded as well.
-static void encodeDylibOrdinal(const DylibSymbol *dysym, Binding *lastBinding,
-                               raw_svector_ostream &os) {
-  using namespace llvm::MachO;
+static int16_t ordinalForDylibSymbol(const DylibSymbol &dysym) {
+  return dysym.isDynamicLookup() ? MachO::BIND_SPECIAL_DYLIB_FLAT_LOOKUP
+                                 : dysym.getFile()->ordinal;
+}
 
-  int16_t ordinal = dysym->isDynamicLookup() ? BIND_SPECIAL_DYLIB_FLAT_LOOKUP
-                                             : dysym->getFile()->ordinal;
-
-  if (lastBinding == nullptr ||
-      lastBinding->ordinal != ordinal) {
-    if (ordinal <= 0) {
-      os << static_cast<uint8_t>(
-          BIND_OPCODE_SET_DYLIB_SPECIAL_IMM |
-          (ordinal & BIND_IMMEDIATE_MASK));
-    } else if (ordinal <= BIND_IMMEDIATE_MASK) {
-      os << static_cast<uint8_t>(BIND_OPCODE_SET_DYLIB_ORDINAL_IMM |
-                                 ordinal);
-    } else {
-      os << static_cast<uint8_t>(BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB);
-      encodeULEB128(ordinal, os);
-    }
-    if (lastBinding != nullptr)
-      lastBinding->ordinal = ordinal;
+static void encodeDylibOrdinal(int16_t ordinal, raw_svector_ostream &os) {
+  using namespace llvm::MachO;
+  if (ordinal <= 0) {
+    os << static_cast<uint8_t>(BIND_OPCODE_SET_DYLIB_SPECIAL_IMM |
+                               (ordinal & BIND_IMMEDIATE_MASK));
+  } else if (ordinal <= BIND_IMMEDIATE_MASK) {
+    os << static_cast<uint8_t>(BIND_OPCODE_SET_DYLIB_ORDINAL_IMM | ordinal);
+  } else {
+    os << static_cast<uint8_t>(BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB);
+    encodeULEB128(ordinal, os);
   }
 }
 
@@ -336,7 +329,11 @@
     return a.target.getVA() < b.target.getVA();
   });
   for (const BindingEntry &b : bindings) {
-    encodeDylibOrdinal(b.dysym, &lastBinding, os);
+    int16_t ordinal = ordinalForDylibSymbol(*b.dysym);
+    if (ordinal != lastBinding.ordinal) {
+      encodeDylibOrdinal(ordinal, os);
+      lastBinding.ordinal = ordinal;
+    }
     if (auto *isec = b.target.section.dyn_cast<const InputSection *>()) {
       encodeBinding(b.dysym, isec->parent, isec->outSecOff + b.target.offset,
                     b.addend, /*isWeakBinding=*/false, lastBinding, os);
@@ -558,7 +555,7 @@
   uint64_t offset = in.lazyPointers->addr - dataSeg->firstSection()->addr +
                     sym.stubsIndex * WordSize;
   encodeULEB128(offset, os);
-  encodeDylibOrdinal(&sym, nullptr, os);
+  encodeDylibOrdinal(ordinalForDylibSymbol(sym), os);
 
   uint8_t flags = MachO::BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM;
   if (sym.isWeakRef())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97597.326961.patch
Type: text/x-patch
Size: 2869 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210228/6e4bf3f3/attachment.bin>


More information about the llvm-commits mailing list