Simplify decoupling between RuntimeDyld/RuntimeDyldChecker, add 'got_addr' util.

This patch reduces the number of functions in the interface between RuntimeDyld
and RuntimeDyldChecker by combining "GetXAddress" and "GetXContent" functions
into "GetXInfo" functions that return a struct describing both the address and
content. The GetStubOffset function is also replaced with a pair of utilities,
GetStubInfo and GetGOTInfo, that fit the new scheme. For RuntimeDyld both of
these functions will return the same result, but for the new JITLink linker
(https://reviews.llvm.org/D58704) these will provide the addresses of PLT stubs
and GOT entries respectively.

For JITLink's use, a 'got_addr' utility has been added to the rtdyld-check
language, and the syntax of 'got_addr' and 'stub_addr' has been changed: both
functions now take two arguments, a 'stub container name' and a target symbol
name. For llvm-rtdyld/RuntimeDyld the stub container name is the object file
name and section name, separated by a slash. E.g.:

rtdyld-check: *{8}(stub_addr(foo.o/__text, y)) = y

For the upcoming llvm-jitlink utility, which creates stubs on a per-file basis
rather than a per-section basis, the container name is just the file name. E.g.:

jitlink-check: *{8}(got_addr(foo.o, y)) = y
llvm-svn: 358295
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
index dee8ecd..2fd677a 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
@@ -386,7 +386,8 @@
 
         // If this is a named stub, just call NotifyStubEmitted.
         if (VR.SymbolName) {
-          NotifyStubEmitted(FileName, SectionName, VR.SymbolName, StubAddr);
+          NotifyStubEmitted(FileName, SectionName, VR.SymbolName, SectionID,
+                            StubAddr);
           continue;
         }
 
@@ -396,7 +397,8 @@
           auto &GSTEntry = GSTMapEntry.second;
           if (GSTEntry.getSectionID() == VR.SectionID &&
               GSTEntry.getOffset() == VR.Offset) {
-            NotifyStubEmitted(FileName, SectionName, SymbolName, StubAddr);
+            NotifyStubEmitted(FileName, SectionName, SymbolName, SectionID,
+                              StubAddr);
             break;
           }
         }
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
index 3a293c0..e801ebd 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
@@ -319,22 +319,22 @@
     return std::make_pair(EvalResult(NextPC), RemainingExpr);
   }
 
-  // Evaluate a call to stub_addr.
+  // Evaluate a call to stub_addr/got_addr.
   // Look up and return the address of the stub for the given
   // (<file name>, <section name>, <symbol name>) tuple.
   // On success, returns a pair containing the stub address, plus the expression
   // remaining to be evaluated.
