[llvm] Add support for mach-o symbol stubs. (PR #225155)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 13:50:43 PDT 2026


================
@@ -66,12 +68,115 @@ static std::vector<uint8_t> getUUID(const object::ObjectFile &Obj) {
   return UUID;
 }
 
+/// Create function information entries for Mach-O symbol stubs.
+///
+/// Symbol stubs are small chunks of code, all with the same fixed size, that
+/// resolves a function pointer on first call and then jumps to the resolved
+/// function on subsequent calls for functions that live in another shared
+/// library. The stubs are stored in sections whose type is S_SYMBOL_STUBS and
+/// the size of a single stub is stored in the "reserved2" field of the section
+/// header. These stubs have no entries in the symbol table of their own, so
+/// they end up being attributed to whatever function precedes them unless they
+/// are synthesized here.
+///
+/// The name of the function a stub jumps to is found using the indirect symbol
+/// table from the LC_DYSYMTAB load command. The "reserved1" field of the
+/// section header contains the index of the indirect symbol table entry that
+/// describes the first stub in the section, and each subsequent stub is
+/// described by the entry that follows. Each indirect symbol table entry is an
+/// index into the symbol table where the matching undefined (N_UNDF) symbol
+/// supplies the name to use for the stub. Each name gets a "symbol stub for: "
+/// prefix prepended to it so that symbolication makes it clear that the address
+/// is the stub for a function and not the function itself.
+///
+/// \returns The number of function infos that were added to \a Gsym.
+static uint64_t addMachOSymbolStubs(const object::MachOObjectFile &MachO,
+                                    OutputAggregator &Out, GsymCreator &Gsym) {
+  const MachO::dysymtab_command Dysymtab = MachO.getDysymtabLoadCommand();
+  if (Dysymtab.nindirectsyms == 0)
----------------
alx32 wrote:

Does a dSYM ever have an `LC_DYSYMTAB`? If not, does this path only do anything when someone converts the linked binary rather than the dSYM? Is that the intended behavior ? 


https://github.com/llvm/llvm-project/pull/225155


More information about the llvm-commits mailing list