[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
This commit is contained in:
Jez Ng 2021-06-30 18:55:36 -04:00
parent e7e71e9454
commit 0d6d35e63b
5 changed files with 16 additions and 6 deletions

View File

@ -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);

View File

@ -46,7 +46,7 @@ public:
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;

View File

@ -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;

View File

@ -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 @@ public:
template <class LP> void writeResult();
NamePair maybeRenameSection(NamePair key);
void createSyntheticSections();
// Add bindings for symbols that need weak or non-lazy bindings.

View File

@ -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: