llvm.org GIT mirror llvm / 5cebded
[llvm-readobj/llvm-readelf] - Don't fail to dump the object if .dynsym has broken sh_link field. This is https://bugs.llvm.org/show_bug.cgi?id=42215. GNU readelf allows to dump the objects in that case, but llvm-readobj/llvm-readelf reports an error and stops. The patch fixes that. Differential revision: https://reviews.llvm.org/D63074 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362938 91177308-0d34-0410-b5e6-96231b3b80d8 George Rimar 11 months ago
6 changed file(s) with 78 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
0 ## Test that we are able to dump section headers even if the
1 ## .dynsym section's sh_link field is broken.
2
3 ## Case 1: sh_link is set to 0.
4 # RUN: yaml2obj %s -o %t1
5 # RUN: llvm-readobj -S %t1 2>&1 | FileCheck %s --check-prefixes=LLVM,ERR
6 # RUN: llvm-readelf -S %t1 2>&1 | FileCheck %s --check-prefixes=GNU,ERR
7
8 # ERR: warning: invalid sh_type for string table, expected SHT_STRTAB
9
10 # LLVM: Name: .dynsym
11 # LLVM-NEXT: Type: SHT_DYNSYM
12 # LLVM-NEXT: Flags [
13 # LLVM-NEXT: SHF_ALLOC
14 # LLVM-NEXT: ]
15 # LLVM-NEXT: Address: 0x0
16 # LLVM-NEXT: Offset: 0x180
17 # LLVM-NEXT: Size: 24
18 # LLVM-NEXT: Link: 0
19
20 # GNU: Section Headers:
21 # GNU-NEXT: [Nr] Name Type Address Off Size ES Flg Lk
22 # GNU-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0
23 # GNU-NEXT: [ 1] .dynsym DYNSYM 0000000000000000 000180 000018 18 A 0
24
25 --- !ELF
26 FileHeader:
27 Class: ELFCLASS64
28 Data: ELFDATA2LSB
29 Type: ET_DYN
30 Machine: EM_X86_64
31 Sections:
32 - Name: .dynsym
33 Type: SHT_DYNSYM
34
35 ## TODO: Remove precompiled input object after fixing yaml2obj.
36 ## See https://bugs.llvm.org/show_bug.cgi?id=42216.
37
38 ## Case 2: sh_link is set to 255, which is larger than the number of the sections.
39 # RUN: llvm-readobj -S %p/Inputs/elf-broken-dynsym-link.elf-x86-64 2>&1 \
40 # RUN: | FileCheck %s --check-prefixes=LLVM2,ERR2
41 # RUN: llvm-readelf -S %p/Inputs/elf-broken-dynsym-link.elf-x86-64 2>&1 \
42 # RUN: | FileCheck %s --check-prefixes=GNU2,ERR2
43
44 # ERR2: warning: invalid section index
45
46 # LLVM2: Name: .dynsym
47 # LLVM2-NEXT: Type: SHT_DYNSYM
48 # LLVM2-NEXT: Flags [
49 # LLVM2-NEXT: SHF_ALLOC
50 # LLVM2-NEXT: ]
51 # LLVM2-NEXT: Address: 0x0
52 # LLVM2-NEXT: Offset: 0x180
53 # LLVM2-NEXT: Size: 2
54 # LLVM2-NEXT: Link: 255
55
56 # GNU2: Section Headers:
57 # GNU2-NEXT: [Nr] Name Type Address Off Size ES Flg Lk
58 # GNU2-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0
59 # GNU2-NEXT: [ 1] .dynsym DYNSYM 0000000000000000 000180 000002 18 A 255
11 ## explicitly, but .dynstr is not present.
22
33 # RUN: yaml2obj %s -o %t
4 # RUN: not llvm-readelf --section-headers %t 2>&1 | FileCheck %s
4 # RUN: llvm-readelf --section-headers %t | FileCheck %s
55
6 ## TODO: Check that .dynsym has Link field set to 0.
7 ## GNU readelf is able to dump sections headers,
8 ## but llvm-readelf reports an error below too early.
9 ## See https://bugs.llvm.org/show_bug.cgi?id=42215.
6 ## Check that .dynsym has Link field set to 0.
107
11 # CHECK: error: invalid sh_type for string table, expected SHT_STRTAB
8 # CHECK: Section Headers:
9 # CHECK-NEXT: [Nr] Name Type Address Off Size ES Flg Lk
10 # CHECK-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0
11 # CHECK-NEXT: [ 1] .dynsym DYNSYM 0000000000000000 000180 000018 18 A 0
1212
1313 --- !ELF
1414 FileHeader:
14221422 // This is only used (if Elf_Shdr present)for naming section in GNU
14231423 // style
14241424 DynSymtabName = unwrapOrError(Obj->getSectionName(&Sec));
1425 DynamicStringTable = unwrapOrError(Obj->getStringTableForSymtab(Sec));
1425
1426 if (Expected E = Obj->getStringTableForSymtab(Sec))
1427 DynamicStringTable = *E;
1428 else
1429 warn(E.takeError());
14261430 }
14271431 break;
14281432 case ELF::SHT_SYMTAB_SHNDX:
375375 void reportWarning(Twine Msg) {
376376 errs() << "\n";
377377 WithColor::warning(errs()) << Msg << "\n";
378 }
379
380 void warn(Error Err) {
381 handleAllErrors(std::move(Err), [&](const ErrorInfoBase &EI) {
382 reportWarning(EI.message());
383 });
378384 }
379385
380386 void error(Error EC) {
2222 // Various helper functions.
2323 LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg);
2424 void reportWarning(Twine Msg);
25 void warn(llvm::Error Err);
2526 void error(std::error_code EC);
2627 void error(llvm::Error EC);
2728 template T error(llvm::Expected &&E) {