<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Sep 1, 2016 at 3:43 PM, Petr Hosek via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: phosek<br>
Date: Thu Sep 1 17:43:03 2016<br>
New Revision: 280421<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=280421&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=280421&view=rev</a><br>
Log:<br>
[ELF] Do not omit debug sections when computing build-id<br>
<br>
The primary use of build-id is in debugging, hence omitting debug<br>
sections when computing it significantly reduces its usability as<br>
changes in debug section content wouldn't alter the build-id.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D24120" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D24120</a><br>
<br>
Modified:<br>
lld/trunk/ELF/OutputSections.<wbr>cpp<br>
lld/trunk/ELF/OutputSections.h<br>
lld/trunk/ELF/Writer.cpp<br>
<br>
Modified: lld/trunk/ELF/OutputSections.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=280421&r1=280420&r2=280421&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>OutputSections.cpp?rev=280421&<wbr>r1=280420&r2=280421&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/OutputSections.<wbr>cpp (original)<br>
+++ lld/trunk/ELF/OutputSections.<wbr>cpp Thu Sep 1 17:43:03 2016<br>
@@ -1657,40 +1657,36 @@ template <class ELFT> void BuildIdSectio<br>
}<br>
<br>
template <class ELFT><br>
-void BuildIdFnv1<ELFT>::<wbr>writeBuildId(ArrayRef<<wbr>ArrayRef<uint8_t>> Bufs) {<br>
+void BuildIdFnv1<ELFT>::<wbr>writeBuildId(ArrayRef<uint8_t> Buf) {<br>
const endianness E = ELFT::TargetEndianness;<br>
<br>
// 64-bit FNV-1 hash<br>
uint64_t Hash = 0xcbf29ce484222325;<br>
- for (ArrayRef<uint8_t> Buf : Bufs) {<br>
- for (uint8_t B : Buf) {<br>
- Hash *= 0x100000001b3;<br>
- Hash ^= B;<br>
- }<br>
+ for (uint8_t B : Buf) {<br>
+ Hash *= 0x100000001b3;<br>
+ Hash ^= B;<br>
}<br>
write64<E>(this->HashBuf, Hash);<br>
}<br>
<br>
template <class ELFT><br>
-void BuildIdMd5<ELFT>::<wbr>writeBuildId(ArrayRef<<wbr>ArrayRef<uint8_t>> Bufs) {<br>
+void BuildIdMd5<ELFT>::<wbr>writeBuildId(ArrayRef<uint8_t> Buf) {<br>
MD5 Hash;<br>
- for (ArrayRef<uint8_t> Buf : Bufs)<br>
- Hash.update(Buf);<br>
+ Hash.update(Buf);<br>
MD5::MD5Result Res;<br>
Hash.final(Res);<br>
memcpy(this->HashBuf, Res, 16);<br>
}<br>
<br>
template <class ELFT><br>
-void BuildIdSha1<ELFT>::<wbr>writeBuildId(ArrayRef<<wbr>ArrayRef<uint8_t>> Bufs) {<br>
+void BuildIdSha1<ELFT>::<wbr>writeBuildId(ArrayRef<uint8_t> Buf) {<br>
SHA1 Hash;<br>
- for (ArrayRef<uint8_t> Buf : Bufs)<br>
- Hash.update(Buf);<br>
+ Hash.update(Buf);<br>
memcpy(this->HashBuf, Hash.final().data(), 20);<br>
}<br>
<br>
template <class ELFT><br>
-void BuildIdUuid<ELFT>::<wbr>writeBuildId(ArrayRef<<wbr>ArrayRef<uint8_t>> Bufs) {<br>
+void BuildIdUuid<ELFT>::<wbr>writeBuildId(ArrayRef<uint8_t> Buf) {<br>
if (getRandomBytes(this->HashBuf, 16))<br>
error("entropy source failure");<br>
}<br>
@@ -1700,7 +1696,7 @@ BuildIdHexstring<ELFT>::<wbr>BuildIdHexstring<br>
: BuildIdSection<ELFT>(Config-><wbr>BuildIdVector.size()) {}<br>
<br>
template <class ELFT><br>
-void BuildIdHexstring<ELFT>::<wbr>writeBuildId(ArrayRef<<wbr>ArrayRef<uint8_t>> Bufs) {<br>
+void BuildIdHexstring<ELFT>::<wbr>writeBuildId(ArrayRef<uint8_t> Buf) {<br>
memcpy(this->HashBuf, Config->BuildIdVector.data(),<br>
Config->BuildIdVector.size());<br>
}<br>
<br>
Modified: lld/trunk/ELF/OutputSections.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=280421&r1=280420&r2=280421&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/<wbr>OutputSections.h?rev=280421&<wbr>r1=280420&r2=280421&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/OutputSections.h (original)<br>
+++ lld/trunk/ELF/OutputSections.h Thu Sep 1 17:43:03 2016<br>
@@ -700,7 +700,7 @@ template <class ELFT> class BuildIdSecti<br>
<br>
public:<br>
void writeTo(uint8_t *Buf) override;<br>
- virtual void writeBuildId(ArrayRef<<wbr>ArrayRef<uint8_t>> Bufs) = 0;<br>
+ virtual void writeBuildId(ArrayRef<uint8_t> Buf) = 0;<br>
typename Base::Kind getKind() const override { return Base::BuildId; }<br>
static bool classof(const Base *B) { return B->getKind() == Base::BuildId; }<br>
<br>
@@ -713,32 +713,32 @@ protected:<br>
template <class ELFT> class BuildIdFnv1 final : public BuildIdSection<ELFT> {<br>
public:<br>
BuildIdFnv1() : BuildIdSection<ELFT>(8) {}<br>
- void writeBuildId(ArrayRef<<wbr>ArrayRef<uint8_t>> Bufs) override;<br>
+ void writeBuildId(ArrayRef<uint8_t> Buf) override;<br>
};<br>
<br>
template <class ELFT> class BuildIdMd5 final : public BuildIdSection<ELFT> {<br>
public:<br>
BuildIdMd5() : BuildIdSection<ELFT>(16) {}<br>
- void writeBuildId(ArrayRef<<wbr>ArrayRef<uint8_t>> Bufs) override;<br>
+ void writeBuildId(ArrayRef<uint8_t> Buf) override;<br>
};<br>
<br>
template <class ELFT> class BuildIdSha1 final : public BuildIdSection<ELFT> {<br>
public:<br>
BuildIdSha1() : BuildIdSection<ELFT>(20) {}<br>
- void writeBuildId(ArrayRef<<wbr>ArrayRef<uint8_t>> Bufs) override;<br>
+ void writeBuildId(ArrayRef<uint8_t> Buf) override;<br>
};<br>
<br>
template <class ELFT> class BuildIdUuid final : public BuildIdSection<ELFT> {<br>
public:<br>
BuildIdUuid() : BuildIdSection<ELFT>(16) {}<br>
- void writeBuildId(ArrayRef<<wbr>ArrayRef<uint8_t>> Bufs) override;<br>
+ void writeBuildId(ArrayRef<uint8_t> Buf) override;<br>
};<br>
<br>
template <class ELFT><br>
class BuildIdHexstring final : public BuildIdSection<ELFT> {<br>
public:<br>
BuildIdHexstring();<br>
- void writeBuildId(ArrayRef<<wbr>ArrayRef<uint8_t>> Bufs) override;<br>
+ void writeBuildId(ArrayRef<uint8_t><wbr>) override;<br>
};<br>
<br>
// All output sections that are hadnled by the linker specially are<br>
<br>
Modified: lld/trunk/ELF/Writer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=280421&r1=280420&r2=280421&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/lld/trunk/ELF/Writer.<wbr>cpp?rev=280421&r1=280420&r2=<wbr>280421&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- lld/trunk/ELF/Writer.cpp (original)<br>
+++ lld/trunk/ELF/Writer.cpp Thu Sep 1 17:43:03 2016<br>
@@ -1320,21 +1320,10 @@ template <class ELFT> void Writer<ELFT>:<br>
if (!Out<ELFT>::BuildId)<br>
return;<br>
<br>
- // Compute a hash of all sections except .debug_* sections.<br>
- // We skip debug sections because they tend to be very large<br>
- // and their contents are very likely to be the same as long as<br>
- // other sections are the same.<br>
+ // Compute a hash of all sections of the output file.<br></blockquote><div><br></div><div>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.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
uint8_t *Start = Buffer->getBufferStart();<br>
- uint8_t *Last = Start;<br>
- std::vector<ArrayRef<uint8_t>> Regions;<br>
- for (OutputSectionBase<ELFT> *Sec : OutputSections) {<br>
- uint8_t *End = Start + Sec->getFileOff();<br>
- if (!Sec->getName().startswith(".<wbr>debug_"))<br>
- Regions.push_back({Last, End});<br>
- Last = End;<br>
- }<br>
- Regions.push_back({Last, Start + FileSize});<br>
- Out<ELFT>::BuildId-><wbr>writeBuildId(Regions);<br>
+ uint8_t *End = Start + FileSize;<br>
+ Out<ELFT>::BuildId-><wbr>writeBuildId({Start, End});<br>
}<br>
<br>
template void elf::writeResult<ELF32LE>();<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>