From: Nico Weber Date: Sat, 27 Feb 2021 00:13:48 +0000 (-0500) Subject: [lld/mac] Simplify encodeDylibOrdinal() a bit X-Git-Tag: llvmorg-14-init~13831 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=860e862f34ce17f6a5ddeee472fe4e305370da18;p=platform%2Fupstream%2Fllvm.git [lld/mac] Simplify encodeDylibOrdinal() a bit Only one of the two callers used the lastBinding parameter, so do that work at that one call site. Extract a ordinalForDylibSymbol() helper to make this tidy. No behavior change. Differential Revision: https://reviews.llvm.org/D97597 --- diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp index 7fd7a49..6e21986 100644 --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -279,28 +279,21 @@ static void encodeBinding(const Symbol *sym, const OutputSection *osec, } // 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( - BIND_OPCODE_SET_DYLIB_SPECIAL_IMM | - (ordinal & BIND_IMMEDIATE_MASK)); - } else if (ordinal <= BIND_IMMEDIATE_MASK) { - os << static_cast(BIND_OPCODE_SET_DYLIB_ORDINAL_IMM | - ordinal); - } else { - os << static_cast(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(BIND_OPCODE_SET_DYLIB_SPECIAL_IMM | + (ordinal & BIND_IMMEDIATE_MASK)); + } else if (ordinal <= BIND_IMMEDIATE_MASK) { + os << static_cast(BIND_OPCODE_SET_DYLIB_ORDINAL_IMM | ordinal); + } else { + os << static_cast(BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB); + encodeULEB128(ordinal, os); } } @@ -336,7 +329,11 @@ void BindingSection::finalizeContents() { 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()) { encodeBinding(b.dysym, isec->parent, isec->outSecOff + b.target.offset, b.addend, /*isWeakBinding=*/false, lastBinding, os); @@ -558,7 +555,7 @@ uint32_t LazyBindingSection::encode(const DylibSymbol &sym) { 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())