[PATCH] D141025: [lld-macho] Don't support relocations in cstring sections
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 4 19:54:20 PST 2023
int3 created this revision.
int3 added a reviewer: lld-macho.
Herald added projects: lld-macho, All.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D141025
Files:
lld/MachO/InputFiles.cpp
lld/test/MachO/invalid/cstring-dedup.s
Index: lld/test/MachO/invalid/cstring-dedup.s
===================================================================
--- lld/test/MachO/invalid/cstring-dedup.s
+++ 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
Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ lld/MachO/InputFiles.cpp
@@ -343,23 +343,20 @@
};
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)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141025.486454.patch
Type: text/x-patch
Size: 2404 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230105/d75d6c65/attachment.bin>
More information about the llvm-commits
mailing list