[lld] 0d6d35e - [lld-macho] -section_rename should work on synthetic sections too
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 30 15:55:59 PDT 2021
Author: Jez Ng
Date: 2021-06-30T18:55:48-04:00
New Revision: 0d6d35e63bb01c7021b116c0f14227e353668627
URL: https://github.com/llvm/llvm-project/commit/0d6d35e63bb01c7021b116c0f14227e353668627
DIFF: https://github.com/llvm/llvm-project/commit/0d6d35e63bb01c7021b116c0f14227e353668627.diff
LOG: [lld-macho] -section_rename should work on synthetic sections too
Previously, we only applied the renames to
ConcatOutputSections.
Reviewed By: #lld-macho, thakis
Differential Revision: https://reviews.llvm.org/D105079
Added:
Modified:
lld/MachO/SyntheticSections.cpp
lld/MachO/SyntheticSections.h
lld/MachO/Writer.cpp
lld/MachO/Writer.h
lld/test/MachO/rename.s
Removed:
################################################################################
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index c5d77142fda0..03976ff2d688 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -47,7 +47,8 @@ InStruct macho::in;
std::vector<SyntheticSection *> macho::syntheticSections;
SyntheticSection::SyntheticSection(const char *segname, const char *name)
- : OutputSection(SyntheticKind, name), segname(segname) {
+ : OutputSection(SyntheticKind, name) {
+ std::tie(this->segname, this->name) = maybeRenameSection({segname, name});
isec = make<ConcatInputSection>(segname, name);
isec->parent = this;
syntheticSections.push_back(this);
diff --git a/lld/MachO/SyntheticSections.h b/lld/MachO/SyntheticSections.h
index 95a09a010e27..73d4c3153438 100644
--- a/lld/MachO/SyntheticSections.h
+++ b/lld/MachO/SyntheticSections.h
@@ -46,7 +46,7 @@ class SyntheticSection : public OutputSection {
return sec->kind() == SyntheticKind;
}
- const StringRef segname;
+ StringRef segname;
// This fake InputSection makes it easier for us to write code that applies
// generically to both user inputs and synthetics.
InputSection *isec;
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index 5520e65d881f..443cd99b73f4 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -855,7 +855,7 @@ static void sortSegmentsAndSections() {
}
}
-static NamePair maybeRenameSection(NamePair key) {
+NamePair macho::maybeRenameSection(NamePair key) {
auto newNames = config->sectionRenameMap.find(key);
if (newNames != config->sectionRenameMap.end())
return newNames->second;
diff --git a/lld/MachO/Writer.h b/lld/MachO/Writer.h
index 56f6f7ae6fe7..2a6cc63d5b82 100644
--- a/lld/MachO/Writer.h
+++ b/lld/MachO/Writer.h
@@ -9,6 +9,8 @@
#ifndef LLD_MACHO_WRITER_H
#define LLD_MACHO_WRITER_H
+#include "Config.h"
+
#include <cstdint>
namespace lld {
@@ -27,6 +29,8 @@ class LoadCommand {
template <class LP> void writeResult();
+NamePair maybeRenameSection(NamePair key);
+
void createSyntheticSections();
// Add bindings for symbols that need weak or non-lazy bindings.
diff --git a/lld/test/MachO/rename.s b/lld/test/MachO/rename.s
index 0b74ff1fdfd2..58144f05df79 100644
--- a/lld/test/MachO/rename.s
+++ b/lld/test/MachO/rename.s
@@ -30,6 +30,7 @@
# RUN: %lld \
# RUN: -rename_section __FROM_SECT __from_sect __TO_SECT __to_sect \
# RUN: -rename_segment __FROM_SEG __TO_SEG \
+# RUN: -rename_section __TEXT __cstring __RODATA __cstring \
# RUN: -o %t %t.o
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s
@@ -37,14 +38,14 @@
# CHECK-NEXT: sectname __text
# CHECK-NEXT: segname __TEXT
# CHECK: {{^}}Section{{$}}
-# CHECK-NOT: sectname __from_sect
# CHECK-NEXT: sectname __to_sect
-# CHECK-NOT: segname __FROM_SECT
# CHECK-NEXT: segname __TO_SECT
# CHECK: {{^}}Section{{$}}
# CHECK-NEXT: sectname __from_seg
-# CHECK-NOT: segname __FROM_SEG
# CHECK-NEXT: segname __TO_SEG
+# CHECK: {{^}}Section{{$}}
+# CHECK-NEXT: sectname __cstring
+# CHECK-NEXT: segname __RODATA
.section __FROM_SECT,__from_sect
.global _from_sect
@@ -56,6 +57,10 @@ _from_sect:
_from_seg:
.space 8
+## This is a synthetic section; make sure it gets renamed too.
+.cstring
+ .space 8
+
.text
.global _main
_main:
More information about the llvm-commits
mailing list