-  std::pair<EvalResult, StringRef> evalStubAddr(StringRef Expr,
-                                                ParseContext PCtx) const {
+  std::pair<EvalResult, StringRef>
+  evalStubOrGOTAddr(StringRef Expr, ParseContext PCtx, bool IsStubAddr) const {
     if (!Expr.startswith("("))
       return std::make_pair(unexpectedToken(Expr, Expr, "expected '('"), "");
     StringRef RemainingExpr = Expr.substr(1).ltrim();
 
     // Handle file-name specially, as it may contain characters that aren't
     // legal for symbols.
-    StringRef FileName;
+    StringRef StubContainerName;
     size_t ComaIdx = RemainingExpr.find(',');
-    FileName = RemainingExpr.substr(0, ComaIdx).rtrim();
+    StubContainerName = RemainingExpr.substr(0, ComaIdx).rtrim();
     RemainingExpr = RemainingExpr.substr(ComaIdx).ltrim();
 
     if (!RemainingExpr.startswith(","))
@@ -342,14 +342,6 @@
           unexpectedToken(RemainingExpr, Expr, "expected ','"), "");
     RemainingExpr = RemainingExpr.substr(1).ltrim();
 
-    StringRef SectionName;
-    std::tie(SectionName, RemainingExpr) = parseSymbol(RemainingExpr);
-
-    if (!RemainingExpr.startswith(","))
-      return std::make_pair(
-          unexpectedToken(RemainingExpr, Expr, "expected ','"), "");
-    RemainingExpr = RemainingExpr.substr(1).ltrim();
-
     StringRef Symbol;
     std::tie(Symbol, RemainingExpr) = parseSymbol(RemainingExpr);
 
@@ -360,8 +352,8 @@
 
     uint64_t StubAddr;
     std::string ErrorMsg = "";
-    std::tie(StubAddr, ErrorMsg) = Checker.getStubAddrFor(
-        FileName, SectionName, Symbol, PCtx.IsInsideLoad);
+    std::tie(StubAddr, ErrorMsg) = Checker.getStubOrGOTAddrFor(
+        StubContainerName, Symbol, PCtx.IsInsideLoad, IsStubAddr);
 
     if (ErrorMsg != "")
       return std::make_pair(EvalResult(ErrorMsg), "");
@@ -421,7 +413,9 @@
     else if (Symbol == "next_pc")
       return evalNextPC(RemainingExpr, PCtx);
     else if (Symbol == "stub_addr")
-      return evalStubAddr(RemainingExpr, PCtx);
+      return evalStubOrGOTAddr(RemainingExpr, PCtx, true);
+    else if (Symbol == "got_addr")
+      return evalStubOrGOTAddr(RemainingExpr, PCtx, false);
     else if (Symbol == "section_addr")
       return evalSectionAddr(RemainingExpr, PCtx);
 
@@ -676,22 +670,15 @@
 }
 
 RuntimeDyldCheckerImpl::RuntimeDyldCheckerImpl(
-                      IsSymbolValidFunction IsSymbolValid,
-                      GetSymbolAddressFunction GetSymbolAddress,
-                      GetSymbolContentFunction GetSymbolContent,
-                      GetSectionLoadAddressFunction GetSectionLoadAddress,
-                      GetSectionContentFunction GetSectionContent,
-                      GetStubOffsetInSectionFunction GetStubOffsetInSection,
-                      support::endianness Endianness,
-                      MCDisassembler *Disassembler,
-                      MCInstPrinter *InstPrinter,
-                      raw_ostream &ErrStream)
+    IsSymbolValidFunction IsSymbolValid, GetSymbolInfoFunction GetSymbolInfo,
+    GetSectionInfoFunction GetSectionInfo, GetStubInfoFunction GetStubInfo,
+    GetGOTInfoFunction GetGOTInfo, support::endianness Endianness,
+    MCDisassembler *Disassembler, MCInstPrinter *InstPrinter,
+    raw_ostream &ErrStream)
     : IsSymbolValid(std::move(IsSymbolValid)),
-      GetSymbolAddress(std::move(GetSymbolAddress)),
-      GetSymbolContent(std::move(GetSymbolContent)),
-      GetSectionLoadAddress(std::move(GetSectionLoadAddress)),
-      GetSectionContent(std::move(GetSectionContent)),
-      GetStubOffsetInSection(std::move(GetStubOffsetInSection)),
+      GetSymbolInfo(std::move(GetSymbolInfo)),
+      GetSectionInfo(std::move(GetSectionInfo)),
+      GetStubInfo(std::move(GetStubInfo)), GetGOTInfo(std::move(GetGOTInfo)),
       Endianness(Endianness), Disassembler(Disassembler),
       InstPrinter(InstPrinter), ErrStream(ErrStream) {}
 
