[lld] r280421 - [ELF] Do not omit debug sections when computing build-id
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 1 15:58:47 PDT 2016
On Thu, Sep 1, 2016 at 3:43 PM, Petr Hosek via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: phosek
> Date: Thu Sep 1 17:43:03 2016
> New Revision: 280421
>
> URL: http://llvm.org/viewvc/llvm-project?rev=280421&view=rev
> Log:
> [ELF] Do not omit debug sections when computing build-id
>
> The primary use of build-id is in debugging, hence omitting debug
> sections when computing it significantly reduces its usability as
> changes in debug section content wouldn't alter the build-id.
>
> Differential Revision: https://reviews.llvm.org/D24120
>
> Modified:
> lld/trunk/ELF/OutputSections.cpp
> lld/trunk/ELF/OutputSections.h
> lld/trunk/ELF/Writer.cpp
>
> Modified: lld/trunk/ELF/OutputSections.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/
> OutputSections.cpp?rev=280421&r1=280420&r2=280421&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/OutputSections.cpp (original)
> +++ lld/trunk/ELF/OutputSections.cpp Thu Sep 1 17:43:03 2016
> @@ -1657,40 +1657,36 @@ template <class ELFT> void BuildIdSectio
> }
>
> template <class ELFT>
> -void BuildIdFnv1<ELFT>::writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) {
> +void BuildIdFnv1<ELFT>::writeBuildId(ArrayRef<uint8_t> Buf) {
> const endianness E = ELFT::TargetEndianness;
>
> // 64-bit FNV-1 hash
> uint64_t Hash = 0xcbf29ce484222325;
> - for (ArrayRef<uint8_t> Buf : Bufs) {
> - for (uint8_t B : Buf) {
> - Hash *= 0x100000001b3;
> - Hash ^= B;
> - }
> + for (uint8_t B : Buf) {
> + Hash *= 0x100000001b3;
> + Hash ^= B;
> }
> write64<E>(this->HashBuf, Hash);
> }
>
> template <class ELFT>
> -void BuildIdMd5<ELFT>::writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) {
> +void BuildIdMd5<ELFT>::writeBuildId(ArrayRef<uint8_t> Buf) {
> MD5 Hash;
> - for (ArrayRef<uint8_t> Buf : Bufs)
> - Hash.update(Buf);
> + Hash.update(Buf);
> MD5::MD5Result Res;
> Hash.final(Res);
> memcpy(this->HashBuf, Res, 16);
> }
>
> template <class ELFT>
> -void BuildIdSha1<ELFT>::writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) {
> +void BuildIdSha1<ELFT>::writeBuildId(ArrayRef<uint8_t> Buf) {
> SHA1 Hash;
> - for (ArrayRef<uint8_t> Buf : Bufs)
> - Hash.update(Buf);
> + Hash.update(Buf);
> memcpy(this->HashBuf, Hash.final().data(), 20);
> }
>
> template <class ELFT>
> -void BuildIdUuid<ELFT>::writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) {
> +void BuildIdUuid<ELFT>::writeBuildId(ArrayRef<uint8_t> Buf) {
> if (getRandomBytes(this->HashBuf, 16))
> error("entropy source failure");
> }
> @@ -1700,7 +1696,7 @@ BuildIdHexstring<ELFT>::BuildIdHexstring
> : BuildIdSection<ELFT>(Config->BuildIdVector.size()) {}
>
> template <class ELFT>
> -void BuildIdHexstring<ELFT>::writeBuildId(ArrayRef<ArrayRef<uint8_t>>
> Bufs) {
> +void BuildIdHexstring<ELFT>::writeBuildId(ArrayRef<uint8_t> Buf) {
> memcpy(this->HashBuf, Config->BuildIdVector.data(),
> Config->BuildIdVector.size());
> }
>
> Modified: lld/trunk/ELF/OutputSections.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/
> OutputSections.h?rev=280421&r1=280420&r2=280421&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/OutputSections.h (original)
> +++ lld/trunk/ELF/OutputSections.h Thu Sep 1 17:43:03 2016
> @@ -700,7 +700,7 @@ template <class ELFT> class BuildIdSecti
>
> public:
> void writeTo(uint8_t *Buf) override;
> - virtual void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) = 0;
> + virtual void writeBuildId(ArrayRef<uint8_t> Buf) = 0;
> typename Base::Kind getKind() const override { return Base::BuildId; }
> static bool classof(const Base *B) { return B->getKind() ==
> Base::BuildId; }
>
> @@ -713,32 +713,32 @@ protected:
> template <class ELFT> class BuildIdFnv1 final : public
> BuildIdSection<ELFT> {
> public:
> BuildIdFnv1() : BuildIdSection<ELFT>(8) {}
> - void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
> + void writeBuildId(ArrayRef<uint8_t> Buf) override;
> };
>
> template <class ELFT> class BuildIdMd5 final : public
> BuildIdSection<ELFT> {
> public:
> BuildIdMd5() : BuildIdSection<ELFT>(16) {}
> - void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
> + void writeBuildId(ArrayRef<uint8_t> Buf) override;
> };
>
> template <class ELFT> class BuildIdSha1 final : public
> BuildIdSection<ELFT> {
> public:
> BuildIdSha1() : BuildIdSection<ELFT>(20) {}
> - void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
> + void writeBuildId(ArrayRef<uint8_t> Buf) override;
> };
>
> template <class ELFT> class BuildIdUuid final : public
> BuildIdSection<ELFT> {
> public:
> BuildIdUuid() : BuildIdSection<ELFT>(16) {}
> - void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
> + void writeBuildId(ArrayRef<uint8_t> Buf) override;
> };
>
> template <class ELFT>
> class BuildIdHexstring final : public BuildIdSection<ELFT> {
> public:
> BuildIdHexstring();
> - void writeBuildId(ArrayRef<ArrayRef<uint8_t>> Bufs) override;
> + void writeBuildId(ArrayRef<uint8_t>) override;
> };
>
> // All output sections that are hadnled by the linker specially are
>
> Modified: lld/trunk/ELF/Writer.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.
> cpp?rev=280421&r1=280420&r2=280421&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/Writer.cpp (original)
> +++ lld/trunk/ELF/Writer.cpp Thu Sep 1 17:43:03 2016
> @@ -1320,21 +1320,10 @@ template <class ELFT> void Writer<ELFT>:
> if (!Out<ELFT>::BuildId)
> return;
>
> - // Compute a hash of all sections except .debug_* sections.
> - // We skip debug sections because they tend to be very large
> - // and their contents are very likely to be the same as long as
> - // other sections are the same.
> + // Compute a hash of all sections of the output file.
>
I was trying to say "compute a hash of the output file" because it does not
include only output sections but also headers, trailers and padding between
sections.
uint8_t *Start = Buffer->getBufferStart();
> - uint8_t *Last = Start;
> - std::vector<ArrayRef<uint8_t>> Regions;
> - for (OutputSectionBase<ELFT> *Sec : OutputSections) {
> - uint8_t *End = Start + Sec->getFileOff();
> - if (!Sec->getName().startswith(".debug_"))
> - Regions.push_back({Last, End});
> - Last = End;
> - }
> - Regions.push_back({Last, Start + FileSize});
> - Out<ELFT>::BuildId->writeBuildId(Regions);
> + uint8_t *End = Start + FileSize;
> + Out<ELFT>::BuildId->writeBuildId({Start, End});
> }
>
> template void elf::writeResult<ELF32LE>();
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160901/a39256da/attachment.html>
More information about the llvm-commits
mailing list