@@ -327,9 +327,11 @@ class MipsGotSection final : public SyntheticSection {
327327 size_t startIndex = 0 ;
328328
329329 struct PageBlock {
330+ Symbol *repSym; // Representative symbol for the OutputSection
330331 size_t firstIndex;
331332 size_t count;
332- PageBlock () : firstIndex(0 ), count(0 ) {}
333+ PageBlock (Symbol *repSym = nullptr )
334+ : repSym(repSym), firstIndex(0 ), count(0 ) {}
333335 };
334336
335337 // Map output sections referenced by MIPS GOT relocations
@@ -418,61 +420,31 @@ class StringTableSection final : public SyntheticSection {
418420
419421class DynamicReloc {
420422public:
421- enum Kind {
422- // / The resulting dynamic relocation does not reference a symbol (#sym must
423- // / be nullptr) and uses #addend as the result of computeAddend(ctx).
424- AddendOnly,
425- // / The resulting dynamic relocation will not reference a symbol: #sym is
426- // / only used to compute the addend with InputSection::getRelocTargetVA().
427- // / Useful for various relative and TLS relocations (e.g. R_X86_64_TPOFF64).
428- AddendOnlyWithTargetVA,
429- // / The resulting dynamic relocation references symbol #sym from the dynamic
430- // / symbol table and uses #addend as the value of computeAddend(ctx).
431- AgainstSymbol,
432- // / The resulting dynamic relocation references symbol #sym from the dynamic
433- // / symbol table and uses InputSection::getRelocTargetVA() + #addend for the
434- // / final addend. It can be used for relocations that write the symbol VA as
435- // the addend (e.g. R_MIPS_TLS_TPREL64) but still reference the symbol.
436- AgainstSymbolWithTargetVA,
437- // / This is used by the MIPS multi-GOT implementation. It relocates
438- // / addresses of 64kb pages that lie inside the output section.
439- MipsMultiGotPage,
440- };
441- // / This constructor records a relocation against a symbol.
423+ // / This constructor records a normal relocation.
442424 DynamicReloc (RelType type, const InputSectionBase *inputSec,
443- uint64_t offsetInSec, Kind kind , Symbol &sym, int64_t addend ,
444- RelExpr expr)
425+ uint64_t offsetInSec, bool isAgainstSymbol , Symbol &sym,
426+ int64_t addend, RelExpr expr)
445427 : sym(&sym), inputSec(inputSec), offsetInSec(offsetInSec), type(type),
446- addend (addend), kind(kind), expr(expr) {}
428+ addend (addend), isAgainstSymbol(isAgainstSymbol), isFinal(false ),
429+ expr(expr) {}
447430 // / This constructor records a relative relocation with no symbol.
448431 DynamicReloc (RelType type, const InputSectionBase *inputSec,
449432 uint64_t offsetInSec, int64_t addend = 0 )
450- : sym(nullptr ), inputSec(inputSec), offsetInSec(offsetInSec), type(type),
451- addend(addend), kind(AddendOnly), expr(R_ADDEND) {}
452- // / This constructor records dynamic relocation settings used by the MIPS
453- // / multi-GOT implementation.
454- DynamicReloc (RelType type, const InputSectionBase *inputSec,
455- uint64_t offsetInSec, const OutputSection *outputSec,
456- int64_t addend)
457- : sym(nullptr ), outputSec(outputSec), inputSec(inputSec),
458- offsetInSec(offsetInSec), type(type), addend(addend),
459- kind(MipsMultiGotPage), expr(R_ADDEND) {}
433+ : DynamicReloc(type, inputSec, offsetInSec, false ,
434+ *inputSec->getCtx ().dummySym, addend, R_ADDEND) {}
460435
461436 uint64_t getOffset () const ;
462437 uint32_t getSymIndex (SymbolTableBaseSection *symTab) const ;
463- bool needsDynSymIndex () const {
464- return kind == AgainstSymbol || kind == AgainstSymbolWithTargetVA;
465- }
438+ bool needsDynSymIndex () const { return isAgainstSymbol; }
466439
467440 // / Computes the addend of the dynamic relocation. Note that this is not the
468441 // / same as the #addend member variable as it may also include the symbol
469442 // / address/the address of the corresponding GOT entry/etc.
470443 int64_t computeAddend (Ctx &) const ;
471444
472- void computeRaw (Ctx &, SymbolTableBaseSection *symt);
445+ void finalize (Ctx &, SymbolTableBaseSection *symt);
473446
474447 Symbol *sym;
475- const OutputSection *outputSec = nullptr ;
476448 const InputSectionBase *inputSec;
477449 uint64_t offsetInSec;
478450 uint64_t r_offset;
@@ -483,7 +455,15 @@ class DynamicReloc {
483455 int64_t addend;
484456
485457private:
486- Kind kind;
458+ // / Whether this was constructed with a Kind of AgainstSymbol.
459+ LLVM_PREFERRED_TYPE (bool )
460+ uint8_t isAgainstSymbol : 1;
461+
462+ // / The resulting dynamic relocation has already had its addend computed.
463+ // / Calling computeAddend() is an error.
464+ LLVM_PREFERRED_TYPE (bool )
465+ uint8_t isFinal : 1;
466+
487467 // The kind of expression used to calculate the added (required e.g. for
488468 // relative GOT relocations).
489469 RelExpr expr;
@@ -528,8 +508,8 @@ class RelocationBaseSection : public SyntheticSection {
528508 uint64_t offsetInSec, Symbol &sym, int64_t addend,
529509 RelType addendRelType, RelExpr expr) {
530510 assert (expr != R_ADDEND && " expected non-addend relocation expression" );
531- addReloc<shard>(DynamicReloc::AddendOnlyWithTargetVA , dynType, isec,
532- offsetInSec, sym, addend, expr, addendRelType);
511+ addReloc<shard>(false , dynType, isec, offsetInSec, sym, addend, expr ,
512+ addendRelType);
533513 }
534514 // / Add a dynamic relocation using the target address of \p sym as the addend
535515 // / if \p sym is non-preemptible. Otherwise add a relocation against \p sym.
@@ -538,14 +518,15 @@ class RelocationBaseSection : public SyntheticSection {
538518 uint64_t offsetInSec, Symbol &sym,
539519 RelType addendRelType);
540520 template <bool shard = false >
541- void addReloc (DynamicReloc::Kind kind , RelType dynType, InputSectionBase &sec,
521+ void addReloc (bool isAgainstSymbol , RelType dynType, InputSectionBase &sec,
542522 uint64_t offsetInSec, Symbol &sym, int64_t addend, RelExpr expr,
543523 RelType addendRelType) {
544524 // Write the addends to the relocated address if required. We skip
545525 // it if the written value would be zero.
546526 if (ctx.arg .writeAddends && (expr != R_ADDEND || addend != 0 ))
547527 sec.addReloc ({expr, addendRelType, offsetInSec, addend, &sym});
548- addReloc<shard>({dynType, &sec, offsetInSec, kind, sym, addend, expr});
528+ addReloc<shard>(
529+ {dynType, &sec, offsetInSec, isAgainstSymbol, sym, addend, expr});
549530 }
550531 bool isNeeded () const override {
551532 return !relocs.empty () ||
0 commit comments