Index: lld/ELF/SyntheticSections.h
--- lld/ELF/SyntheticSections.h.orig
+++ lld/ELF/SyntheticSections.h
@@ -374,6 +374,31 @@ class MipsGotSection final : public SyntheticSection {
   bool tryMergeGots(FileGot & dst, FileGot & src, bool isPrimary);
 };
 
+#if defined(__OpenBSD__)
+class MipsStubsSection final : public SyntheticSection {
+  static constexpr size_t stubNormalSize = 16;
+  static constexpr size_t stubBigSize = 20;
+
+public:
+  MipsStubsSection(Ctx &);
+  void addSymbols();
+  void recordCall(const Symbol &sym) { callOnly.try_emplace(&sym, true); }
+  void exclude(const Symbol &sym) { callOnly[&sym] = false; }
+  std::optional<uint64_t> getStubVA(const Symbol &sym) const;
+  size_t getSize() const override { return entries.size() * stubSize; }
+  bool isNeeded() const override { return !entries.empty(); }
+  void finalizeContents() override;
+  void writeTo(uint8_t *buf) override;
+
+private:
+  SmallVector<const Symbol *, 0> entries;
+  llvm::DenseMap<const Symbol *, uint32_t> indices;
+  // False entries record exclusions that later calls must not override.
+  llvm::DenseMap<const Symbol *, bool> callOnly;
+  size_t stubSize = stubNormalSize;
+};
+#endif
+
 class GotPltSection final : public SyntheticSection {
 public:
   GotPltSection(Ctx &);
@@ -439,6 +464,11 @@ class DynamicReloc { (public)
   uint64_t getOffset() const;
   uint32_t getSymIndex(SymbolTableBaseSection *symTab) const;
   bool needsDynSymIndex() const { return isAgainstSymbol; }
+  void convertToRelative(RelType relativeRel) {
+    type = relativeRel;
+    isAgainstSymbol = false;
+    expr = R_ABS;
+  }
 
   /// Computes the addend of the dynamic relocation. Note that this is not the
   /// same as the #addend member variable as it may also include the symbol
@@ -663,6 +693,7 @@ class SymbolTableBaseSection : public SyntheticSection
   void finalizeContents() override;
   size_t getSize() const override { return getNumSymbols() * entsize; }
   void addSymbol(Symbol *sym);
+  void addLocalSectionSymbol(Symbol *sym);
   unsigned getNumSymbols() const { return symbols.size() + 1; }
   size_t getSymbolIndex(const Symbol &sym);
   ArrayRef<SymbolTableEntry> getSymbols() const { return symbols; }
@@ -672,6 +703,7 @@ class SymbolTableBaseSection : public SyntheticSection
 
   // A vector of symbols and their string table offsets.
   SmallVector<SymbolTableEntry, 0> symbols;
+  size_t numLocalDynamicSymbols = 0;
 
   StringTableSection &strTabSec;
 
@@ -1329,7 +1361,11 @@ void addVerneed(Ctx &, Symbol &ss);
 // placed in it.
 struct PhdrEntry {
   PhdrEntry(Ctx &ctx, unsigned type, unsigned flags)
+#ifdef __OpenBSD__
+      : p_align(type == llvm::ELF::PT_LOAD ? ctx.arg.textAlignPageSize : 0),
+#else
       : p_align(type == llvm::ELF::PT_LOAD ? ctx.arg.maxPageSize : 0),
+#endif
         p_type(type), p_flags(flags) {}
   void add(OutputSection *sec);
 
