Skip to content

Commit 2828a54

Browse files
committed
[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
1 parent 93a0ff2 commit 2828a54

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

lld/MachO/InputFiles.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -343,23 +343,20 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
343343
};
344344

345345
if (sectionType(sec.flags) == S_CSTRING_LITERALS) {
346-
if (sec.nreloc && config->dedupStrings)
347-
fatal(toString(this) + " contains relocations in " + sec.segname + "," +
348-
sec.sectname +
349-
", so LLD cannot deduplicate strings. Try re-running with "
350-
"--no-deduplicate-strings.");
351-
352-
InputSection *isec = make<CStringInputSection>(
353-
section, data, align,
354-
/*dedupLiterals=*/name == section_names::objcMethname ||
355-
config->dedupStrings);
346+
if (sec.nreloc)
347+
fatal(toString(this) + ": " + sec.segname + "," + sec.sectname +
348+
" contains relocations, which is unsupported");
349+
bool dedupLiterals =
350+
name == section_names::objcMethname || config->dedupStrings;
351+
InputSection *isec =
352+
make<CStringInputSection>(section, data, align, dedupLiterals);
356353
// FIXME: parallelize this?
357354
cast<CStringInputSection>(isec)->splitIntoPieces();
358355
section.subsections.push_back({0, isec});
359356
} else if (isWordLiteralSection(sec.flags)) {
360357
if (sec.nreloc)
361-
fatal(toString(this) + " contains unsupported relocations in " +
362-
sec.segname + "," + sec.sectname);
358+
fatal(toString(this) + ": " + sec.segname + "," + sec.sectname +
359+
" contains relocations, which is unsupported");
363360
InputSection *isec = make<WordLiteralInputSection>(section, data, align);
364361
section.subsections.push_back({0, isec});
365362
} else if (auto recordSize = getRecordSize(segname, name)) {

lld/test/MachO/invalid/cstring-dedup.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# RUN: not %lld -dylib %t/relocs.o 2>&1 | FileCheck %s --check-prefix=RELOCS
1212

1313
# TERM: not-terminated.o:(__cstring+0x4): string is not null terminated
14-
# RELOCS: relocs.o contains relocations in __TEXT,__cstring, so LLD cannot deduplicate strings. Try re-running with --no-deduplicate-strings.
14+
# RELOCS: error: {{.*}}relocs.o: __TEXT,__cstring contains relocations, which is unsupported
1515

1616
#--- not-terminated.s
1717
.cstring

0 commit comments

Comments
 (0)