[ELF] Replace uncompressed InputSectionBase::data() with rawData. NFC
In many call sites we know uncompression cannot happen (non-SHF_ALLOC, or the data (even if compressed) must have been uncompressed by a previous pass). Prefer rawData in these cases. data() increases code size and prevents optimization on rawData.
This commit is contained in:
parent
41cb504b7c
commit
ae1ba6194f
|
@ -349,7 +349,7 @@ static uint64_t scanCortexA53Errata843419(InputSection *isec, uint64_t &off,
|
|||
}
|
||||
|
||||
uint64_t patchOff = 0;
|
||||
const uint8_t *buf = isec->data().begin();
|
||||
const uint8_t *buf = isec->rawData.begin();
|
||||
const ulittle32_t *instBuf = reinterpret_cast<const ulittle32_t *>(buf + off);
|
||||
uint32_t instr1 = *instBuf++;
|
||||
uint32_t instr2 = *instBuf++;
|
||||
|
@ -408,7 +408,7 @@ uint64_t Patch843419Section::getLDSTAddr() const {
|
|||
void Patch843419Section::writeTo(uint8_t *buf) {
|
||||
// Copy the instruction that we will be replacing with a branch in the
|
||||
// patchee Section.
|
||||
write32le(buf, read32le(patchee->data().begin() + patcheeOffset));
|
||||
write32le(buf, read32le(patchee->rawData.begin() + patcheeOffset));
|
||||
|
||||
// Apply any relocation transferred from the original patchee section.
|
||||
relocateAlloc(buf, buf + getSize());
|
||||
|
@ -591,7 +591,7 @@ AArch64Err843419Patcher::patchInputSectionDescription(
|
|||
auto dataSym = std::next(codeSym);
|
||||
uint64_t off = (*codeSym)->value;
|
||||
uint64_t limit =
|
||||
(dataSym == mapSyms.end()) ? isec->data().size() : (*dataSym)->value;
|
||||
(dataSym == mapSyms.end()) ? isec->rawData.size() : (*dataSym)->value;
|
||||
|
||||
while (off < limit) {
|
||||
uint64_t startAddr = isec->getVA(off);
|
||||
|
|
|
@ -265,7 +265,7 @@ static ScanResult scanCortexA8Errata657417(InputSection *isec, uint64_t &off,
|
|||
}
|
||||
|
||||
ScanResult scanRes = {0, 0, nullptr};
|
||||
const uint8_t *buf = isec->data().begin();
|
||||
const uint8_t *buf = isec->rawData.begin();
|
||||
// ARMv7-A Thumb 32-bit instructions are encoded 2 consecutive
|
||||
// little-endian halfwords.
|
||||
const ulittle16_t *instBuf = reinterpret_cast<const ulittle16_t *>(buf + off);
|
||||
|
@ -497,7 +497,7 @@ ARMErr657417Patcher::patchInputSectionDescription(
|
|||
while (thumbSym != mapSyms.end()) {
|
||||
auto nonThumbSym = std::next(thumbSym);
|
||||
uint64_t off = (*thumbSym)->value;
|
||||
uint64_t limit = (nonThumbSym == mapSyms.end()) ? isec->data().size()
|
||||
uint64_t limit = (nonThumbSym == mapSyms.end()) ? isec->rawData.size()
|
||||
: (*nonThumbSym)->value;
|
||||
|
||||
while (off < limit) {
|
||||
|
|
|
@ -263,7 +263,7 @@ bool X86_64::deleteFallThruJmpInsn(InputSection &is, InputFile *file,
|
|||
Relocation &r = is.relocations[rIndex];
|
||||
|
||||
// Check if the relocation corresponds to a direct jmp.
|
||||
const uint8_t *secContents = is.data().data();
|
||||
const uint8_t *secContents = is.rawData.data();
|
||||
// If it is not a direct jmp instruction, there is nothing to do here.
|
||||
if (*(secContents + r.offset - 1) != 0xe9)
|
||||
return false;
|
||||
|
|
|
@ -1923,7 +1923,7 @@ static void readSymbolPartitionSection(InputSectionBase *s) {
|
|||
if (!isa<Defined>(sym) || !sym->includeInDynsym())
|
||||
return;
|
||||
|
||||
StringRef partName = reinterpret_cast<const char *>(s->data().data());
|
||||
StringRef partName = reinterpret_cast<const char *>(s->rawData.data());
|
||||
for (Partition &part : partitions) {
|
||||
if (part.name == partName) {
|
||||
sym->partition = part.getNumber();
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
private:
|
||||
template <class P> void failOn(const P *loc, const Twine &msg) {
|
||||
fatal("corrupted .eh_frame: " + msg + "\n>>> defined in " +
|
||||
isec->getObjMsg((const uint8_t *)loc - isec->data().data()));
|
||||
isec->getObjMsg((const uint8_t *)loc - isec->rawData.data()));
|
||||
}
|
||||
|
||||
uint8_t readByte();
|
||||
|
|
|
@ -312,7 +312,7 @@ bool ICF<ELFT>::constantEq(const InputSection *secA, ArrayRef<RelTy> ra,
|
|||
template <class ELFT>
|
||||
bool ICF<ELFT>::equalsConstant(const InputSection *a, const InputSection *b) {
|
||||
if (a->flags != b->flags || a->getSize() != b->getSize() ||
|
||||
a->data() != b->data())
|
||||
a->rawData != b->rawData)
|
||||
return false;
|
||||
|
||||
// If two sections have different output sections, we cannot merge them.
|
||||
|
@ -491,7 +491,7 @@ template <class ELFT> void ICF<ELFT>::run() {
|
|||
// Initially, we use hash values to partition sections.
|
||||
parallelForEach(sections, [&](InputSection *s) {
|
||||
// Set MSB to 1 to avoid collisions with unique IDs.
|
||||
s->eqClass[0] = xxHash64(s->data()) | (1U << 31);
|
||||
s->eqClass[0] = xxHash64(s->rawData) | (1U << 31);
|
||||
});
|
||||
|
||||
// Perform 2 rounds of relocation hash propagation. 2 is an empirical value to
|
||||
|
|
|
@ -789,10 +789,10 @@ template <class ELFT> static uint32_t readAndFeatures(const InputSection &sec) {
|
|||
using Elf_Note = typename ELFT::Note;
|
||||
|
||||
uint32_t featuresSet = 0;
|
||||
ArrayRef<uint8_t> data = sec.data();
|
||||
ArrayRef<uint8_t> data = sec.rawData;
|
||||
auto reportFatal = [&](const uint8_t *place, const char *msg) {
|
||||
fatal(toString(sec.file) + ":(" + sec.name + "+0x" +
|
||||
Twine::utohexstr(place - sec.data().data()) + "): " + msg);
|
||||
Twine::utohexstr(place - sec.rawData.data()) + "): " + msg);
|
||||
};
|
||||
while (!data.empty()) {
|
||||
// Read one NOTE record.
|
||||
|
|
|
@ -367,6 +367,7 @@ template <class ELFT, class RelTy>
|
|||
void InputSection::copyRelocations(uint8_t *buf, ArrayRef<RelTy> rels) {
|
||||
const TargetInfo &target = *elf::target;
|
||||
InputSectionBase *sec = getRelocatedSection();
|
||||
(void)sec->data(); // uncompress if needed
|
||||
|
||||
for (const RelTy &rel : rels) {
|
||||
RelType type = rel.getType(config->isMips64EL);
|
||||
|
@ -419,7 +420,7 @@ void InputSection::copyRelocations(uint8_t *buf, ArrayRef<RelTy> rels) {
|
|||
}
|
||||
|
||||
int64_t addend = getAddend<ELFT>(rel);
|
||||
const uint8_t *bufLoc = sec->data().begin() + rel.r_offset;
|
||||
const uint8_t *bufLoc = sec->rawData.begin() + rel.r_offset;
|
||||
if (!RelTy::IsRela)
|
||||
addend = target.getImplicitAddend(bufLoc, type);
|
||||
|
||||
|
@ -1423,7 +1424,7 @@ void MergeInputSection::splitIntoPieces() {
|
|||
}
|
||||
|
||||
SectionPiece *MergeInputSection::getSectionPiece(uint64_t offset) {
|
||||
if (this->data().size() <= offset)
|
||||
if (this->rawData.size() <= offset)
|
||||
fatal(toString(this) + ": offset is outside the section");
|
||||
|
||||
// If Offset is not at beginning of a section piece, it is not in the map.
|
||||
|
|
|
@ -215,18 +215,18 @@ public:
|
|||
|
||||
|
||||
template <typename T> llvm::ArrayRef<T> getDataAs() const {
|
||||
size_t s = data().size();
|
||||
size_t s = rawData.size();
|
||||
assert(s % sizeof(T) == 0);
|
||||
return llvm::makeArrayRef<T>((const T *)data().data(), s / sizeof(T));
|
||||
return llvm::makeArrayRef<T>((const T *)rawData.data(), s / sizeof(T));
|
||||
}
|
||||
|
||||
mutable ArrayRef<uint8_t> rawData;
|
||||
|
||||
protected:
|
||||
template <typename ELFT>
|
||||
void parseCompressedHeader();
|
||||
void uncompress() const;
|
||||
|
||||
mutable ArrayRef<uint8_t> rawData;
|
||||
|
||||
// This field stores the uncompressed size of the compressed data in rawData,
|
||||
// or -1 if rawData is not compressed (either because the section wasn't
|
||||
// compressed in the first place, or because we ended up uncompressing it).
|
||||
|
@ -277,8 +277,8 @@ public:
|
|||
llvm::CachedHashStringRef getData(size_t i) const {
|
||||
size_t begin = pieces[i].inputOff;
|
||||
size_t end =
|
||||
(pieces.size() - 1 == i) ? data().size() : pieces[i + 1].inputOff;
|
||||
return {toStringRef(data().slice(begin, end - begin)), pieces[i].hash};
|
||||
(pieces.size() - 1 == i) ? rawData.size() : pieces[i + 1].inputOff;
|
||||
return {toStringRef(rawData.slice(begin, end - begin)), pieces[i].hash};
|
||||
}
|
||||
|
||||
// Returns the SectionPiece at a given input section offset.
|
||||
|
@ -300,7 +300,7 @@ struct EhSectionPiece {
|
|||
: inputOff(off), sec(sec), size(size), firstRelocation(firstRelocation) {}
|
||||
|
||||
ArrayRef<uint8_t> data() const {
|
||||
return {sec->data().data() + this->inputOff, size};
|
||||
return {sec->rawData.data() + this->inputOff, size};
|
||||
}
|
||||
|
||||
size_t inputOff;
|
||||
|
|
|
@ -74,7 +74,7 @@ private:
|
|||
template <class ELFT>
|
||||
static uint64_t getAddend(InputSectionBase &sec,
|
||||
const typename ELFT::Rel &rel) {
|
||||
return target->getImplicitAddend(sec.data().begin() + rel.r_offset,
|
||||
return target->getImplicitAddend(sec.rawData.begin() + rel.r_offset,
|
||||
rel.getType(config->isMips64EL));
|
||||
}
|
||||
|
||||
|
|
|
@ -497,7 +497,7 @@ int64_t RelocationScanner::computeMipsAddend(const RelTy &rel, RelExpr expr,
|
|||
if (pairTy == R_MIPS_NONE)
|
||||
return 0;
|
||||
|
||||
const uint8_t *buf = sec.data().data();
|
||||
const uint8_t *buf = sec.rawData.data();
|
||||
uint32_t symIndex = rel.getSymbol(config->isMips64EL);
|
||||
|
||||
// To make things worse, paired relocations might not be contiguous in
|
||||
|
@ -524,7 +524,7 @@ int64_t RelocationScanner::computeAddend(const RelTy &rel, RelExpr expr,
|
|||
if (RelTy::IsRela) {
|
||||
addend = getAddend<ELFT>(rel);
|
||||
} else {
|
||||
const uint8_t *buf = sec.data().data();
|
||||
const uint8_t *buf = sec.rawData.data();
|
||||
addend = target.getImplicitAddend(buf + rel.r_offset, type);
|
||||
}
|
||||
|
||||
|
@ -1326,7 +1326,7 @@ template <class ELFT, class RelTy> void RelocationScanner::scanOne(RelTy *&i) {
|
|||
maybeReportUndefined(cast<Undefined>(sym), sec, offset))
|
||||
return;
|
||||
|
||||
const uint8_t *relocatedAddr = sec.data().begin() + offset;
|
||||
const uint8_t *relocatedAddr = sec.rawData.begin() + offset;
|
||||
RelExpr expr = target.getRelExpr(type, sym, relocatedAddr);
|
||||
|
||||
// Ignore R_*_NONE and other marker relocations.
|
||||
|
|
|
@ -112,7 +112,7 @@ std::unique_ptr<MipsAbiFlagsSection<ELFT>> MipsAbiFlagsSection<ELFT>::create() {
|
|||
create = true;
|
||||
|
||||
std::string filename = toString(sec->file);
|
||||
const size_t size = sec->data().size();
|
||||
const size_t size = sec->rawData.size();
|
||||
// Older version of BFD (such as the default FreeBSD linker) concatenate
|
||||
// .MIPS.abiflags instead of merging. To allow for this case (or potential
|
||||
// zero padding) we ignore everything after the first Elf_Mips_ABIFlags
|
||||
|
@ -121,7 +121,7 @@ std::unique_ptr<MipsAbiFlagsSection<ELFT>> MipsAbiFlagsSection<ELFT>::create() {
|
|||
Twine(size) + " instead of " + Twine(sizeof(Elf_Mips_ABIFlags)));
|
||||
return nullptr;
|
||||
}
|
||||
auto *s = reinterpret_cast<const Elf_Mips_ABIFlags *>(sec->data().data());
|
||||
auto *s = reinterpret_cast<const Elf_Mips_ABIFlags *>(sec->rawData.data());
|
||||
if (s->version != 0) {
|
||||
error(filename + ": unexpected .MIPS.abiflags version " +
|
||||
Twine(s->version));
|
||||
|
@ -184,7 +184,7 @@ std::unique_ptr<MipsOptionsSection<ELFT>> MipsOptionsSection<ELFT>::create() {
|
|||
sec->markDead();
|
||||
|
||||
std::string filename = toString(sec->file);
|
||||
ArrayRef<uint8_t> d = sec->data();
|
||||
ArrayRef<uint8_t> d = sec->rawData;
|
||||
|
||||
while (!d.empty()) {
|
||||
if (d.size() < sizeof(Elf_Mips_Options)) {
|
||||
|
@ -240,12 +240,12 @@ std::unique_ptr<MipsReginfoSection<ELFT>> MipsReginfoSection<ELFT>::create() {
|
|||
for (InputSectionBase *sec : sections) {
|
||||
sec->markDead();
|
||||
|
||||
if (sec->data().size() != sizeof(Elf_Mips_RegInfo)) {
|
||||
if (sec->rawData.size() != sizeof(Elf_Mips_RegInfo)) {
|
||||
error(toString(sec->file) + ": invalid size of .reginfo section");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto *r = reinterpret_cast<const Elf_Mips_RegInfo *>(sec->data().data());
|
||||
auto *r = reinterpret_cast<const Elf_Mips_RegInfo *>(sec->rawData.data());
|
||||
reginfo.ri_gprmask |= r->ri_gprmask;
|
||||
sec->getFile<ELFT>()->mipsGp0 = r->ri_gp_value;
|
||||
};
|
||||
|
@ -3535,7 +3535,7 @@ void ARMExidxSyntheticSection::writeTo(uint8_t *buf) {
|
|||
for (InputSection *isec : executableSections) {
|
||||
assert(isec->getParent() != nullptr);
|
||||
if (InputSection *d = findExidxSection(isec)) {
|
||||
memcpy(buf + offset, d->data().data(), d->data().size());
|
||||
memcpy(buf + offset, d->rawData.data(), d->rawData.size());
|
||||
d->relocateAlloc(buf + d->outSecOff, buf + d->outSecOff + d->getSize());
|
||||
offset += d->getSize();
|
||||
} else {
|
||||
|
|
|
@ -1695,7 +1695,7 @@ static void fixSymbolsAfterShrinking() {
|
|||
if (!inputSec || !inputSec->bytesDropped)
|
||||
return;
|
||||
|
||||
const size_t OldSize = inputSec->data().size();
|
||||
const size_t OldSize = inputSec->rawData.size();
|
||||
const size_t NewSize = OldSize - inputSec->bytesDropped;
|
||||
|
||||
if (def->value > NewSize && def->value <= OldSize) {
|
||||
|
|
Loading…
Reference in New Issue