[lld] afdeb43 - [lld/mac] Move output segment rename logic into OutputSegment
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 25 15:21:43 PDT 2021
Author: Nico Weber
Date: 2021-07-25T18:20:09-04:00
New Revision: afdeb432f0a1e10257862e4a047fc32458f4c124
URL: https://github.com/llvm/llvm-project/commit/afdeb432f0a1e10257862e4a047fc32458f4c124
DIFF: https://github.com/llvm/llvm-project/commit/afdeb432f0a1e10257862e4a047fc32458f4c124.diff
LOG: [lld/mac] Move output segment rename logic into OutputSegment
Fixes the output segment name if both -rename_section and
-rename_segment are used and the post-section-rename segment
name is the same as the pre-segment-rename segment name to
match ld64's behavior.
The motivation is that segment$start$ can create section-less segments,
and this makes a corner case in the interaction between segment$start and
-rename_segment in the upcoming segment$start patch.
Differential Revision: https://reviews.llvm.org/D106766
Added:
Modified:
lld/MachO/ConcatOutputSection.cpp
lld/MachO/OutputSegment.cpp
lld/test/MachO/rename.s
Removed:
################################################################################
diff --git a/lld/MachO/ConcatOutputSection.cpp b/lld/MachO/ConcatOutputSection.cpp
index b98af92a891b7..78590cff2eefc 100644
--- a/lld/MachO/ConcatOutputSection.cpp
+++ b/lld/MachO/ConcatOutputSection.cpp
@@ -339,7 +339,7 @@ void ConcatOutputSection::writeTo(uint8_t *buf) const {
void ConcatOutputSection::finalizeFlags(InputSection *input) {
switch (sectionType(input->getFlags())) {
default /*type-unspec'ed*/:
- // FIXME: Add additional logics here when supporting emitting obj files.
+ // FIXME: Add additional logic here when supporting emitting obj files.
break;
case S_4BYTE_LITERALS:
case S_8BYTE_LITERALS:
@@ -373,8 +373,5 @@ NamePair macho::maybeRenameSection(NamePair key) {
auto newNames = config->sectionRenameMap.find(key);
if (newNames != config->sectionRenameMap.end())
return newNames->second;
- auto newName = config->segmentRenameMap.find(key.first);
- if (newName != config->segmentRenameMap.end())
- return std::make_pair(newName->second, key.second);
return key;
}
diff --git a/lld/MachO/OutputSegment.cpp b/lld/MachO/OutputSegment.cpp
index 7345bf074b2ec..7d9544d06ea1a 100644
--- a/lld/MachO/OutputSegment.cpp
+++ b/lld/MachO/OutputSegment.cpp
@@ -153,7 +153,16 @@ void macho::sortOutputSegments() {
static DenseMap<StringRef, OutputSegment *> nameToOutputSegment;
std::vector<OutputSegment *> macho::outputSegments;
+static StringRef maybeRenameSegment(StringRef name) {
+ auto newName = config->segmentRenameMap.find(name);
+ if (newName != config->segmentRenameMap.end())
+ return newName->second;
+ return name;
+}
+
OutputSegment *macho::getOrCreateOutputSegment(StringRef name) {
+ name = maybeRenameSegment(name);
+
OutputSegment *&segRef = nameToOutputSegment[name];
if (segRef)
return segRef;
diff --git a/lld/test/MachO/rename.s b/lld/test/MachO/rename.s
index 7ce82048a8544..94c3afdec7e25 100644
--- a/lld/test/MachO/rename.s
+++ b/lld/test/MachO/rename.s
@@ -71,8 +71,7 @@
# SECTSEGYES-NEXT: segname __TEXT
# SECTSEGYES: Section
# SECTSEGYES-NEXT: sectname __to_sect
-# SECTSEGYES-NEXT: segname __TO_SECT
-## FIXME: ^ This should use __SEG like ld64 does.
+# SECTSEGYES-NEXT: segname __SEG
## ...but rename_segment has no effect if it doesn't match the name after
## rename_section is applied.
# RUN: %lld -dylib \
More information about the llvm-commits
mailing list