[lld] [lld][MachO] Accept hex format for cstring hashes in order file (PR #178933)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 30 10:09:35 PST 2026
https://github.com/SharonXSharon created https://github.com/llvm/llvm-project/pull/178933
Change the cstring hash parsing in parseOrderFile() to use getAsInteger(0, hash) instead of to_integer(). This allows the order file to accept cstring hashes in both decimal (e.g., 540201826) and hexadecimal (e.g., 0x2032D362) formats.
The getAsInteger function with radix 0 auto-detects the base from the string prefix (0x for hex, otherwise decimal).
>From df69bc48c453f93ba0f37568ff3b13ef87a1f1e3 Mon Sep 17 00:00:00 2001
From: Sharon Xu <sharonxu at fb.com>
Date: Thu, 29 Jan 2026 16:25:28 -0800
Subject: [PATCH] [lld][MachO] Accept hex format for cstring hashes in order
file
Change the cstring hash parsing in parseOrderFile() to use
getAsInteger(0, hash) instead of to_integer(). This allows
the order file to accept cstring hashes in both decimal
(e.g., 540201826) and hexadecimal (e.g., 0x2032D362) formats.
The getAsInteger function with radix 0 auto-detects the base
from the string prefix (0x for hex, otherwise decimal).
---
lld/MachO/SectionPriorities.cpp | 4 +++-
lld/test/MachO/order-file-cstring.s | 8 ++++----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/lld/MachO/SectionPriorities.cpp b/lld/MachO/SectionPriorities.cpp
index b652d1ee8325f..955293fb935a9 100644
--- a/lld/MachO/SectionPriorities.cpp
+++ b/lld/MachO/SectionPriorities.cpp
@@ -355,7 +355,9 @@ void macho::PriorityBuilder::parseOrderFile(StringRef path) {
line = line.trim();
if (line.consume_front(cStringEntryPrefix)) {
uint32_t hash = 0;
- if (to_integer(line, hash))
+ // getAsInteger with base 0 auto-detects: 0x prefix for hex, otherwise
+ // decimal. Returns false on success.
+ if (!line.getAsInteger(0, hash))
cStringPriorities[hash].setPriority(prio, objectFile);
} else {
StringRef symbol = utils::getRootSymbol(line);
diff --git a/lld/test/MachO/order-file-cstring.s b/lld/test/MachO/order-file-cstring.s
index d6734308fffdf..ca3c32bb1e4f5 100644
--- a/lld/test/MachO/order-file-cstring.s
+++ b/lld/test/MachO/order-file-cstring.s
@@ -54,11 +54,11 @@
#foo2
CSTR;1433942677
#bar
-CSTR;540201826
+CSTR;0x2032D362
#bar2
CSTR;1496286555
#foo3
-CSTR;1343999025
+CSTR;0x501BCC31
# ONE_SYM-DAG: _globl_foo2
# ONE_SYM-DAG: _local_foo2
@@ -178,13 +178,13 @@ CSTR;862947621
#\t\n
CSTR;1035903177
#foo2
-CSTR;1433942677
+CSTR;0x55783A95
#@\"NSDictionary\"
CSTR;1202669430
#foo3
CSTR;1343999025
#bar
-CSTR;540201826
+CSTR;0x2032D362
#--- test.s
More information about the llvm-commits
mailing list