forked from OSchip/llvm-project
Revert "[ELF] Create input and output section names"
This reverts commit r222311. Reverting because of failure in the darwin bot. llvm-svn: 222329
This commit is contained in:
parent
1d2a061bd8
commit
f994868b65
|
@ -175,14 +175,8 @@ public:
|
||||||
SectionOrder getSectionOrder(StringRef name, int32_t contentType,
|
SectionOrder getSectionOrder(StringRef name, int32_t contentType,
|
||||||
int32_t contentPermissions) override;
|
int32_t contentPermissions) override;
|
||||||
|
|
||||||
/// \brief Return the name of the input section by decoding the input
|
/// \brief This maps the input sections to the output section names
|
||||||
/// sectionChoice.
|
virtual StringRef getSectionName(const DefinedAtom *da) const;
|
||||||
virtual StringRef getInputSectionName(const DefinedAtom *da) const;
|
|
||||||
|
|
||||||
/// \brief Return the name of the output section from the input section and
|
|
||||||
/// path.
|
|
||||||
virtual StringRef getOutputSectionName(StringRef inputSectionName,
|
|
||||||
StringRef path) const;
|
|
||||||
|
|
||||||
/// \brief Gets or creates a section.
|
/// \brief Gets or creates a section.
|
||||||
AtomSection<ELFT> *
|
AtomSection<ELFT> *
|
||||||
|
@ -408,8 +402,7 @@ Layout::SectionOrder DefaultLayout<ELFT>::getSectionOrder(
|
||||||
|
|
||||||
/// \brief This maps the input sections to the output section names
|
/// \brief This maps the input sections to the output section names
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
StringRef
|
StringRef DefaultLayout<ELFT>::getSectionName(const DefinedAtom *da) const {
|
||||||
DefaultLayout<ELFT>::getInputSectionName(const DefinedAtom *da) const {
|
|
||||||
if (da->sectionChoice() == DefinedAtom::sectionBasedOnContent) {
|
if (da->sectionChoice() == DefinedAtom::sectionBasedOnContent) {
|
||||||
switch (da->contentType()) {
|
switch (da->contentType()) {
|
||||||
case DefinedAtom::typeCode:
|
case DefinedAtom::typeCode:
|
||||||
|
@ -428,15 +421,7 @@ DefaultLayout<ELFT>::getInputSectionName(const DefinedAtom *da) const {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return da->customSectionName();
|
return llvm::StringSwitch<StringRef>(da->customSectionName())
|
||||||
}
|
|
||||||
|
|
||||||
/// \brief This maps the input sections to the output section names
|
|
||||||
template <class ELFT>
|
|
||||||
StringRef
|
|
||||||
DefaultLayout<ELFT>::getOutputSectionName(StringRef inputSectionName,
|
|
||||||
StringRef /* path */) const {
|
|
||||||
return llvm::StringSwitch<StringRef>(inputSectionName)
|
|
||||||
.StartsWith(".text", ".text")
|
.StartsWith(".text", ".text")
|
||||||
.StartsWith(".ctors", ".ctors")
|
.StartsWith(".ctors", ".ctors")
|
||||||
.StartsWith(".dtors", ".dtors")
|
.StartsWith(".dtors", ".dtors")
|
||||||
|
@ -449,7 +434,7 @@ DefaultLayout<ELFT>::getOutputSectionName(StringRef inputSectionName,
|
||||||
.StartsWith(".tbss", ".tbss")
|
.StartsWith(".tbss", ".tbss")
|
||||||
.StartsWith(".init_array", ".init_array")
|
.StartsWith(".init_array", ".init_array")
|
||||||
.StartsWith(".fini_array", ".fini_array")
|
.StartsWith(".fini_array", ".fini_array")
|
||||||
.Default(inputSectionName);
|
.Default(da->customSectionName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Gets the segment for a output section
|
/// \brief Gets the segment for a output section
|
||||||
|
@ -562,7 +547,6 @@ DefaultLayout<ELFT>::getSection(StringRef sectionName, int32_t contentType,
|
||||||
getSectionOrder(sectionName, contentType, permissions);
|
getSectionOrder(sectionName, contentType, permissions);
|
||||||
AtomSection<ELFT> *newSec =
|
AtomSection<ELFT> *newSec =
|
||||||
createSection(sectionName, contentType, permissions, sectionOrder);
|
createSection(sectionName, contentType, permissions, sectionOrder);
|
||||||
newSec->setOutputSectionName(getOutputSectionName(sectionName, path));
|
|
||||||
newSec->setOrder(sectionOrder);
|
newSec->setOrder(sectionOrder);
|
||||||
_sections.push_back(newSec);
|
_sections.push_back(newSec);
|
||||||
_sectionMap.insert(std::make_pair(sectionKey, newSec));
|
_sectionMap.insert(std::make_pair(sectionKey, newSec));
|
||||||
|
@ -581,7 +565,7 @@ ErrorOr<const lld::AtomLayout &> DefaultLayout<ELFT>::addAtom(const Atom *atom)
|
||||||
definedAtom->permissions();
|
definedAtom->permissions();
|
||||||
const DefinedAtom::ContentType contentType = definedAtom->contentType();
|
const DefinedAtom::ContentType contentType = definedAtom->contentType();
|
||||||
|
|
||||||
StringRef sectionName = getInputSectionName(definedAtom);
|
StringRef sectionName = getSectionName(definedAtom);
|
||||||
AtomSection<ELFT> *section = getSection(
|
AtomSection<ELFT> *section = getSection(
|
||||||
sectionName, contentType, permissions, definedAtom->file().path());
|
sectionName, contentType, permissions, definedAtom->file().path());
|
||||||
|
|
||||||
|
@ -628,18 +612,15 @@ template <class ELFT> void DefaultLayout<ELFT>::createOutputSections() {
|
||||||
OutputSection<ELFT> *outputSection;
|
OutputSection<ELFT> *outputSection;
|
||||||
|
|
||||||
for (auto &si : _sections) {
|
for (auto &si : _sections) {
|
||||||
Section<ELFT> *section = dyn_cast<Section<ELFT>>(si);
|
|
||||||
if (!section)
|
|
||||||
continue;
|
|
||||||
const std::pair<StringRef, OutputSection<ELFT> *> currentOutputSection(
|
const std::pair<StringRef, OutputSection<ELFT> *> currentOutputSection(
|
||||||
section->outputSectionName(), nullptr);
|
si->name(), nullptr);
|
||||||
std::pair<typename OutputSectionMapT::iterator, bool> outputSectionInsert(
|
std::pair<typename OutputSectionMapT::iterator, bool> outputSectionInsert(
|
||||||
_outputSectionMap.insert(currentOutputSection));
|
_outputSectionMap.insert(currentOutputSection));
|
||||||
if (!outputSectionInsert.second) {
|
if (!outputSectionInsert.second) {
|
||||||
outputSection = outputSectionInsert.first->second;
|
outputSection = outputSectionInsert.first->second;
|
||||||
} else {
|
} else {
|
||||||
outputSection = new (_allocator.Allocate<OutputSection<ELFT>>())
|
outputSection = new (_allocator.Allocate<OutputSection<ELFT>>())
|
||||||
OutputSection<ELFT>(section->outputSectionName());
|
OutputSection<ELFT>(si->name());
|
||||||
_outputSections.push_back(outputSection);
|
_outputSections.push_back(outputSection);
|
||||||
outputSectionInsert.first->second = outputSection;
|
outputSectionInsert.first->second = outputSection;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,8 @@ public:
|
||||||
contentPermissions);
|
contentPermissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Return the appropriate input section name.
|
/// \brief This maps the input sections to the output section names
|
||||||
virtual StringRef getInputSectionName(const DefinedAtom *da) const {
|
virtual StringRef getSectionName(const DefinedAtom *da) const {
|
||||||
switch (da->contentType()) {
|
switch (da->contentType()) {
|
||||||
case DefinedAtom::typeDataFast:
|
case DefinedAtom::typeDataFast:
|
||||||
case DefinedAtom::typeZeroFillFast:
|
case DefinedAtom::typeZeroFillFast:
|
||||||
|
@ -55,7 +55,7 @@ public:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return DefaultLayout<HexagonELFType>::getInputSectionName(da);
|
return DefaultLayout<HexagonELFType>::getSectionName(da);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Gets or creates a section.
|
/// \brief Gets or creates a section.
|
||||||
|
|
|
@ -302,9 +302,7 @@ template <class ELFT> void OutputELFWriter<ELFT>::createDefaultSections() {
|
||||||
_layout.addSection(_shdrtab.get());
|
_layout.addSection(_shdrtab.get());
|
||||||
|
|
||||||
for (auto sec : _layout.sections()) {
|
for (auto sec : _layout.sections()) {
|
||||||
// TODO: use findOutputSection
|
if (sec->name() != ".eh_frame")
|
||||||
auto section = dyn_cast<Section<ELFT>>(sec);
|
|
||||||
if (!section || section->outputSectionName() != ".eh_frame")
|
|
||||||
continue;
|
continue;
|
||||||
_ehFrameHeader.reset(new (_alloc) EHFrameHeader<ELFT>(
|
_ehFrameHeader.reset(new (_alloc) EHFrameHeader<ELFT>(
|
||||||
_context, ".eh_frame_hdr", _layout,
|
_context, ".eh_frame_hdr", _layout,
|
||||||
|
|
|
@ -38,13 +38,11 @@ template <class ELFT> class Segment;
|
||||||
/// \brief An ELF section.
|
/// \brief An ELF section.
|
||||||
template <class ELFT> class Section : public Chunk<ELFT> {
|
template <class ELFT> class Section : public Chunk<ELFT> {
|
||||||
public:
|
public:
|
||||||
Section(const ELFLinkingContext &context, StringRef sectionName,
|
Section(const ELFLinkingContext &context, StringRef name,
|
||||||
StringRef chunkName,
|
|
||||||
typename Chunk<ELFT>::Kind k = Chunk<ELFT>::Kind::ELFSection)
|
typename Chunk<ELFT>::Kind k = Chunk<ELFT>::Kind::ELFSection)
|
||||||
: Chunk<ELFT>(chunkName, k, context), _outputSection(nullptr), _flags(0),
|
: Chunk<ELFT>(name, k, context), _outputSection(nullptr), _flags(0),
|
||||||
_entSize(0), _type(0), _link(0), _info(0),
|
_entSize(0), _type(0), _link(0), _info(0),
|
||||||
_isFirstSectionInOutputSection(false), _segmentType(SHT_NULL),
|
_isFirstSectionInOutputSection(false), _segmentType(SHT_NULL) {}
|
||||||
_inputSectionName(sectionName), _outputSectionName(sectionName) {}
|
|
||||||
|
|
||||||
/// \brief Modify the section contents before assigning virtual addresses
|
/// \brief Modify the section contents before assigning virtual addresses
|
||||||
// or assigning file offsets
|
// or assigning file offsets
|
||||||
|
@ -112,14 +110,6 @@ public:
|
||||||
: this->_align2;
|
: this->_align2;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual StringRef inputSectionName() const { return _inputSectionName; }
|
|
||||||
|
|
||||||
virtual StringRef outputSectionName() const { return _outputSectionName; }
|
|
||||||
|
|
||||||
virtual void setOutputSectionName(StringRef outputSectionName) {
|
|
||||||
_outputSectionName = outputSectionName;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// \brief OutputSection this Section is a member of, or nullptr.
|
/// \brief OutputSection this Section is a member of, or nullptr.
|
||||||
OutputSection<ELFT> *_outputSection;
|
OutputSection<ELFT> *_outputSection;
|
||||||
|
@ -137,19 +127,14 @@ protected:
|
||||||
bool _isFirstSectionInOutputSection;
|
bool _isFirstSectionInOutputSection;
|
||||||
/// \brief the output ELF segment type of this section.
|
/// \brief the output ELF segment type of this section.
|
||||||
Layout::SegmentType _segmentType;
|
Layout::SegmentType _segmentType;
|
||||||
/// \brief Input section name.
|
|
||||||
StringRef _inputSectionName;
|
|
||||||
/// \brief Output section name.
|
|
||||||
StringRef _outputSectionName;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \brief A section containing atoms.
|
/// \brief A section containing atoms.
|
||||||
template <class ELFT> class AtomSection : public Section<ELFT> {
|
template <class ELFT> class AtomSection : public Section<ELFT> {
|
||||||
public:
|
public:
|
||||||
AtomSection(const ELFLinkingContext &context, StringRef sectionName,
|
AtomSection(const ELFLinkingContext &context, StringRef name,
|
||||||
int32_t contentType, int32_t permissions, int32_t order)
|
int32_t contentType, int32_t permissions, int32_t order)
|
||||||
: Section<ELFT>(context, sectionName, "AtomSection",
|
: Section<ELFT>(context, name, Chunk<ELFT>::Kind::AtomSection),
|
||||||
Chunk<ELFT>::Kind::AtomSection),
|
|
||||||
_contentType(contentType), _contentPermissions(permissions),
|
_contentType(contentType), _contentPermissions(permissions),
|
||||||
_isLoadedInMemory(true) {
|
_isLoadedInMemory(true) {
|
||||||
this->setOrder(order);
|
this->setOrder(order);
|
||||||
|
@ -570,7 +555,7 @@ private:
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
StringTable<ELFT>::StringTable(const ELFLinkingContext &context,
|
StringTable<ELFT>::StringTable(const ELFLinkingContext &context,
|
||||||
const char *str, int32_t order, bool dynamic)
|
const char *str, int32_t order, bool dynamic)
|
||||||
: Section<ELFT>(context, str, "StringTable") {
|
: Section<ELFT>(context, str) {
|
||||||
// the string table has a NULL entry for which
|
// the string table has a NULL entry for which
|
||||||
// add an empty string
|
// add an empty string
|
||||||
_strings.push_back("");
|
_strings.push_back("");
|
||||||
|
@ -694,7 +679,7 @@ protected:
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
SymbolTable<ELFT>::SymbolTable(const ELFLinkingContext &context,
|
SymbolTable<ELFT>::SymbolTable(const ELFLinkingContext &context,
|
||||||
const char *str, int32_t order)
|
const char *str, int32_t order)
|
||||||
: Section<ELFT>(context, str, "SymbolTable") {
|
: Section<ELFT>(context, str) {
|
||||||
this->setOrder(order);
|
this->setOrder(order);
|
||||||
Elf_Sym symbol;
|
Elf_Sym symbol;
|
||||||
std::memset(&symbol, 0, sizeof(Elf_Sym));
|
std::memset(&symbol, 0, sizeof(Elf_Sym));
|
||||||
|
@ -926,7 +911,7 @@ public:
|
||||||
|
|
||||||
RelocationTable(const ELFLinkingContext &context, StringRef str,
|
RelocationTable(const ELFLinkingContext &context, StringRef str,
|
||||||
int32_t order)
|
int32_t order)
|
||||||
: Section<ELFT>(context, str, "RelocationTable"), _symbolTable(nullptr) {
|
: Section<ELFT>(context, str), _symbolTable(nullptr) {
|
||||||
this->setOrder(order);
|
this->setOrder(order);
|
||||||
this->_flags = SHF_ALLOC;
|
this->_flags = SHF_ALLOC;
|
||||||
// Set the alignment properly depending on the target architecture
|
// Set the alignment properly depending on the target architecture
|
||||||
|
@ -1042,7 +1027,7 @@ public:
|
||||||
|
|
||||||
DynamicTable(const ELFLinkingContext &context, TargetLayout<ELFT> &layout,
|
DynamicTable(const ELFLinkingContext &context, TargetLayout<ELFT> &layout,
|
||||||
StringRef str, int32_t order)
|
StringRef str, int32_t order)
|
||||||
: Section<ELFT>(context, str, "DynamicSection"), _layout(layout) {
|
: Section<ELFT>(context, str), _layout(layout) {
|
||||||
this->setOrder(order);
|
this->setOrder(order);
|
||||||
this->_entSize = sizeof(Elf_Dyn);
|
this->_entSize = sizeof(Elf_Dyn);
|
||||||
this->_align2 = ELFT::Is64Bits ? 8 : 4;
|
this->_align2 = ELFT::Is64Bits ? 8 : 4;
|
||||||
|
@ -1225,7 +1210,7 @@ template <class ELFT> class InterpSection : public Section<ELFT> {
|
||||||
public:
|
public:
|
||||||
InterpSection(const ELFLinkingContext &context, StringRef str, int32_t order,
|
InterpSection(const ELFLinkingContext &context, StringRef str, int32_t order,
|
||||||
StringRef interp)
|
StringRef interp)
|
||||||
: Section<ELFT>(context, str, "Dynamic:Interp"), _interp(interp) {
|
: Section<ELFT>(context, str), _interp(interp) {
|
||||||
this->setOrder(order);
|
this->setOrder(order);
|
||||||
this->_align2 = 1;
|
this->_align2 = 1;
|
||||||
// + 1 for null term.
|
// + 1 for null term.
|
||||||
|
@ -1274,7 +1259,7 @@ template <class ELFT> class HashSection : public Section<ELFT> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HashSection(const ELFLinkingContext &context, StringRef name, int32_t order)
|
HashSection(const ELFLinkingContext &context, StringRef name, int32_t order)
|
||||||
: Section<ELFT>(context, name, "Dynamic:Hash"), _symbolTable(nullptr) {
|
: Section<ELFT>(context, name), _symbolTable(nullptr) {
|
||||||
this->setOrder(order);
|
this->setOrder(order);
|
||||||
this->_entSize = 4;
|
this->_entSize = 4;
|
||||||
this->_type = SHT_HASH;
|
this->_type = SHT_HASH;
|
||||||
|
@ -1378,7 +1363,7 @@ template <class ELFT> class EHFrameHeader : public Section<ELFT> {
|
||||||
public:
|
public:
|
||||||
EHFrameHeader(const ELFLinkingContext &context, StringRef name,
|
EHFrameHeader(const ELFLinkingContext &context, StringRef name,
|
||||||
TargetLayout<ELFT> &layout, int32_t order)
|
TargetLayout<ELFT> &layout, int32_t order)
|
||||||
: Section<ELFT>(context, name, "EHFrameHeader"), _layout(layout) {
|
: Section<ELFT>(context, name), _layout(layout) {
|
||||||
this->setOrder(order);
|
this->setOrder(order);
|
||||||
this->_entSize = 0;
|
this->_entSize = 0;
|
||||||
this->_type = SHT_PROGBITS;
|
this->_type = SHT_PROGBITS;
|
||||||
|
|
|
@ -432,6 +432,7 @@ void Segment<ELFT>::assignFileOffsets(uint64_t startOffset) {
|
||||||
isDataPageAlignedForNMagic = true;
|
isDataPageAlignedForNMagic = true;
|
||||||
} else
|
} else
|
||||||
fileOffset = llvm::RoundUpToAlignment(fileOffset, section->align2());
|
fileOffset = llvm::RoundUpToAlignment(fileOffset, section->align2());
|
||||||
|
|
||||||
if (isFirstSection) {
|
if (isFirstSection) {
|
||||||
slice->setFileOffset(fileOffset);
|
slice->setFileOffset(fileOffset);
|
||||||
isFirstSection = false;
|
isFirstSection = false;
|
||||||
|
@ -523,7 +524,7 @@ template <class ELFT> void Segment<ELFT>::assignVirtualAddress(uint64_t addr) {
|
||||||
}
|
}
|
||||||
uint64_t newAddr = llvm::RoundUpToAlignment(curAddr, (*si)->align2());
|
uint64_t newAddr = llvm::RoundUpToAlignment(curAddr, (*si)->align2());
|
||||||
// If the newAddress computed is more than a page away, let's create
|
// If the newAddress computed is more than a page away, let's create
|
||||||
// a separate segment, so that memory is not used up while running.
|
// a separate segment, so that memory is not used up while running
|
||||||
if (((newAddr - curAddr) > this->_context.getPageSize()) &&
|
if (((newAddr - curAddr) > this->_context.getPageSize()) &&
|
||||||
(_outputMagic != ELFLinkingContext::OutputMagic::NMAGIC &&
|
(_outputMagic != ELFLinkingContext::OutputMagic::NMAGIC &&
|
||||||
_outputMagic != ELFLinkingContext::OutputMagic::OMAGIC)) {
|
_outputMagic != ELFLinkingContext::OutputMagic::OMAGIC)) {
|
||||||
|
|
Loading…
Reference in New Issue