[PATCH] D103662: [lld][MachO] Fix function starts section

Alexander Shaposhnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 3 18:55:48 PDT 2021


alexshap created this revision.
alexshap added a reviewer: thakis.
alexshap created this object with visibility "All Users".
Herald added a subscriber: mgrang.
Herald added a reviewer: int3.
Herald added a reviewer: gkm.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.
alexshap requested review of this revision.
Herald added a project: LLVM.

This diff fixes the generation of the function starts section.
WIP.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103662

Files:
  lld/MachO/SyntheticSections.cpp


Index: lld/MachO/SyntheticSections.cpp
===================================================================
--- lld/MachO/SyntheticSections.cpp
+++ lld/MachO/SyntheticSections.cpp
@@ -592,20 +592,24 @@
 
 void FunctionStartsSection::finalizeContents() {
   raw_svector_ostream os{contents};
-  uint64_t addr = in.header->addr;
+  std::vector<uint64_t> addrs;
   for (const Symbol *sym : symtab->getSymbols()) {
     if (const auto *defined = dyn_cast<Defined>(sym)) {
-      if (!defined->isec || !isCodeSection(defined->isec) || !defined->isLive())
-        continue;
       // TODO: Add support for thumbs, in that case
       // the lowest bit of nextAddr needs to be set to 1.
-      uint64_t nextAddr = defined->getVA();
+      if (!defined->isec || !isCodeSection(defined->isec) || !defined->isLive())
+        continue;
+      addrs.push_back(defined->getVA());
+    }
+  }
+  llvm::sort(addrs);
+  uint64_t addr = in.header->addr;
+  for (uint64_t nextAddr : addrs) {
       uint64_t delta = nextAddr - addr;
       if (delta == 0)
         continue;
       encodeULEB128(delta, os);
       addr = nextAddr;
-    }
   }
   os << '\0';
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103662.349741.patch
Type: text/x-patch
Size: 1145 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210604/5012173a/attachment.bin>


More information about the llvm-commits mailing list