From 67bdfb0a5973aa15c977747b1cae10b8d883fe44 Mon Sep 17 00:00:00 2001 From: James Henderson Date: Thu, 21 Feb 2019 10:57:15 +0000 Subject: [PATCH] [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 --- llvm/lib/ObjectYAML/ELFYAML.cpp | 3 -- llvm/test/tools/yaml2obj/symbol-index.yaml | 53 +++++++++++++--------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp index d709f997966c..3eac787a7280 100644 --- a/llvm/lib/ObjectYAML/ELFYAML.cpp +++ b/llvm/lib/ObjectYAML/ELFYAML.cpp @@ -832,9 +832,6 @@ StringRef MappingTraits::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(); } diff --git a/llvm/test/tools/yaml2obj/symbol-index.yaml b/llvm/test/tools/yaml2obj/symbol-index.yaml index e6b537b148e5..e5c50735f4ca 100644 --- a/llvm/test/tools/yaml2obj/symbol-index.yaml +++ b/llvm/test/tools/yaml2obj/symbol-index.yaml @@ -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