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

Alexander Shaposhnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 3 19:07:15 PDT 2021


alexshap updated this revision to Diff 349745.
alexshap edited the summary of this revision.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103662/new/

https://reviews.llvm.org/D103662

Files:
  lld/MachO/SyntheticSections.cpp
  lld/test/MachO/function-starts.s


Index: lld/test/MachO/function-starts.s
===================================================================
--- lld/test/MachO/function-starts.s
+++ lld/test/MachO/function-starts.s
@@ -13,9 +13,9 @@
 # BASIC-NEXT:  [[#%x,F1:]] g F __TEXT,__text _f1
 # BASIC-NEXT:  [[#%x,F2:]] g F __TEXT,__text _f2
 # BASIC-LABEL: basic:
-# BASIC:       [[#MAIN]]
 # BASIC:       [[#F1]]
 # BASIC:       [[#F2]]
+# BASIC:       [[#MAIN]]
 
 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/alias.s -o %t/alias.o
 # RUN: %lld %t/alias.o -o %t/alias
@@ -28,8 +28,8 @@
 # ALIAS-NEXT:  [[#%x,MAIN:]] g F __TEXT,__text _main
 # ALIAS-NEXT:  [[#%x,F1:]] g F __TEXT,__text _f1
 # ALIAS-LABEL: alias:
-# ALIAS:       [[#MAIN]]
 # ALIAS:       [[#F1]]
+# ALIAS:       [[#MAIN]]
 
 # RUN: %lld %t/basic.o -no_function_starts -o %t/basic-no-function-starts
 # RUN: llvm-objdump --macho --function-starts %t/basic-no-function-starts | FileCheck %s --check-prefix=NO-FUNCTION-STARTS
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.349745.patch
Type: text/x-patch
Size: 2111 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210604/f8f851f4/attachment-0001.bin>


More information about the llvm-commits mailing list