[lld] [lld][macho] Support order cstrings with -order_file_cstring (PR #140307)
Ellis Hoag via llvm-commits
llvm-commits at lists.llvm.org
Wed May 28 08:19:11 PDT 2025
================
@@ -330,10 +334,19 @@ void macho::PriorityBuilder::parseOrderFile(StringRef path) {
break;
}
}
- symbol = line.trim();
- if (!symbol.empty()) {
- SymbolPriorityEntry &entry = priorities[symbol];
+ // The rest of the line is either <symbol name> or
+ // CStringEntryPrefix<cstring hash>
+ if (line.starts_with(CStringEntryPrefix)) {
+ StringRef possibleHash = line.drop_front(CStringEntryPrefix.size());
+ uint32_t hash = 0;
+ if (to_integer(possibleHash, hash))
+ line = possibleHash;
+ }
+ symbolOrCStrHash = line.trim();
+
+ if (!symbolOrCStrHash.empty()) {
+ SymbolPriorityEntry &entry = priorities[symbolOrCStrHash];
----------------
ellishg wrote:
I think this is a good place to report an error if the orderfile cannot be parsed. It might take some refactoring to avoid code duplication
```suggestion
// The rest of the line is either <symbol name> or
// CStringEntryPrefix<cstring hash>
if (line.consume_front(CStringEntryPrefix)) {
uint32_t hash;
if (!line.consume_integer(/*Radix=*/0, hash))
// report error
if (!line.trim().empty())
// report error
SymbolPriorityEntry &entry = cstrPriorities[hash];
// assign priority and return?
}
symbol = line.trim();
if (!symbol.empty()) {
SymbolPriorityEntry &entry = priorities[symbol];
```
https://github.com/llvm/llvm-project/pull/140307
More information about the llvm-commits
mailing list