[lld] r285691 - Don't store an OutputLoc in every InputSection.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 1 06:57:19 PDT 2016
Author: rafael
Date: Tue Nov 1 08:57:19 2016
New Revision: 285691
URL: http://llvm.org/viewvc/llvm-project?rev=285691&view=rev
Log:
Don't store an OutputLoc in every InputSection.
It was only used by build-id and that can easily compute it.
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/InputSection.h
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=285691&r1=285690&r2=285691&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Tue Nov 1 08:57:19 2016
@@ -482,9 +482,6 @@ template <class ELFT> void InputSection<
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(siz
}
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());
}
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=285691&r1=285690&r2=285691&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Tue Nov 1 08:57:19 2016
@@ -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.
More information about the llvm-commits
mailing list