@@ -743,22 +730,23 @@
 }
 
 uint64_t RuntimeDyldCheckerImpl::getSymbolLocalAddr(StringRef Symbol) const {
-  auto Contents = GetSymbolContent(Symbol);
-  if (!Contents) {
-    logAllUnhandledErrors(Contents.takeError(), errs(), "RTDyldChecker: ");
+  auto SymInfo = GetSymbolInfo(Symbol);
+  if (!SymInfo) {
+    logAllUnhandledErrors(SymInfo.takeError(), errs(), "RTDyldChecker: ");
     return 0;
   }
-  return static_cast<uint64_t>(reinterpret_cast<uintptr_t>(Contents->data()));
+  return static_cast<uint64_t>(
+      reinterpret_cast<uintptr_t>(SymInfo->Content.data()));
 }
 
 uint64_t RuntimeDyldCheckerImpl::getSymbolRemoteAddr(StringRef Symbol) const {
-  auto Addr = GetSymbolAddress(Symbol);
-  if (!Addr) {
-    logAllUnhandledErrors(Addr.takeError(), errs(), "RTDyldChecker: ");
+  auto SymInfo = GetSymbolInfo(Symbol);
+  if (!SymInfo) {
+    logAllUnhandledErrors(SymInfo.takeError(), errs(), "RTDyldChecker: ");
     return 0;
   }
 
-  return *Addr;
+  return SymInfo->TargetAddress;
 }
 
 uint64_t RuntimeDyldCheckerImpl::readMemoryAtAddr(uint64_t SrcAddr,
@@ -781,87 +769,79 @@
 }
 
 StringRef RuntimeDyldCheckerImpl::getSymbolContent(StringRef Symbol) const {
-  auto Content = GetSymbolContent(Symbol);
-  if (!Content) {
-    logAllUnhandledErrors(Content.takeError(), errs(), "RTDyldChecker: ");
+  auto SymInfo = GetSymbolInfo(Symbol);
+  if (!SymInfo) {
+    logAllUnhandledErrors(SymInfo.takeError(), errs(), "RTDyldChecker: ");
     return StringRef();
   }
-  return *Content;
+  return SymInfo->Content;
 }
 
 std::pair<uint64_t, std::string> RuntimeDyldCheckerImpl::getSectionAddr(
     StringRef FileName, StringRef SectionName, bool IsInsideLoad) const {
 
-  uint64_t Addr = 0;
-  std::string ErrMsg;
-
-  // If this address is being looked up in "load" mode, return the content
-  // pointer.
-  if (IsInsideLoad) {
-    if (auto Content = GetSectionContent(FileName, SectionName))
-      Addr = pointerToJITTargetAddress(Content->data());
-    else {
-      raw_string_ostream ErrMsgStream(ErrMsg);
-      logAllUnhandledErrors(Content.takeError(), ErrMsgStream,
-                            "RTDyldChecker: ");
-    }
-    return std::make_pair(Addr, std::move(ErrMsg));
-  }
-
-  // ... otherwise return the target pointer.
-  if (auto LoadAddr = GetSectionLoadAddress(FileName, SectionName))
-    Addr = *LoadAddr;
-  else
-    return std::make_pair(Addr, ("Section (" + FileName + ", " +
-                                 SectionName + ") does not exist").str());
-
-  return std::make_pair(Addr, std::move(ErrMsg));
-}
-
-std::pair<uint64_t, std::string> RuntimeDyldCheckerImpl::getStubAddrFor(
-    StringRef FileName, StringRef SectionName, StringRef SymbolName,
-    bool IsInsideLoad) const {
-
-  auto SectionAddr = getSectionAddr(FileName, SectionName, IsInsideLoad);
-
-  if (!SectionAddr.second.empty())
-    return SectionAddr;
-
-  auto StubOffset = GetStubOffsetInSection(FileName, SectionName, SymbolName);
-
-  if (!StubOffset) {
+  auto SecInfo = GetSectionInfo(FileName, SectionName);
+  if (!SecInfo) {
     std::string ErrMsg;
     {
       raw_string_ostream ErrMsgStream(ErrMsg);
-      logAllUnhandledErrors(StubOffset.takeError(), ErrMsgStream,
+      logAllUnhandledErrors(SecInfo.takeError(), ErrMsgStream,
+                            "RTDyldChecker: ");
+    }
+    return std::make_pair(0, std::move(ErrMsg));
+  }
+
+  // If this address is being looked up in "load" mode, return the content
+  // pointer, otherwise return the target address.
+
+  uint64_t Addr = 0;
+
+  if (IsInsideLoad)
+    Addr = pointerToJITTargetAddress(SecInfo->Content.data());
+  else
+    Addr = SecInfo->TargetAddress;
+
+  return std::make_pair(Addr, "");
+}
+
+std::pair<uint64_t, std::string> RuntimeDyldCheckerImpl::getStubOrGOTAddrFor(
+    StringRef StubContainerName, StringRef SymbolName, bool IsInsideLoad,
+    bool IsStubAddr) const {
+
+  auto StubInfo = IsStubAddr ? GetStubInfo(StubContainerName, SymbolName)
+                             : GetGOTInfo(StubContainerName, SymbolName);
+
+  if (!StubInfo) {
+    std::string ErrMsg;
+    {
+      raw_string_ostream ErrMsgStream(ErrMsg);
+      logAllUnhandledErrors(StubInfo.takeError(), ErrMsgStream,
                             "RTDyldChecker: ");
     }
     return std::make_pair((uint64_t)0, std::move(ErrMsg));
   }
 
-  return std::make_pair(SectionAddr.first + *StubOffset, "");
+  uint64_t Addr = 0;
+
+  if (IsInsideLoad)
+    Addr = pointerToJITTargetAddress(StubInfo->Content.data());
+  else
+    Addr = StubInfo->TargetAddress;
+
+  return std::make_pair(Addr, "");
 }
 
 RuntimeDyldChecker::RuntimeDyldChecker(
-                      IsSymbolValidFunction IsSymbolValid,
-                      GetSymbolAddressFunction GetSymbolAddress,
-                      GetSymbolContentFunction GetSymbolContent,
-                      GetSectionLoadAddressFunction GetSectionLoadAddress,
-                      GetSectionContentFunction GetSectionContent,
-                      GetStubOffsetInSectionFunction GetStubOffsetInSection,
-                      support::endianness Endianness,
-                      MCDisassembler *Disassembler,
-                      MCInstPrinter *InstPrinter,
-                      raw_ostream &ErrStream)
+    IsSymbolValidFunction IsSymbolValid, GetSymbolInfoFunction GetSymbolInfo,
+    GetSectionInfoFunction GetSectionInfo, GetStubInfoFunction GetStubInfo,
+    GetGOTInfoFunction GetGOTInfo, support::endianness Endianness,
+    MCDisassembler *Disassembler, MCInstPrinter *InstPrinter,
+    raw_ostream &ErrStream)
     : Impl(::llvm::make_unique<RuntimeDyldCheckerImpl>(
-                                            std::move(IsSymbolValid),
-                                            std::move(GetSymbolAddress),
-                                            std::move(GetSymbolContent),
-                                            std::move(GetSectionLoadAddress),
-                                            std::move(GetSectionContent),
-                                            std::move(GetStubOffsetInSection),
-                                            Endianness, Disassembler,
-                                            InstPrinter, ErrStream)) {}
+          std::move(IsSymbolValid), std::move(GetSymbolInfo),
+          std::move(GetSectionInfo), std::move(GetStubInfo),
+          std::move(GetGOTInfo), Endianness, Disassembler, InstPrinter,
+          ErrStream)) {}
 
 RuntimeDyldChecker::~RuntimeDyldChecker() {}
 
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCheckerImpl.h b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCheckerImpl.h
index 0debd29..ac9d4d4 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCheckerImpl.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCheckerImpl.h
@@ -19,31 +19,18 @@
 
   using IsSymbolValidFunction =
     RuntimeDyldChecker::IsSymbolValidFunction;
-  using GetSymbolAddressFunction =
-    RuntimeDyldChecker::GetSymbolAddressFunction;
-  using GetSymbolContentFunction =
-    RuntimeDyldChecker::GetSymbolContentFunction;
-
-  using GetSectionLoadAddressFunction =
-    RuntimeDyldChecker::GetSectionLoadAddressFunction;
-  using GetSectionContentFunction =
-    RuntimeDyldChecker::GetSectionContentFunction;
-
-  using GetStubOffsetInSectionFunction =
-    RuntimeDyldChecker::GetStubOffsetInSectionFunction;
+  using GetSymbolInfoFunction = RuntimeDyldChecker::GetSymbolInfoFunction;
+  using GetSectionInfoFunction = RuntimeDyldChecker::GetSectionInfoFunction;
+  using GetStubInfoFunction = RuntimeDyldChecker::GetStubInfoFunction;
+  using GetGOTInfoFunction = RuntimeDyldChecker::GetGOTInfoFunction;
 
 public:
   RuntimeDyldCheckerImpl(
-                      IsSymbolValidFunction IsSymbolValid,
-                      GetSymbolAddressFunction GetSymbolAddress,
-                      GetSymbolContentFunction GetSymbolContent,
-                      GetSectionLoadAddressFunction GetSectionLoadAddress,
-                      GetSectionContentFunction GetSectionContent,
-                      GetStubOffsetInSectionFunction GetStubOffsetInSection,
-                      support::endianness Endianness,
-                      MCDisassembler *Disassembler,
-                      MCInstPrinter *InstPrinter,
-                      llvm::raw_ostream &ErrStream);
+      IsSymbolValidFunction IsSymbolValid, GetSymbolInfoFunction GetSymbolInfo,
+      GetSectionInfoFunction GetSectionInfo, GetStubInfoFunction GetStubInfo,
+      GetGOTInfoFunction GetGOTInfo, support::endianness Endianness,
+      MCDisassembler *Disassembler, MCInstPrinter *InstPrinter,
+      llvm::raw_ostream &ErrStream);
 
   bool check(StringRef CheckExpr) const;
   bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const;
@@ -66,19 +53,17 @@
                                                   StringRef SectionName,
                                                   bool IsInsideLoad) const;
 
