Skip to content

Conversation

ellishg
Copy link
Contributor

@ellishg ellishg commented Sep 26, 2025

The test name had a typo from #140307. Fix it.

I realized cstring ordering is not supported when string deduplication is turned off. We could easily call buildCStringPriorities() in CStringSection::finalizeContents(), but I worry it might harm build performance since it creates multiple vectors and searches though maps. If users are not deduplicating strings, they probably won't care to order them, but it would be good to support this.

@llvmbot
Copy link
Member

llvmbot commented Sep 26, 2025

@llvm/pr-subscribers-lld-macho

Author: Ellis Hoag (ellishg)

Changes

The test name had a typo from #140307. Fix it.

I realized cstring ordering is not supported when string deduplication is turned off. We could easily call buildCStringPriorities() in CStringSection::finalizeContents(), but I worry it might harm build performance since it creates multiple vectors and searches though maps. If users are not deduplicating strings, they probably won't care to order them, but it would be good to support this.


Full diff: https://github.com/llvm/llvm-project/pull/160938.diff

2 Files Affected:

  • (modified) lld/MachO/SyntheticSections.cpp (+3)
  • (renamed) lld/test/MachO/order-file-cstring.s ()
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index 979a4ee6d8133..228b84db21c2a 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -1687,6 +1687,9 @@ void CStringSection::writeTo(uint8_t *buf) const {
 
 void CStringSection::finalizeContents() {
   uint64_t offset = 0;
+  // TODO: Call buildCStringPriorities() to support cstring ordering when
+  // deduplication is off, although this may negatively impact build
+  // performance.
   for (CStringInputSection *isec : inputs) {
     for (const auto &[i, piece] : llvm::enumerate(isec->pieces)) {
       if (!piece.live)
diff --git a/lld/test/MachO/ordre-file-cstring.s b/lld/test/MachO/order-file-cstring.s
similarity index 100%
rename from lld/test/MachO/ordre-file-cstring.s
rename to lld/test/MachO/order-file-cstring.s

@llvmbot
Copy link
Member

llvmbot commented Sep 26, 2025

@llvm/pr-subscribers-lld

Author: Ellis Hoag (ellishg)

Changes

The test name had a typo from #140307. Fix it.

I realized cstring ordering is not supported when string deduplication is turned off. We could easily call buildCStringPriorities() in CStringSection::finalizeContents(), but I worry it might harm build performance since it creates multiple vectors and searches though maps. If users are not deduplicating strings, they probably won't care to order them, but it would be good to support this.


Full diff: https://github.com/llvm/llvm-project/pull/160938.diff

2 Files Affected:

  • (modified) lld/MachO/SyntheticSections.cpp (+3)
  • (renamed) lld/test/MachO/order-file-cstring.s ()
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index 979a4ee6d8133..228b84db21c2a 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -1687,6 +1687,9 @@ void CStringSection::writeTo(uint8_t *buf) const {
 
 void CStringSection::finalizeContents() {
   uint64_t offset = 0;
+  // TODO: Call buildCStringPriorities() to support cstring ordering when
+  // deduplication is off, although this may negatively impact build
+  // performance.
   for (CStringInputSection *isec : inputs) {
     for (const auto &[i, piece] : llvm::enumerate(isec->pieces)) {
       if (!piece.live)
diff --git a/lld/test/MachO/ordre-file-cstring.s b/lld/test/MachO/order-file-cstring.s
similarity index 100%
rename from lld/test/MachO/ordre-file-cstring.s
rename to lld/test/MachO/order-file-cstring.s


void CStringSection::finalizeContents() {
uint64_t offset = 0;
// TODO: Call buildCStringPriorities() to support cstring ordering when
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the comment, would it make sense to log this information to the user if deduplication is not enabled and c-string ordering is specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, but unfortunately we can't tell if an orderfile contains cstrings or just normal symbols without looking at the file itself. They both use the same -order_file flag.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay that's fair. We'd have to read in the orderfile at some point when specified. In theory, we could thread that information of whether an orderfile contains cstring up to here, but it might not be worth that complexity if this specific case is something a user would even care about.

@ellishg ellishg merged commit 727ce02 into llvm:main Sep 27, 2025
7 of 9 checks passed
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
The test name had a typo from
llvm#140307. Fix it.

I realized cstring ordering is not supported when string deduplication
is turned off. We could easily call `buildCStringPriorities()` in
`CStringSection::finalizeContents()`, but I worry it might harm build
performance since it creates multiple vectors and searches though maps.
If users are not deduplicating strings, they probably won't care to
order them, but it would be good to support this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants