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

via llvm-commits llvm-commits at lists.llvm.org
Mon May 19 10:47:27 PDT 2025


================
@@ -388,3 +388,74 @@ macho::PriorityBuilder::buildInputSectionPriorities() {
 
   return sectionPriorities;
 }
+
+void macho::PriorityBuilder::parseOrderFileCString(StringRef path) {
+  std::optional<MemoryBufferRef> buffer = readFile(path);
+  if (!buffer) {
+    error("Could not read cstring order file at " + path);
+    return;
+  }
+  MemoryBufferRef mbref = *buffer;
+  int priority = std::numeric_limits<int>::min();
+  for (StringRef line : args::getLines(mbref)) {
+    if (line.empty())
+      continue;
+    uint32_t hash = 0;
+    if (!to_integer(line, hash))
+      continue;
----------------
SharonXSharon wrote:

Yea I guess we don't want to exit just because we encounter an invalid line?
The hash is indeed a hex, the to_integer should be true for parsing a hex number. The hash we are using is the existing hash lld use for cstring literal dedup, i.e
```
uint32_t hash = xxh3_64bits(str) & 0x7fffffff;
``` 
in https://github.com/llvm/llvm-project/blob/4d0a7358771e3fe0009c7a2fcfb7e0a5c9bb86f4/lld/MachO/SyntheticSections.cpp#L1803

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


More information about the llvm-commits mailing list