-  std::pair<uint64_t, std::string> getStubAddrFor(StringRef FileName,
-                                                  StringRef SectionName,
-                                                  StringRef Symbol,
-                                                  bool IsInsideLoad) const;
+  std::pair<uint64_t, std::string>
+  getStubOrGOTAddrFor(StringRef StubContainerName, StringRef Symbol,
+                      bool IsInsideLoad, bool IsStubAddr) const;
 
   Optional<uint64_t> getSectionLoadAddress(void *LocalAddr) const;
 
   IsSymbolValidFunction IsSymbolValid;
-  GetSymbolAddressFunction GetSymbolAddress;
-  GetSymbolContentFunction GetSymbolContent;
-  GetSectionLoadAddressFunction GetSectionLoadAddress;
-  GetSectionContentFunction GetSectionContent;
-  GetStubOffsetInSectionFunction GetStubOffsetInSection;
+  GetSymbolInfoFunction GetSymbolInfo;
+  GetSectionInfoFunction GetSectionInfo;
+  GetStubInfoFunction GetStubInfo;
+  GetGOTInfoFunction GetGOTInfo;
   support::endianness Endianness;
   MCDisassembler *Disassembler;
   MCInstPrinter *InstPrinter;
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h
index ec4809f..ef0784e 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h
@@ -60,7 +60,7 @@
   void resolveBPFRelocation(const SectionEntry &Section, uint64_t Offset,
                             uint64_t Value, uint32_t Type, int64_t Addend);
 
