Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit e0a63eb

Browse files
committed
Revert "[llvm-objcopy] [COFF] Implement --add-gnu-debuglink"
This reverts commit r351801, as it caused errors on (so far) ppc64be and aarch64 buildbots - the reason is yet unknown. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351811 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 598d00e commit e0a63eb

File tree

6 files changed

+7
-137
lines changed

6 files changed

+7
-137
lines changed

test/tools/llvm-objcopy/COFF/add-gnu-debuglink.test

Lines changed: 0 additions & 42 deletions
This file was deleted.

tools/llvm-objcopy/COFF/COFFObjcopy.cpp

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include "llvm/Object/Binary.h"
1818
#include "llvm/Object/COFF.h"
1919
#include "llvm/Support/Errc.h"
20-
#include "llvm/Support/JamCRC.h"
21-
#include "llvm/Support/Path.h"
2220
#include <cassert>
2321

2422
namespace llvm {
@@ -32,61 +30,6 @@ static bool isDebugSection(const Section &Sec) {
3230
return Sec.Name.startswith(".debug");
3331
}
3432

35-
static uint64_t getNextRVA(const Object &Obj) {
36-
if (Obj.getSections().empty())
37-
return 0;
38-
const Section &Last = Obj.getSections().back();
39-
return alignTo(Last.Header.VirtualAddress + Last.Header.VirtualSize,
40-
Obj.PeHeader.SectionAlignment);
41-
}
42-
43-
static uint32_t getCRC32(StringRef Data) {
44-
JamCRC CRC;
45-
CRC.update(ArrayRef<char>(Data.data(), Data.size()));
46-
// The CRC32 value needs to be complemented because the JamCRC dosn't
47-
// finalize the CRC32 value. It also dosn't negate the initial CRC32 value
48-
// but it starts by default at 0xFFFFFFFF which is the complement of zero.
49-
return ~CRC.getCRC();
50-
}
51-
52-
static std::vector<uint8_t> createGnuDebugLinkSectionContents(StringRef File) {
53-
ErrorOr<std::unique_ptr<MemoryBuffer>> LinkTargetOrErr =
54-
MemoryBuffer::getFile(File);
55-
if (!LinkTargetOrErr)
56-
error("'" + File + "': " + LinkTargetOrErr.getError().message());
57-
auto LinkTarget = std::move(*LinkTargetOrErr);
58-
uint32_t CRC32 = getCRC32(LinkTarget->getBuffer());
59-
60-
StringRef FileName = sys::path::filename(File);
61-
size_t CRCPos = alignTo(FileName.size() + 1, 4);
62-
std::vector<uint8_t> Data(CRCPos + 4);
63-
memcpy(Data.data(), FileName.data(), FileName.size());
64-
support::endian::write32le(Data.data() + CRCPos, CRC32);
65-
return Data;
66-
}
67-
68-
static void addGnuDebugLink(Object &Obj, StringRef DebugLinkFile) {
69-
uint32_t StartRVA = getNextRVA(Obj);
70-
71-
std::vector<Section> Sections;
72-
Section Sec;
73-
Sec.setOwnedContents(createGnuDebugLinkSectionContents(DebugLinkFile));
74-
Sec.Name = ".gnu_debuglink";
75-
Sec.Header.VirtualSize = Sec.getContents().size();
76-
Sec.Header.VirtualAddress = StartRVA;
77-
Sec.Header.SizeOfRawData =
78-
alignTo(Sec.Header.VirtualSize, Obj.PeHeader.FileAlignment);
79-
// Sec.Header.PointerToRawData is filled in by the writer.
80-
Sec.Header.PointerToRelocations = 0;
81-
Sec.Header.PointerToLinenumbers = 0;
82-
// Sec.Header.NumberOfRelocations is filled in by the writer.
83-
Sec.Header.NumberOfLinenumbers = 0;
84-
Sec.Header.Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA |
85-
IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE;
86-
Sections.push_back(Sec);
87-
Obj.addSections(Sections);
88-
}
89-
9033
static Error handleArgs(const CopyConfig &Config, Object &Obj) {
9134
// Perform the actual section removals.
9235
Obj.removeSections([&Config](const Section &Sec) {
@@ -166,10 +109,6 @@ static Error handleArgs(const CopyConfig &Config, Object &Obj) {
166109

167110
return false;
168111
});
169-
170-
if (!Config.AddGnuDebugLink.empty())
171-
addGnuDebugLink(Obj, Config.AddGnuDebugLink);
172-
173112
return Error::success();
174113
}
175114

tools/llvm-objcopy/COFF/Object.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void Object::removeSections(function_ref<bool(const Section &)> ToRemove) {
129129
void Object::truncateSections(function_ref<bool(const Section &)> ToTruncate) {
130130
for (Section &Sec : Sections) {
131131
if (ToTruncate(Sec)) {
132-
Sec.clearContents();
132+
Sec.Contents = ArrayRef<uint8_t>();
133133
Sec.Relocs.clear();
134134
Sec.Header.SizeOfRawData = 0;
135135
}

tools/llvm-objcopy/COFF/Object.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,35 +35,11 @@ struct Relocation {
3535

3636
struct Section {
3737
object::coff_section Header;
38+
ArrayRef<uint8_t> Contents;
3839
std::vector<Relocation> Relocs;
3940
StringRef Name;
4041
ssize_t UniqueId;
4142
size_t Index;
42-
43-
ArrayRef<uint8_t> getContents() const {
44-
if (!OwnedContents.empty())
45-
return OwnedContents;
46-
return ContentsRef;
47-
}
48-
49-
void setContentsRef(ArrayRef<uint8_t> Data) {
50-
OwnedContents.clear();
51-
ContentsRef = Data;
52-
}
53-
54-
void setOwnedContents(std::vector<uint8_t> &&Data) {
55-
ContentsRef = ArrayRef<uint8_t>();
56-
OwnedContents = std::move(Data);
57-
}
58-
59-
void clearContents() {
60-
ContentsRef = ArrayRef<uint8_t>();
61-
OwnedContents.clear();
62-
}
63-
64-
private:
65-
ArrayRef<uint8_t> ContentsRef;
66-
std::vector<uint8_t> OwnedContents;
6743
};
6844

6945
struct Symbol {

tools/llvm-objcopy/COFF/Reader.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ Error COFFReader::readSections(Object &Obj) const {
6969
Sections.push_back(Section());
7070
Section &S = Sections.back();
7171
S.Header = *Sec;
72-
ArrayRef<uint8_t> Contents;
73-
if (auto EC = COFFObj.getSectionContents(Sec, Contents))
72+
if (auto EC = COFFObj.getSectionContents(Sec, S.Contents))
7473
return errorCodeToError(EC);
75-
S.setContentsRef(Contents);
7674
ArrayRef<coff_relocation> Relocs = COFFObj.getRelocations(Sec);
7775
for (const coff_relocation &R : Relocs)
7876
S.Relocs.push_back(R);

tools/llvm-objcopy/COFF/Writer.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,14 @@ void COFFWriter::writeHeaders(bool IsBigObj) {
286286
void COFFWriter::writeSections() {
287287
for (const auto &S : Obj.getSections()) {
288288
uint8_t *Ptr = Buf.getBufferStart() + S.Header.PointerToRawData;
289-
ArrayRef<uint8_t> Contents = S.getContents();
290-
std::copy(Contents.begin(), Contents.end(), Ptr);
289+
std::copy(S.Contents.begin(), S.Contents.end(), Ptr);
291290

292291
// For executable sections, pad the remainder of the raw data size with
293292
// 0xcc, which is int3 on x86.
294293
if ((S.Header.Characteristics & IMAGE_SCN_CNT_CODE) &&
295-
S.Header.SizeOfRawData > Contents.size())
296-
memset(Ptr + Contents.size(), 0xcc,
297-
S.Header.SizeOfRawData - Contents.size());
294+
S.Header.SizeOfRawData > S.Contents.size())
295+
memset(Ptr + S.Contents.size(), 0xcc,
296+
S.Header.SizeOfRawData - S.Contents.size());
298297

299298
Ptr += S.Header.SizeOfRawData;
300299
for (const auto &R : S.Relocs) {

0 commit comments

Comments
 (0)