llvm.org GIT mirror llvm / d7c5a21
[llvm-objcopy] Improve error message for unrecognised archive member Prior to this patch, llvm-objcopy's error messages for archives with unsupported members only mentioned the archive name, not the member name, making them unhelpful. This change improves it by approximately following GNU objcopy's error message syntax of "<archive name>(<member name>): <problem>". Reviewed by: grimar Differential Revision: https://reviews.llvm.org/D61674 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360251 91177308-0d34-0410-b5e6-96231b3b80d8 James Henderson 5 months ago
2 changed file(s) with 51 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
0 ## Show that llvm-objcopy and llvm-strip emit errors when attempting to modify
1 ## archives containing unrecognized files, and do not modify anything. We use
2 ## --strip-debug so that the section should be removed, and a difference
3 ## detectable, if the file were modified.
4
5 # RUN: yaml2obj %s -o %t.o
6 # RUN: rm -f %t.a
7 # RUN: llvm-ar rc %t.a %t.o %s
8 # RUN: cp %t.a %t1.a
9 # RUN: cp %t.a %t2.a
10
11 # RUN: not llvm-objcopy --strip-debug %t1.a 2>&1 | FileCheck %s -DARCHIVE=%t1.a
12 # RUN: not llvm-strip --strip-debug %t2.a 2>&1 | FileCheck %s -DARCHIVE=%t2.a
13 ## Verify that the archive was not modified, if any member couldn't be recognised.
14 # RUN: cmp %t.a %t1.a
15 # RUN: cmp %t.a %t2.a
16
17 # CHECK: error: '[[ARCHIVE]](archive-unknown-members.test)': The file was not recognized as a valid object file
18
19 # RUN: rm -f %t.thin1.a %t.thin2.a
20 # RUN: cp %t.o %t1.o
21 # RUN: cp %t.o %t2.o
22 # RUN: llvm-ar rcT %t.thin1.a %t1.o %s
23 # RUN: llvm-ar rcT %t.thin2.a %t2.o %s
24
25 # RUN: not llvm-objcopy --strip-debug %t.thin1.a 2>&1 \
26 # RUN: | FileCheck %s --check-prefix=THIN -DARCHIVE=%t.thin1.a -DMEMBER=%s
27 # RUN: not llvm-strip --strip-debug %t.thin2.a 2>&1 \
28 # RUN: | FileCheck %s --check-prefix=THIN -DARCHIVE=%t.thin2.a -DMEMBER=%s
29 ## Verify that the first member was not modified, if a later member could not
30 ## be recognised.
31 # RUN: cmp %t.o %t1.o
32 # RUN: cmp %t.o %t2.o
33
34 # THIN: error: '[[ARCHIVE]]([[MEMBER]])': The file was not recognized as a valid object file
35
36 --- !ELF
37 FileHeader:
38 Class: ELFCLASS64
39 Data: ELFDATA2LSB
40 Type: ET_EXEC
41 Machine: EM_X86_64
42 Sections:
43 - Name: .debug_foo
44 Type: SHT_PROGBITS
153153 std::vector NewArchiveMembers;
154154 Error Err = Error::success();
155155 for (const Archive::Child &Child : Ar.children(Err)) {
156 Expected> ChildOrErr = Child.getAsBinary();
157 if (!ChildOrErr)
158 return createFileError(Ar.getFileName(), ChildOrErr.takeError());
159 Binary *Bin = ChildOrErr->get();
160
161156 Expected ChildNameOrErr = Child.getName();
162157 if (!ChildNameOrErr)
163158 return createFileError(Ar.getFileName(), ChildNameOrErr.takeError());
164159
160 Expected> ChildOrErr = Child.getAsBinary();
161 if (!ChildOrErr)
162 return createFileError(Ar.getFileName() + "(" + *ChildNameOrErr + ")",
163 ChildOrErr.takeError());
164
165165 MemBuffer MB(ChildNameOrErr.get());
166 if (Error E = executeObjcopyOnBinary(Config, *Bin, MB))
166 if (Error E = executeObjcopyOnBinary(Config, *ChildOrErr->get(), MB))
167167 return E;
168168
169169 Expected Member =