@@ -279,28 +279,21 @@ static void encodeBinding(const Symbol *sym, const OutputSection *osec,
279
279
}
280
280
281
281
// Non-weak bindings need to have their dylib ordinal encoded as well.
282
- static void encodeDylibOrdinal (const DylibSymbol *dysym, Binding *lastBinding,
283
- raw_svector_ostream &os) {
284
- using namespace llvm ::MachO;
282
+ static int16_t ordinalForDylibSymbol (const DylibSymbol &dysym) {
283
+ return dysym.isDynamicLookup () ? MachO::BIND_SPECIAL_DYLIB_FLAT_LOOKUP
284
+ : dysym.getFile ()->ordinal ;
285
+ }
285
286
286
- int16_t ordinal = dysym->isDynamicLookup () ? BIND_SPECIAL_DYLIB_FLAT_LOOKUP
287
- : dysym->getFile ()->ordinal ;
288
-
289
- if (lastBinding == nullptr ||
290
- lastBinding->ordinal != ordinal) {
291
- if (ordinal <= 0 ) {
292
- os << static_cast <uint8_t >(
293
- BIND_OPCODE_SET_DYLIB_SPECIAL_IMM |
294
- (ordinal & BIND_IMMEDIATE_MASK));
295
- } else if (ordinal <= BIND_IMMEDIATE_MASK) {
296
- os << static_cast <uint8_t >(BIND_OPCODE_SET_DYLIB_ORDINAL_IMM |
297
- ordinal);
298
- } else {
299
- os << static_cast <uint8_t >(BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB);
300
- encodeULEB128 (ordinal, os);
301
- }
302
- if (lastBinding != nullptr )
303
- lastBinding->ordinal = ordinal;
287
+ static void encodeDylibOrdinal (int16_t ordinal, raw_svector_ostream &os) {
288
+ using namespace llvm ::MachO;
289
+ if (ordinal <= 0 ) {
290
+ os << static_cast <uint8_t >(BIND_OPCODE_SET_DYLIB_SPECIAL_IMM |
291
+ (ordinal & BIND_IMMEDIATE_MASK));
292
+ } else if (ordinal <= BIND_IMMEDIATE_MASK) {
293
+ os << static_cast <uint8_t >(BIND_OPCODE_SET_DYLIB_ORDINAL_IMM | ordinal);
294
+ } else {
295
+ os << static_cast <uint8_t >(BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB);
296
+ encodeULEB128 (ordinal, os);
304
297
}
305
298
}
306
299
@@ -336,7 +329,11 @@ void BindingSection::finalizeContents() {
336
329
return a.target .getVA () < b.target .getVA ();
337
330
});
338
331
for (const BindingEntry &b : bindings) {
339
- encodeDylibOrdinal (b.dysym , &lastBinding, os);
332
+ int16_t ordinal = ordinalForDylibSymbol (*b.dysym );
333
+ if (ordinal != lastBinding.ordinal ) {
334
+ encodeDylibOrdinal (ordinal, os);
335
+ lastBinding.ordinal = ordinal;
336
+ }
340
337
if (auto *isec = b.target .section .dyn_cast <const InputSection *>()) {
341
338
encodeBinding (b.dysym , isec->parent , isec->outSecOff + b.target .offset ,
342
339
b.addend , /* isWeakBinding=*/ false , lastBinding, os);
@@ -558,7 +555,7 @@ uint32_t LazyBindingSection::encode(const DylibSymbol &sym) {
558
555
uint64_t offset = in.lazyPointers ->addr - dataSeg->firstSection ()->addr +
559
556
sym.stubsIndex * WordSize;
560
557
encodeULEB128 (offset, os);
561
- encodeDylibOrdinal (& sym, nullptr , os);
558
+ encodeDylibOrdinal (ordinalForDylibSymbol ( sym) , os);
562
559
563
560
uint8_t flags = MachO::BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM;
564
561
if (sym.isWeakRef ())
0 commit comments