Skip to content

Commit ef46d4e

Browse files
author
git apple-llvm automerger
committed
Merge commit 'c5c002da31be' from swift/release/5.5 into swift/main
2 parents 4d40e13 + c5c002d commit ef46d4e

File tree

3 files changed

+57
-12
lines changed

3 files changed

+57
-12
lines changed
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
; Verify that llvm-dwarfdump doesn't crash on broken input files.
22

3-
RUN: not llvm-dwarfdump %p/Inputs/invalid.elf 2>&1 | FileCheck %s --check-prefix=INVALID-ELF
4-
RUN: not llvm-dwarfdump %p/Inputs/invalid.elf.2 2>&1 | FileCheck %s --check-prefix=INVALID-ELF
5-
RUN: not llvm-dwarfdump %p/Inputs/invalid.elf.3 2>&1 | FileCheck %s --check-prefix=INVALID-ELF
6-
INVALID-ELF: Invalid data was encountered while parsing the file
3+
RUN: not llvm-dwarfdump %p/Inputs/invalid.elf 2>&1 | FileCheck %s --check-prefix=INVALID-ELF1
4+
RUN: not llvm-dwarfdump %p/Inputs/invalid.elf.2 2>&1 | FileCheck %s --check-prefix=INVALID-ELF2
5+
RUN: not llvm-dwarfdump %p/Inputs/invalid.elf.3 2>&1 | FileCheck %s --check-prefix=INVALID-ELF3
6+
INVALID-ELF1: section header table goes past the end of the file
7+
INVALID-ELF2: Invalid ELF data
8+
INVALID-ELF3: Invalid ELF class
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# RUN: yaml2obj %s | not llvm-dwarfdump --uuid - 2>&1 | FileCheck %s
2+
# CHECK: load command 0 filesize field in LC_SEGMENT_64 greater than vmsize field
3+
4+
--- !mach-o
5+
FileHeader:
6+
magic: 0xFEEDFACF
7+
cputype: 0x01000007
8+
cpusubtype: 0x00000003
9+
filetype: 0x00000001
10+
ncmds: 1
11+
sizeofcmds: 24
12+
flags: 0x00002000
13+
reserved: 0x00000000
14+
LoadCommands:
15+
- cmd: LC_SEGMENT_64
16+
cmdsize: 232
17+
segname: ''
18+
vmaddr: 0
19+
vmsize: 80
20+
fileoff: 384
21+
filesize: 81
22+
maxprot: 7
23+
initprot: 7
24+
nsects: 1
25+
flags: 0
26+
Sections:
27+
- sectname: __text
28+
segname: __TEXT
29+
addr: 0x0000000000000000
30+
size: 15
31+
offset: 0x00000180
32+
align: 4
33+
reloff: 0x00000000
34+
nreloc: 0
35+
flags: 0x80000400
36+
reserved1: 0x00000000
37+
reserved2: 0x00000000
38+
reserved3: 0x00000000
39+
...

llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,17 @@ static cl::extrahelp
257257
/// @}
258258
//===----------------------------------------------------------------------===//
259259

260-
static void error(StringRef Prefix, std::error_code EC) {
261-
if (!EC)
260+
static void error(StringRef Prefix, Error Err) {
261+
if (!Err)
262262
return;
263-
WithColor::error() << Prefix << ": " << EC.message() << "\n";
263+
WithColor::error() << Prefix << ": " << toString(std::move(Err)) << "\n";
264264
exit(1);
265265
}
266266

267+
static void error(StringRef Prefix, std::error_code EC) {
268+
error(Prefix, errorCodeToError(EC));
269+
}
270+
267271
static DIDumpOptions getDumpOpts(DWARFContext &C) {
268272
DIDumpOptions DumpOpts;
269273
DumpOpts.DumpType = DumpType;
@@ -502,21 +506,21 @@ static bool handleArchive(StringRef Filename, Archive &Arch,
502506
Error Err = Error::success();
503507
for (auto Child : Arch.children(Err)) {
504508
auto BuffOrErr = Child.getMemoryBufferRef();
505-
error(Filename, errorToErrorCode(BuffOrErr.takeError()));
509+
error(Filename, BuffOrErr.takeError());
506510
auto NameOrErr = Child.getName();
507-
error(Filename, errorToErrorCode(NameOrErr.takeError()));
511+
error(Filename, NameOrErr.takeError());
508512
std::string Name = (Filename + "(" + NameOrErr.get() + ")").str();
509513
Result &= handleBuffer(Name, BuffOrErr.get(), HandleObj, OS);
510514
}
511-
error(Filename, errorToErrorCode(std::move(Err)));
515+
error(Filename, std::move(Err));
512516

513517
return Result;
514518
}
515519

516520
static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer,
517521
HandlerFn HandleObj, raw_ostream &OS) {
518522
Expected<std::unique_ptr<Binary>> BinOrErr = object::createBinary(Buffer);
519-
error(Filename, errorToErrorCode(BinOrErr.takeError()));
523+
error(Filename, BinOrErr.takeError());
520524

521525
bool Result = true;
522526
auto RecoverableErrorHandler = [&](Error E) {
@@ -547,7 +551,7 @@ static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer,
547551
} else
548552
consumeError(MachOOrErr.takeError());
549553
if (auto ArchiveOrErr = ObjForArch.getAsArchive()) {
550-
error(ObjName, errorToErrorCode(ArchiveOrErr.takeError()));
554+
error(ObjName, ArchiveOrErr.takeError());
551555
if (!handleArchive(ObjName, *ArchiveOrErr.get(), HandleObj, OS))
552556
Result = false;
553557
continue;

0 commit comments

Comments
 (0)