[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:36:55 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;
+ auto it = cStringPriorities.find(hash);
+ if (it == cStringPriorities.end())
+ cStringPriorities[hash] = ++priority;
+ else
+ assert(it->second <= priority);
----------------
SharonXSharon wrote:
`buildCStringPriorities` function will be called twice for MachO, one is for the `__cstring` section and the other is for the`__objc_methname` section which is essentially also a cstring section but dedicated for objc method names; but `parseOrderFileCString` should only be called once.
I guess your point is the assert is unnecessary?
https://github.com/llvm/llvm-project/pull/140307
More information about the llvm-commits
mailing list