<div dir="ltr">Hey sorry about that guys, yes, I didn't mean to commit this just yet. Thanks for reverting it!</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jan 25, 2018 at 1:10 PM Aaron Ballman via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, Jan 17, 2018 at 7:51 PM, Justin Bogner via llvm-commits<br>
<<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br>
> Jake Ehrlich via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> writes:<br>
>> Author: jakehehrlich<br>
>> Date: Tue Jan 9 15:00:25 2018<br>
>> New Revision: 322132<br>
>><br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=322132&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=322132&view=rev</a><br>
>> Log:<br>
>> temp<br>
><br>
> This looks like an accidental commit? Should it be reverted (and<br>
> possibly recommitted at some point with an actual commit message)?<br>
<br>
Because the author has not responded to this or improved the commit<br>
message, I've reverted in r323466.<br>
<br>
~Aaron<br>
<br>
><br>
>> Added:<br>
>> llvm/trunk/test/tools/llvm-objcopy/add-gnu-debuglink.test<br>
>> Modified:<br>
>> llvm/trunk/tools/llvm-objcopy/Object.cpp<br>
>> llvm/trunk/tools/llvm-objcopy/Object.h<br>
>> llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp<br>
>><br>
>> Added: llvm/trunk/test/tools/llvm-objcopy/add-gnu-debuglink.test<br>
>> URL:<br>
>> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/add-gnu-debuglink.test?rev=322132&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/add-gnu-debuglink.test?rev=322132&view=auto</a><br>
>> ==============================================================================<br>
>><br>
>> --- llvm/trunk/test/tools/llvm-objcopy/add-gnu-debuglink.test (added)<br>
>> +++ llvm/trunk/test/tools/llvm-objcopy/add-gnu-debuglink.test Tue Jan 9 15:00:25 2018<br>
>> @@ -0,0 +1,27 @@<br>
>> +# RUN: yaml2obj %s > %t<br>
>> +# RUN: printf 0000 > %t.blob<br>
>> +# RUN: llvm-objcopy -add-gnu-debuglink=%t.blob %t %t2<br>
>> +# RUN: llvm-readobj -sections -section-data %t2 | FileCheck %s<br>
>> +<br>
>> +!ELF<br>
>> +FileHeader:<br>
>> + Class: ELFCLASS64<br>
>> + Data: ELFDATA2LSB<br>
>> + Type: ET_EXEC<br>
>> + Machine: EM_X86_64<br>
>> +<br>
>> +# CHECK: Name: .gnu_debuglink<br>
>> +# CHECK-NEXT: Type: SHT_PROGBITS (0x1)<br>
>> +# CHECK-NEXT: Flags [ (0x0)<br>
>> +# CHECK-NEXT: ]<br>
>> +# CHECK-NEXT: Address: 0x0<br>
>> +# CHECK-NEXT: Offset:<br>
>> +# CHECK-NEXT: Size: 32<br>
>> +# CHECK-NEXT: Link: 0<br>
>> +# CHECK-NEXT: Info: 0<br>
>> +# CHECK-NEXT: AddressAlignment: 4<br>
>> +# CHECK-NEXT: EntrySize: 0<br>
>> +# CHECK-NEXT: SectionData (<br>
>> +# CHECK-NEXT: 0000: 6164642D 676E752D 64656275 676C696E |add-gnu-debuglin|<br>
>> +# CHECK-NEXT: 0010: 6B2E7465 73742E74 6D700000 72C49B0C |k.test.tmp..r...|<br>
>> +# CHECK-NEXT: )<br>
>><br>
>> Modified: llvm/trunk/tools/llvm-objcopy/Object.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/Object.cpp?rev=322132&r1=322131&r2=322132&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/Object.cpp?rev=322132&r1=322131&r2=322132&view=diff</a><br>
>> ==============================================================================<br>
>> --- llvm/trunk/tools/llvm-objcopy/Object.cpp (original)<br>
>> +++ llvm/trunk/tools/llvm-objcopy/Object.cpp Tue Jan 9 15:00:25 2018<br>
>> @@ -18,6 +18,7 @@<br>
>> #include "llvm/Object/ELFObjectFile.h"<br>
>> #include "llvm/Support/ErrorHandling.h"<br>
>> #include "llvm/Support/FileOutputBuffer.h"<br>
>> +#include "llvm/Support/Path.h"<br>
>> #include <algorithm><br>
>> #include <cstddef><br>
>> #include <cstdint><br>
>> @@ -343,6 +344,50 @@ void SectionWithStrTab::initialize(Secti<br>
>><br>
>> void SectionWithStrTab::finalize() { this->Link = StrTab->Index; }<br>
>><br>
>> +template <class ELFT><br>
>> +void GnuDebugLinkSection<ELFT>::init(StringRef File, StringRef Data) {<br>
>> + FileName = sys::path::stem(File);<br>
>> + // The format for the .gnu_debuglink starts with the stemmed file name and is<br>
>> + // followed by a null terminator and then the CRC32 of the file. The CRC32<br>
>> + // should be 4 byte aligned. So we add the FileName size, a 1 for the null<br>
>> + // byte, and then finally push the size to alignment and add 4.<br>
>> + Size = alignTo(FileName.size() + 1, 4) + 4;<br>
>> + // The CRC32 will only be aligned if we align the whole section.<br>
>> + Align = 4;<br>
>> + Type = ELF::SHT_PROGBITS;<br>
>> + Name = ".gnu_debuglink";<br>
>> + // For sections not found in segments, OriginalOffset is only used to<br>
>> + // establish the order that sections should go in. By using the maximum<br>
>> + // possible offset we cause this section to wind up at the end.<br>
>> + OriginalOffset = std::numeric_limits<uint64_t>::max();<br>
>> + JamCRC crc;<br>
>> + crc.update(ArrayRef<char>(Data.data(), Data.size()));<br>
>> + // The CRC32 value needs to be complemented because the JamCRC dosn't<br>
>> + // finalize the CRC32 value. It also dosn't negate the initial CRC32 value<br>
>> + // but it starts by default at 0xFFFFFFFF which is the complement of zero.<br>
>> + CRC32 = ~crc.getCRC();<br>
>> +}<br>
>> +<br>
>> +template <class ELFT><br>
>> +GnuDebugLinkSection<ELFT>::GnuDebugLinkSection(StringRef File)<br>
>> + : FileName(File) {<br>
>> + // Read in the file to compute the CRC of it.<br>
>> + auto DebugOrErr = MemoryBuffer::getFile(File);<br>
>> + if (!DebugOrErr)<br>
>> + error("'" + File + "': " + DebugOrErr.getError().message());<br>
>> + auto Debug = std::move(*DebugOrErr);<br>
>> + init(File, Debug->getBuffer());<br>
>> +}<br>
>> +<br>
>> +template <class ELFT><br>
>> +void GnuDebugLinkSection<ELFT>::writeSection(FileOutputBuffer &Out) const {<br>
>> + auto Buf = Out.getBufferStart() + Offset;<br>
>> + char *File = reinterpret_cast<char *>(Buf);<br>
>> + Elf_Word *CRC = reinterpret_cast<Elf_Word *>(Buf + Size - sizeof(Elf_Word));<br>
>> + *CRC = CRC32;<br>
>> + std::copy(std::begin(FileName), std::end(FileName), File);<br>
>> +}<br>
>> +<br>
>> // Returns true IFF a section is wholly inside the range of a segment<br>
>> static bool sectionWithinSegment(const SectionBase &Section,<br>
>> const Segment &Segment) {<br>
>> @@ -710,6 +755,10 @@ void Object<ELFT>::addSection(StringRef<br>
>> Sections.push_back(std::move(Sec));<br>
>> }<br>
>><br>
>> +template <class ELFT> void Object<ELFT>::addGnuDebugLink(StringRef File) {<br>
>> + Sections.emplace_back(llvm::make_unique<GnuDebugLinkSection<ELFT>>(File));<br>
>> +}<br>
>> +<br>
>> template <class ELFT> void ELFObject<ELFT>::sortSections() {<br>
>> // Put all sections in offset order. Maintain the ordering as closely as<br>
>> // possible while meeting that demand however.<br>
>><br>
>> Modified: llvm/trunk/tools/llvm-objcopy/Object.h<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/Object.h?rev=322132&r1=322131&r2=322132&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/Object.h?rev=322132&r1=322131&r2=322132&view=diff</a><br>
>> ==============================================================================<br>
>> --- llvm/trunk/tools/llvm-objcopy/Object.h (original)<br>
>> +++ llvm/trunk/tools/llvm-objcopy/Object.h Tue Jan 9 15:00:25 2018<br>
>> @@ -16,6 +16,7 @@<br>
>> #include "llvm/BinaryFormat/ELF.h"<br>
>> #include "llvm/MC/StringTableBuilder.h"<br>
>> #include "llvm/Object/ELFObjectFile.h"<br>
>> +#include "llvm/Support/JamCRC.h"<br>
>> #include <cstddef><br>
>> #include <cstdint><br>
>> #include <functional><br>
>> @@ -345,6 +346,24 @@ public:<br>
>> }<br>
>> };<br>
>><br>
>> +template <class ELFT> class GnuDebugLinkSection : public SectionBase {<br>
>> +private:<br>
>> + // Elf_Word is 4-bytes on every format but has the same endianess as the elf<br>
>> + // type ELFT. We'll need to write the CRC32 out in the proper endianess so<br>
>> + // we'll make sure to use this type.<br>
>> + using Elf_Word = typename ELFT::Word;<br>
>> +<br>
>> + StringRef FileName;<br>
>> + uint32_t CRC32;<br>
>> +<br>
>> + void init(StringRef File, StringRef Data);<br>
>> +<br>
>> +public:<br>
>> + // If we add this section from an external source we can use this ctor.<br>
>> + GnuDebugLinkSection(StringRef File);<br>
>> + void writeSection(FileOutputBuffer &Out) const override;<br>
>> +};<br>
>> +<br>
>> template <class ELFT> class Object {<br>
>> private:<br>
>> using SecPtr = std::unique_ptr<SectionBase>;<br>
>> @@ -389,6 +408,7 @@ public:<br>
>> const SectionBase *getSectionHeaderStrTab() const { return SectionNames; }<br>
>> void removeSections(std::function<bool(const SectionBase &)> ToRemove);<br>
>> void addSection(StringRef SecName, ArrayRef<uint8_t> Data);<br>
>> + void addGnuDebugLink(StringRef File);<br>
>> virtual size_t totalSize() const = 0;<br>
>> virtual void finalize() = 0;<br>
>> virtual void write(FileOutputBuffer &Out) const = 0;<br>
>><br>
>> Modified: llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp?rev=322132&r1=322131&r2=322132&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp?rev=322132&r1=322131&r2=322132&view=diff</a><br>
>> ==============================================================================<br>
>> --- llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp (original)<br>
>> +++ llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp Tue Jan 9 15:00:25 2018<br>
>> @@ -121,6 +121,10 @@ static cl::opt<bool> LocalizeHidden(<br>
>> "localize-hidden",<br>
>> cl::desc(<br>
>> "Mark all symbols that have hidden or internal visibility as local"));<br>
>> +static cl::opt<std::string><br>
>> + AddGnuDebugLink("add-gnu-debuglink",<br>
>> + cl::desc("adds a .gnu_debuglink for <debug-file>"),<br>
>> + cl::value_desc("debug-file"));<br>
>><br>
>> using SectionPred = std::function<bool(const SectionBase &Sec)>;<br>
>><br>
>> @@ -318,6 +322,10 @@ template <class ELFT> void CopyBinary(co<br>
>> }<br>
>> }<br>
>><br>
>> + if (!AddGnuDebugLink.empty()) {<br>
>> + Obj->addGnuDebugLink(AddGnuDebugLink);<br>
>> + }<br>
>> +<br>
>> Obj->finalize();<br>
>> WriteObjectFile(*Obj, OutputFilename.getValue());<br>
>> }<br>
>><br>
>><br>
>> _______________________________________________<br>
>> llvm-commits mailing list<br>
>> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">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/mailman/listinfo/llvm-commits</a><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">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/mailman/listinfo/llvm-commits</a><br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">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/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>