[yaml2obj]Allow symbol Index field to take values lower than SHN_LORESERVE

In order to test tool handling of invalid section indexes, I need to
create an object containing such an invalid section index. I could
create a hex-edited binary, but having the ability to use yaml2obj is
preferable. Prior to this change, yaml2obj would reject any explicit
section indexes less than SHN_LORESERVE. This patch changes it to allow
any value.

I had to change the test to use llvm-readelf instead of llvm-readobj,
because llvm-readobj does not like invalid section indexes. I've also
expanded the test to show that the most common SHN_* values are accepted
(SHN_UNDEF, SHN_ABS, SHN_COMMON).

Reviewed by: grimar, jakehehrlich

Differential Revision: https://reviews.llvm.org/D58445

llvm-svn: 354566
This commit is contained in:
James Henderson 2019-02-21 10:57:15 +00:00
parent 886462b5ef
commit db5d29f617
2 changed files with 31 additions and 25 deletions

View File

@ -832,9 +832,6 @@ StringRef MappingTraits<ELFYAML::Symbol>::validate(IO &IO,
if (Symbol.Index && *Symbol.Index == ELFYAML::ELF_SHN(ELF::SHN_XINDEX)) {
return "Large indexes are not supported";
}
if (Symbol.Index && *Symbol.Index < ELFYAML::ELF_SHN(ELF::SHN_LORESERVE)) {
return "Use a section name to define which section a symbol is defined in";
}
return StringRef();
}

View File

@ -1,5 +1,5 @@
# RUN: yaml2obj %s > %t
# RUN: llvm-readobj -symbols %t | FileCheck %s
# RUN: llvm-readelf -symbols %t | FileCheck %s
!ELF
FileHeader:
@ -7,29 +7,38 @@ FileHeader:
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Symbols:
Global:
- Name: test
- Name: absolute1
Index: SHN_ABS
Value: 0x1234
- Name: absolute2
Index: 0xfff1
Value: 0x4321
- Name: common1
Index: SHN_COMMON
- Name: common2
Index: 0xfff2
- Name: good
Index: 0x1
- Name: bad
Index: 0x42
- Name: undef1
Index: SHN_UNDEF
- Name: undef2
Index: 0
#CHECK: Symbols [
#CHECK-NEXT: Symbol {
#CHECK-NEXT: Name: (0)
#CHECK-NEXT: Value: 0x0
#CHECK-NEXT: Size: 0
#CHECK-NEXT: Binding: Local (0x0)
#CHECK-NEXT: Type: None (0x0)
#CHECK-NEXT: Other: 0
#CHECK-NEXT: Section: Undefined (0x0)
#CHECK-NEXT: }
#CHECK-NEXT: Symbol {
#CHECK-NEXT: Name: test (1)
#CHECK-NEXT: Value: 0x1234
#CHECK-NEXT: Size: 0
#CHECK-NEXT: Binding: Global (0x1)
#CHECK-NEXT: Type: None (0x0)
#CHECK-NEXT: Other: 0
#CHECK-NEXT: Section: Absolute (0xFFF1)
#CHECK-NEXT: }
#CHECK-NEXT:]
# CHECK: Symbol table '.symtab' contains 9 entries
# CHECK-NEXT: Num: {{.*}} Ndx Name
# CHECK-NEXT: 0: {{.*}} UND
# CHECK-NEXT: 1: {{.*}} ABS absolute1
# CHECK-NEXT: 2: {{.*}} ABS absolute2
# CHECK-NEXT: 3: {{.*}} COM common1
# CHECK-NEXT: 4: {{.*}} COM common2
# CHECK-NEXT: 5: {{.*}} 1 good
# CHECK-NEXT: 6: {{.*}} 66 bad
# CHECK-NEXT: 7: {{.*}} UND undef1
# CHECK-NEXT: 8: {{.*}} UND undef2