forked from OSchip/llvm-project
Rollback r276538 and r276540 to unbreak asan bot.
llvm-svn: 276543
This commit is contained in:
parent
f23eb70e03
commit
8a9bb7baeb
|
@ -261,15 +261,26 @@ std::vector<OutputSectionBase<ELFT> *>
|
||||||
LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) {
|
LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) {
|
||||||
typedef const std::unique_ptr<ObjectFile<ELFT>> ObjectFile;
|
typedef const std::unique_ptr<ObjectFile<ELFT>> ObjectFile;
|
||||||
std::vector<OutputSectionBase<ELFT> *> Result;
|
std::vector<OutputSectionBase<ELFT> *> Result;
|
||||||
|
DenseSet<OutputSectionBase<ELFT> *> Removed;
|
||||||
|
|
||||||
// Add input section to output section. If there is no output section yet,
|
// Add input section to output section. If there is no output section yet,
|
||||||
// then create it and add to output section list.
|
// then create it and add to output section list.
|
||||||
auto AddInputSec = [&](InputSectionBase<ELFT> *C, StringRef Name) {
|
auto AddInputSec = [&](InputSectionBase<ELFT> *C, StringRef Name,
|
||||||
|
ConstraintKind Constraint) {
|
||||||
OutputSectionBase<ELFT> *Sec;
|
OutputSectionBase<ELFT> *Sec;
|
||||||
bool IsNew;
|
bool IsNew;
|
||||||
std::tie(Sec, IsNew) = Factory.create(C, Name);
|
std::tie(Sec, IsNew) = Factory.create(C, Name);
|
||||||
if (IsNew)
|
if (IsNew)
|
||||||
Result.push_back(Sec);
|
Result.push_back(Sec);
|
||||||
|
if ((!(C->getSectionHdr()->sh_flags & SHF_WRITE)) &&
|
||||||
|
Constraint == ReadWrite) {
|
||||||
|
Removed.insert(Sec);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ((C->getSectionHdr()->sh_flags & SHF_WRITE) && Constraint == ReadOnly) {
|
||||||
|
Removed.insert(Sec);
|
||||||
|
return;
|
||||||
|
}
|
||||||
Sec->addSection(C);
|
Sec->addSection(C);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -295,7 +306,7 @@ LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) {
|
||||||
if (OutCmd->Name == "/DISCARD/")
|
if (OutCmd->Name == "/DISCARD/")
|
||||||
S->Live = false;
|
S->Live = false;
|
||||||
else
|
else
|
||||||
AddInputSec(S, OutCmd->Name);
|
AddInputSec(S, OutCmd->Name, OutCmd->Constraint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -307,46 +318,18 @@ LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) {
|
||||||
for (InputSectionBase<ELFT> *S : F->getSections()) {
|
for (InputSectionBase<ELFT> *S : F->getSections()) {
|
||||||
if (!isDiscarded(S)) {
|
if (!isDiscarded(S)) {
|
||||||
if (!S->OutSec)
|
if (!S->OutSec)
|
||||||
AddInputSec(S, getOutputSectionName(S));
|
AddInputSec(S, getOutputSectionName(S), NoConstraint);
|
||||||
} else
|
} else
|
||||||
reportDiscarded(S, F);
|
reportDiscarded(S, F);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove from the output all the sections which did not meet
|
// Remove from the output all the sections which did not met the constraints.
|
||||||
// the optional constraints.
|
Result.erase(std::remove_if(Result.begin(), Result.end(),
|
||||||
return filter(Result);
|
[&](OutputSectionBase<ELFT> *Sec) {
|
||||||
}
|
return Removed.count(Sec);
|
||||||
|
}),
|
||||||
// Process ONLY_IF_RO and ONLY_IF_RW.
|
Result.end());
|
||||||
template <class ELFT>
|
return Result;
|
||||||
std::vector<OutputSectionBase<ELFT> *>
|
|
||||||
LinkerScript<ELFT>::filter(std::vector<OutputSectionBase<ELFT> *> &Sections) {
|
|
||||||
// Sections and OutputSectionCommands are parallel arrays.
|
|
||||||
// In this loop, we remove output sections if they don't satisfy
|
|
||||||
// requested properties.
|
|
||||||
auto It = Sections.begin();
|
|
||||||
for (const std::unique_ptr<BaseCommand> &Base : Opt.Commands) {
|
|
||||||
auto *Cmd = dyn_cast<OutputSectionCommand>(Base.get());
|
|
||||||
if (!Cmd)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (Cmd->Constraint == ConstraintKind::NoConstraint) {
|
|
||||||
++It;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
OutputSectionBase<ELFT> *Sec = *It;
|
|
||||||
bool Writable = (Sec->getFlags() & SHF_WRITE);
|
|
||||||
bool RO = (Cmd->Constraint == ConstraintKind::ReadOnly);
|
|
||||||
bool RW = (Cmd->Constraint == ConstraintKind::ReadWrite);
|
|
||||||
|
|
||||||
if ((RO && Writable) || (RW && !Writable)) {
|
|
||||||
Sections.erase(It);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
++It;
|
|
||||||
}
|
|
||||||
return Sections;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
|
|
|
@ -130,9 +130,6 @@ private:
|
||||||
// "ScriptConfig" is a bit too long, so define a short name for it.
|
// "ScriptConfig" is a bit too long, so define a short name for it.
|
||||||
ScriptConfiguration &Opt = *ScriptConfig;
|
ScriptConfiguration &Opt = *ScriptConfig;
|
||||||
|
|
||||||
std::vector<OutputSectionBase<ELFT> *>
|
|
||||||
filter(std::vector<OutputSectionBase<ELFT> *> &Sections);
|
|
||||||
|
|
||||||
int getSectionIndex(StringRef Name);
|
int getSectionIndex(StringRef Name);
|
||||||
std::vector<size_t> getPhdrIndicesForSection(StringRef Name);
|
std::vector<size_t> getPhdrIndicesForSection(StringRef Name);
|
||||||
void dispatchAssignment(SymbolAssignment *Cmd);
|
void dispatchAssignment(SymbolAssignment *Cmd);
|
||||||
|
|
Loading…
Reference in New Issue