forked from OSchip/llvm-project
Don't store an OutputLoc in every InputSection.
It was only used by build-id and that can easily compute it. llvm-svn: 285691
This commit is contained in:
parent
70a3d6df52
commit
092d3b7f3b
|
@ -482,9 +482,6 @@ template <class ELFT> void InputSection<ELFT>::writeTo(uint8_t *Buf) {
|
|||
if (this->Type == SHT_NOBITS)
|
||||
return;
|
||||
|
||||
// Set output location.
|
||||
this->OutputLoc = Buf + OutSecOff;
|
||||
|
||||
// If -r is given, then an InputSection may be a relocation section.
|
||||
if (this->Type == SHT_RELA) {
|
||||
copyRelocations(Buf + OutSecOff, this->template getDataAs<Elf_Rela>());
|
||||
|
@ -867,33 +864,38 @@ BuildIdSection<ELFT>::BuildIdSection(size_t HashSize)
|
|||
}
|
||||
|
||||
template <class ELFT>
|
||||
void BuildIdFastHash<ELFT>::writeBuildId(ArrayRef<uint8_t> Buf) {
|
||||
uint8_t *BuildIdSection<ELFT>::getOutputLoc(uint8_t *Start) const {
|
||||
return Start + this->OutSec->getFileOffset() + this->OutSecOff;
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
void BuildIdFastHash<ELFT>::writeBuildId(MutableArrayRef<uint8_t> Buf) {
|
||||
const endianness E = ELFT::TargetEndianness;
|
||||
|
||||
// 64-bit xxhash
|
||||
uint64_t Hash = xxHash64(toStringRef(Buf));
|
||||
write64<E>(this->OutputLoc + 16, Hash);
|
||||
write64<E>(this->getOutputLoc(Buf.begin()) + 16, Hash);
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
void BuildIdMd5<ELFT>::writeBuildId(ArrayRef<uint8_t> Buf) {
|
||||
void BuildIdMd5<ELFT>::writeBuildId(MutableArrayRef<uint8_t> Buf) {
|
||||
MD5 Hash;
|
||||
Hash.update(Buf);
|
||||
MD5::MD5Result Res;
|
||||
Hash.final(Res);
|
||||
memcpy(this->OutputLoc + 16, Res, 16);
|
||||
memcpy(this->getOutputLoc(Buf.begin()) + 16, Res, 16);
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
void BuildIdSha1<ELFT>::writeBuildId(ArrayRef<uint8_t> Buf) {
|
||||
void BuildIdSha1<ELFT>::writeBuildId(MutableArrayRef<uint8_t> Buf) {
|
||||
SHA1 Hash;
|
||||
Hash.update(Buf);
|
||||
memcpy(this->OutputLoc + 16, Hash.final().data(), 20);
|
||||
memcpy(this->getOutputLoc(Buf.begin()) + 16, Hash.final().data(), 20);
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
void BuildIdUuid<ELFT>::writeBuildId(ArrayRef<uint8_t> Buf) {
|
||||
if (getRandomBytes(this->OutputLoc + 16, 16))
|
||||
void BuildIdUuid<ELFT>::writeBuildId(MutableArrayRef<uint8_t> Buf) {
|
||||
if (getRandomBytes(this->getOutputLoc(Buf.begin()) + 16, 16))
|
||||
error("entropy source failure");
|
||||
}
|
||||
|
||||
|
@ -902,8 +904,8 @@ BuildIdHexstring<ELFT>::BuildIdHexstring()
|
|||
: BuildIdSection<ELFT>(Config->BuildIdVector.size()) {}
|
||||
|
||||
template <class ELFT>
|
||||
void BuildIdHexstring<ELFT>::writeBuildId(ArrayRef<uint8_t> Buf) {
|
||||
memcpy(this->OutputLoc + 16, Config->BuildIdVector.data(),
|
||||
void BuildIdHexstring<ELFT>::writeBuildId(MutableArrayRef<uint8_t> Buf) {
|
||||
memcpy(this->getOutputLoc(Buf.begin()) + 16, Config->BuildIdVector.data(),
|
||||
Config->BuildIdVector.size());
|
||||
}
|
||||
|
||||
|
|
|
@ -252,9 +252,6 @@ public:
|
|||
// to. The writer sets a value.
|
||||
uint64_t OutSecOff = 0;
|
||||
|
||||
// Location of this section in the output buffer
|
||||
uint8_t *OutputLoc = nullptr;
|
||||
|
||||
// InputSection that is dependent on us (reverse dependency for GC)
|
||||
InputSectionBase<ELFT> *DependentSection = nullptr;
|
||||
|
||||
|
@ -344,9 +341,11 @@ public:
|
|||
|
||||
template <class ELFT> class BuildIdSection : public InputSection<ELFT> {
|
||||
public:
|
||||
virtual void writeBuildId(ArrayRef<uint8_t> Buf) = 0;
|
||||
virtual void writeBuildId(llvm::MutableArrayRef<uint8_t> Buf) = 0;
|
||||
virtual ~BuildIdSection() = default;
|
||||
|
||||
uint8_t *getOutputLoc(uint8_t *Start) const;
|
||||
|
||||
protected:
|
||||
BuildIdSection(size_t HashSize);
|
||||
std::vector<uint8_t> Buf;
|
||||
|
@ -356,32 +355,32 @@ template <class ELFT>
|
|||
class BuildIdFastHash final : public BuildIdSection<ELFT> {
|
||||
public:
|
||||
BuildIdFastHash() : BuildIdSection<ELFT>(8) {}
|
||||
void writeBuildId(ArrayRef<uint8_t> Buf) override;
|
||||
void writeBuildId(llvm::MutableArrayRef<uint8_t> Buf) override;
|
||||
};
|
||||
|
||||
template <class ELFT> class BuildIdMd5 final : public BuildIdSection<ELFT> {
|
||||
public:
|
||||
BuildIdMd5() : BuildIdSection<ELFT>(16) {}
|
||||
void writeBuildId(ArrayRef<uint8_t> Buf) override;
|
||||
void writeBuildId(llvm::MutableArrayRef<uint8_t> Buf) override;
|
||||
};
|
||||
|
||||
template <class ELFT> class BuildIdSha1 final : public BuildIdSection<ELFT> {
|
||||
public:
|
||||
BuildIdSha1() : BuildIdSection<ELFT>(20) {}
|
||||
void writeBuildId(ArrayRef<uint8_t> Buf) override;
|
||||
void writeBuildId(llvm::MutableArrayRef<uint8_t> Buf) override;
|
||||
};
|
||||
|
||||
template <class ELFT> class BuildIdUuid final : public BuildIdSection<ELFT> {
|
||||
public:
|
||||
BuildIdUuid() : BuildIdSection<ELFT>(16) {}
|
||||
void writeBuildId(ArrayRef<uint8_t> Buf) override;
|
||||
void writeBuildId(llvm::MutableArrayRef<uint8_t> Buf) override;
|
||||
};
|
||||
|
||||
template <class ELFT>
|
||||
class BuildIdHexstring final : public BuildIdSection<ELFT> {
|
||||
public:
|
||||
BuildIdHexstring();
|
||||
void writeBuildId(ArrayRef<uint8_t>) override;
|
||||
void writeBuildId(llvm::MutableArrayRef<uint8_t>) override;
|
||||
};
|
||||
|
||||
// Linker generated sections which can be used as inputs.
|
||||
|
|
Loading…
Reference in New Issue