[lld] 2828a54 - [lld-macho] Don't support relocations in cstring sections

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 5 11:14:20 PST 2023


Author: Jez Ng
Date: 2023-01-05T14:14:11-05:00
New Revision: 2828a54996c407a3b5f5435da8fc9208c5e0ddd1

URL: https://github.com/llvm/llvm-project/commit/2828a54996c407a3b5f5435da8fc9208c5e0ddd1
DIFF: https://github.com/llvm/llvm-project/commit/2828a54996c407a3b5f5435da8fc9208c5e0ddd1.diff

LOG: [lld-macho] Don't support relocations in cstring sections

We can technically handle them, but since they shouldn't come up in any
real-world programs (since ld64 dedups strings unconditionally), there's
no reason to support them.

It's a thoroughly untested code path too -- as evidenced by the fact
that the only test this change breaks is one that verifies that we
reject relocations when dedup'ing. There is no test that covers the case
where we handle relocations in cstring sections when dedup is disabled.

Reviewed By: #lld-macho, oontvoo, keith, thakis

Differential Revision: https://reviews.llvm.org/D141025

Added: 
    

Modified: 
    lld/MachO/InputFiles.cpp
    lld/test/MachO/invalid/cstring-dedup.s

Removed: 
    


################################################################################
diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 6088572cab0b2..b7d3379a12bed 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -343,23 +343,20 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
     };
 
     if (sectionType(sec.flags) == S_CSTRING_LITERALS) {
-      if (sec.nreloc && config->dedupStrings)
-        fatal(toString(this) + " contains relocations in " + sec.segname + "," +
-              sec.sectname +
-              ", so LLD cannot deduplicate strings. Try re-running with "
-              "--no-deduplicate-strings.");
-
-      InputSection *isec = make<CStringInputSection>(
-          section, data, align,
-          /*dedupLiterals=*/name == section_names::objcMethname ||
-              config->dedupStrings);
+      if (sec.nreloc)
+        fatal(toString(this) + ": " + sec.segname + "," + sec.sectname +
+              " contains relocations, which is unsupported");
+      bool dedupLiterals =
+          name == section_names::objcMethname || config->dedupStrings;
+      InputSection *isec =
+          make<CStringInputSection>(section, data, align, dedupLiterals);
       // FIXME: parallelize this?
       cast<CStringInputSection>(isec)->splitIntoPieces();
       section.subsections.push_back({0, isec});
     } else if (isWordLiteralSection(sec.flags)) {
       if (sec.nreloc)
-        fatal(toString(this) + " contains unsupported relocations in " +
-              sec.segname + "," + sec.sectname);
+        fatal(toString(this) + ": " + sec.segname + "," + sec.sectname +
+              " contains relocations, which is unsupported");
       InputSection *isec = make<WordLiteralInputSection>(section, data, align);
       section.subsections.push_back({0, isec});
     } else if (auto recordSize = getRecordSize(segname, name)) {

diff  --git a/lld/test/MachO/invalid/cstring-dedup.s b/lld/test/MachO/invalid/cstring-dedup.s
index 9f5aaaf55bb53..b6ef32531b66f 100644
--- a/lld/test/MachO/invalid/cstring-dedup.s
+++ b/lld/test/MachO/invalid/cstring-dedup.s
@@ -11,7 +11,7 @@
 # RUN: not %lld -dylib %t/relocs.o 2>&1 | FileCheck %s --check-prefix=RELOCS
 
 # TERM:   not-terminated.o:(__cstring+0x4): string is not null terminated
-# RELOCS: relocs.o contains relocations in __TEXT,__cstring, so LLD cannot deduplicate strings. Try re-running with --no-deduplicate-strings.
+# RELOCS: error: {{.*}}relocs.o: __TEXT,__cstring contains relocations, which is unsupported
 
 #--- not-terminated.s
 .cstring


        


More information about the llvm-commits mailing list