-  unsigned getMaxStubSize() override {
+  unsigned getMaxStubSize() const override {
     if (Arch == Triple::aarch64 || Arch == Triple::aarch64_be)
       return 20; // movz; movk; movk; movk; br
     if (Arch == Triple::arm || Arch == Triple::thumb)
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
index 615a728..68b3468 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
@@ -312,7 +312,7 @@
     RuntimeDyld::NotifyStubEmittedFunction;
   NotifyStubEmittedFunction NotifyStubEmitted;
 
-  virtual unsigned getMaxStubSize() = 0;
+  virtual unsigned getMaxStubSize() const = 0;
   virtual unsigned getStubAlignment() = 0;
 
   bool HasError;
@@ -485,8 +485,8 @@
   }
 
   StringRef getSectionContent(unsigned SectionID) const {
-    return StringRef(reinterpret_cast<char*>(Sections[SectionID].getAddress()),
-                     Sections[SectionID].getSize());
+    return StringRef(reinterpret_cast<char *>(Sections[SectionID].getAddress()),
+                     Sections[SectionID].getStubOffset() + getMaxStubSize());
   }
 
   uint8_t* getSymbolLocalAddress(StringRef Name) const {
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
index d43aec6..40910be 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
@@ -27,7 +27,7 @@
                       JITSymbolResolver &Resolver)
       : RuntimeDyldCOFF(MM, Resolver) {}
 
-  unsigned getMaxStubSize() override {
+  unsigned getMaxStubSize() const override {
     return 8; // 2-byte jmp instruction + 32-bit relative address + 2 byte pad
   }
 
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h
index 24b77d5..bb2e962 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h
@@ -50,7 +50,7 @@
                        JITSymbolResolver &Resolver)
       : RuntimeDyldCOFF(MM, Resolver) {}
 
-  unsigned getMaxStubSize() override {
+  unsigned getMaxStubSize() const override {
     return 16; // 8-byte load instructions, 4-byte jump, 4-byte padding
   }
 
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h
index 07a3e7b..d2d7453 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h
@@ -61,7 +61,7 @@
   unsigned getStubAlignment() override { return 1; }
 
   // 2-byte jmp instruction + 32-bit relative address + 64-bit absolute jump
-  unsigned getMaxStubSize() override { return 14; }
+  unsigned getMaxStubSize() const override { return 14; }
 
   // The target location for the relocation is described by RE.SectionID and
   // RE.Offset.  RE.SectionID can be used to find the SectionEntry.  Each
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h
index c994e30..f2ee1b0 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h
@@ -26,7 +26,7 @@
                           JITSymbolResolver &Resolver)
       : RuntimeDyldMachOCRTPBase(MM, Resolver) {}
 
-  unsigned getMaxStubSize() override { return 8; }
+  unsigned getMaxStubSize() const override { return 8; }
 
   unsigned getStubAlignment() override { return 8; }
 
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h
index acc347a..b7649e9 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOARM.h
@@ -29,7 +29,7 @@
                       JITSymbolResolver &Resolver)
     : RuntimeDyldMachOCRTPBase(MM, Resolver) {}
 
-  unsigned getMaxStubSize() override { return 8; }
+  unsigned getMaxStubSize() const override { return 8; }
 
   unsigned getStubAlignment() override { return 4; }
 
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h
index 4d216e8..f0de27b 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOI386.h
@@ -26,7 +26,7 @@
                        JITSymbolResolver &Resolver)
       : RuntimeDyldMachOCRTPBase(MM, Resolver) {}
 
-  unsigned getMaxStubSize() override { return 0; }
+  unsigned getMaxStubSize() const override { return 0; }
 
   unsigned getStubAlignment() override { return 1; }
 
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h
index 0700f9a..249f8dc 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOX86_64.h
@@ -26,7 +26,7 @@
                          JITSymbolResolver &Resolver)
       : RuntimeDyldMachOCRTPBase(MM, Resolver) {}
 
-  unsigned getMaxStubSize() override { return 8; }
+  unsigned getMaxStubSize() const override { return 8; }
 
   unsigned getStubAlignment() override { return 1; }