[lld] [lld][macho] Support order cstrings with -order_file_cstring (PR #140307)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 2 11:13:54 PDT 2025


================
@@ -388,3 +401,41 @@ macho::PriorityBuilder::buildInputSectionPriorities() {
 
   return sectionPriorities;
 }
+
+std::vector<StringPiecePair> macho::PriorityBuilder::buildCStringPriorities(
+    ArrayRef<CStringInputSection *> inputs) {
+  // Split the input strings into hold and cold sets.
+  // Order hot set based on -order_file_cstring for performance improvement;
+  // TODO: Order cold set of cstrings for compression via BP.
+  std::vector<std::pair<int, StringPiecePair>>
+      hotStringPrioritiesAndStringPieces;
+  std::vector<StringPiecePair> coldStringPieces;
+  std::vector<StringPiecePair> orderedStringPieces;
+
+  for (CStringInputSection *isec : inputs) {
+    for (const auto &[stringPieceIdx, piece] : llvm::enumerate(isec->pieces)) {
+      if (!piece.live)
+        continue;
+
+      std::optional<int> priority = getSymbolOrCStringPriority(
+          std::to_string(piece.hash), isec->getFile());
----------------
SharonXSharon wrote:

>  we still support Objective-C which commonly has : in the symbol names.

oh you're right, forgot about the objC symbol names. but on the other hand, all the existing `:` for CPU and files have already been causing this issue for ObjC symbols names...
maybe right now the best trade-off is to use `CSTR;`?

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


More information about the llvm-commits mailing list