[llvm] 49c91a6 - [llvm-objcopy][test] Improve many-sections object and test case

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 4 01:44:50 PST 2021


Author: James Henderson
Date: 2021-03-04T09:42:43Z
New Revision: 49c91a64fd375574970ed5d8c926f71425d18d76

URL: https://github.com/llvm/llvm-project/commit/49c91a64fd375574970ed5d8c926f71425d18d76
DIFF: https://github.com/llvm/llvm-project/commit/49c91a64fd375574970ed5d8c926f71425d18d76.diff

LOG: [llvm-objcopy][test] Improve many-sections object and test case

Additionally do some test tidy-ups and improve coverage of symbol
section indexes where the logical section index >= SHN_LORESERVE.

The symbol and section names in the many-section input object were
mostly shared. This patch changes them to be distinct, enabling
different operations such as --add-symbol, to be more targeted, when
using the object. It also makes the test less confusing and removes some
oddness in the symbol table order, presumably caused by the duplicate
names.

The input object was built from assembly that was of the form:
.section s1
sym1:
.section s2
sym2:
...
with a total of 65536 such occurrences. llvm-objcopy was then used to
remove the empty .text section automatically generated by MC, and
incidentally to move .strtab to the end of the object. This ensured that
the section/symbol indexes matched their name (i.e. section index 1 was
s1, section index 2 was s2 etc, and sym1 was in s1, sym2 in s2 etc).

Reviewed by: MaskRay

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

Added: 
    

Modified: 
    llvm/test/tools/llvm-objcopy/ELF/Inputs/many-sections.o.gz
    llvm/test/tools/llvm-objcopy/ELF/auto-remove-shndx.test
    llvm/test/tools/llvm-objcopy/ELF/many-sections.test
    llvm/test/tools/llvm-objcopy/ELF/strict-no-add.test

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-objcopy/ELF/Inputs/many-sections.o.gz b/llvm/test/tools/llvm-objcopy/ELF/Inputs/many-sections.o.gz
index e71add0ff134..29ecd1462589 100644
Binary files a/llvm/test/tools/llvm-objcopy/ELF/Inputs/many-sections.o.gz and b/llvm/test/tools/llvm-objcopy/ELF/Inputs/many-sections.o.gz 
diff er

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/auto-remove-shndx.test b/llvm/test/tools/llvm-objcopy/ELF/auto-remove-shndx.test
index 8e6c788bf481..970b218479d2 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/auto-remove-shndx.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/auto-remove-shndx.test
@@ -1,5 +1,5 @@
 # RUN: %python %p/../Inputs/ungzip.py %p/Inputs/many-sections.o.gz > %t
-# RUN: llvm-objcopy -R .text -R s0 -R s1 -R s2 -R s3 -R s4 -R s5 -R s6 %t %t2
+# RUN: llvm-objcopy -R 's65[3-9][0-9][0-9]' -R 's6529[0-9]' -R 's6528[1-9]' %t %t2
 # RUN: llvm-readobj --sections %t2 | FileCheck --check-prefix=SECS %s
 
 # SECS-NOT: Name: .symtab_shndx

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/many-sections.test b/llvm/test/tools/llvm-objcopy/ELF/many-sections.test
index 41e237a37771..6622db237026 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/many-sections.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/many-sections.test
@@ -1,103 +1,102 @@
+## Show that llvm-objcopy can handle an input file with many sections.
+
 RUN: %python %p/../Inputs/ungzip.py %p/Inputs/many-sections.o.gz > %t
 RUN: llvm-objcopy %t %t2
-RUN: llvm-readobj --file-headers %t2 | FileCheck --check-prefix=EHDR %s
-RUN: llvm-readobj --sections %t2 | FileCheck --check-prefix=SECS %s
-RUN: llvm-readobj --symbols %t2 | grep "Symbol {" | wc -l | FileCheck --check-prefix=SYMS %s
-RUN: llvm-readobj --symbols %t2 | FileCheck %s --check-prefix=SYM_SEC_IDS
+RUN: llvm-readobj --file-headers --sections --symbols %t2 | FileCheck %s
+RUN: llvm-readelf --symbols %t2 | FileCheck --check-prefix=SYMS %s
+
+## The ELF header should have e_shnum == 0 and e_shstrndx == SHN_XINDEX.
+# CHECK:        SectionHeaderCount: 0
+# CHECK-NEXT:   StringTableSectionIndex: 65535
 
-EHDR:      Format: elf64-x86-64
-EHDR-NEXT: Arch: x86_64
-EHDR-NEXT: AddressSize: 64bit
-EHDR-NEXT: LoadName:
-EHDR-NEXT: ElfHeader {
-EHDR-NEXT:   Ident {
-EHDR-NEXT:     Magic: (7F 45 4C 46)
-EHDR-NEXT:     Class: 64-bit (0x2)
-EHDR-NEXT:     DataEncoding: LittleEndian (0x1)
-EHDR-NEXT:     FileVersion: 1
-EHDR-NEXT:     OS/ABI: SystemV (0x0)
-EHDR-NEXT:     ABIVersion: 0
-EHDR-NEXT:     Unused: (00 00 00 00 00 00 00)
-EHDR-NEXT:   }
-EHDR-NEXT:   Type: Relocatable (0x1)
-EHDR-NEXT:   Machine: EM_X86_64 (0x3E)
-EHDR-NEXT:   Version: 1
-EHDR-NEXT:   Entry: 0x0
-EHDR-NEXT:   ProgramHeaderOffset: 0x0
-EHDR-NEXT:   SectionHeaderOffset:
-EHDR-NEXT:   Flags [ (0x0)
-EHDR-NEXT:   ]
-EHDR-NEXT:   HeaderSize: 64
-EHDR-NEXT:   ProgramHeaderEntrySize: 0
-EHDR-NEXT:   ProgramHeaderCount: 0
-EHDR-NEXT:   SectionHeaderEntrySize: 64
-EHDR-NEXT:   SectionHeaderCount: 0
-EHDR-NEXT:   StringTableSectionIndex: 65535
-EHDR-NEXT: }
+## The first section header should store the real section header count and
+## shstrndx in its fields.
+# CHECK:      Section {
+# CHECK-NEXT:   Index: 0
+# CHECK-NEXT:   Name:
+# CHECK-NEXT:   Type: SHT_NULL
+# CHECK-NEXT:   Flags [
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Address:
+# CHECK-NEXT:   Offset:
+# CHECK-NEXT:   Size: [[#SHNUM:]]
+# CHECK-NEXT:   Link: [[#SHNUM-1]]
 
-SECS: Index: 65285
-SECS-NEXT: Name: .symtab
-SECS-NEXT: Type: SHT_SYMTAB
-SECS: Name: .symtab_shndx
-SECS-NEXT: Type: SHT_SYMTAB_SHNDX
-SECS-NEXT: Flags [ (0x0)
-SECS-NEXT: ]
-SECS-NEXT: Address: 0x0
-SECS-NEXT: Offset:
-# There should be #syms * EntrySize bytes.
-SECS-NEXT: Size: 261136
-SECS-NEXT: Link: 65285
-SECS-NEXT: Info:
-SECS-NEXT: AddressAlignment: 4
-SECS-NEXT: EntrySize: 4
-SECS: Index: 65287
-SYMS: 65284
+## Show that the .symtab_shndx section has the correct properties.
+## To avoid accidentally capturing the index of an unrelated section header for
+## checking the sh_link of the .symtab_shndx section, use the index of the
+## section immediately following the symbol table.
+# CHECK:        Name: .symtab
+# CHECK-NEXT:   Type: SHT_SYMTAB
+# CHECK:        Index: [[#AFTERSYMTAB:]]
+# CHECK:        Name: .symtab_shndx
+# CHECK-NEXT:   Type: SHT_SYMTAB_SHNDX
+# CHECK-NEXT:   Flags [ (0x0)
+# CHECK-NEXT:   ]
+# CHECK-NEXT:   Address: 0x0
+# CHECK-NEXT:   Offset:
+## There should be #syms * EntrySize bytes.
+# CHECK-NEXT:   Size: 262148
+# CHECK-NEXT:   Link: [[#AFTERSYMTAB-1]]
+# CHECK-NEXT:   Info: 0
+# CHECK-NEXT:   AddressAlignment: 4
+# CHECK-NEXT:   EntrySize: 4
+## Show that the sh_link of the first section header is the section header table
+## index. Also show that the last section is the .strtab.
+# CHECK:        Index: [[#SHNUM-1]]
+# CHECK-NEXT:   Name: .strtab
 
-SYM_SEC_IDS:         Section: s9 (0xFEFF)
-SYM_SEC_IDS-NEXT:  }
-SYM_SEC_IDS-NEXT:  Symbol {
-SYM_SEC_IDS-NEXT:    Name: s9 (37)
-SYM_SEC_IDS-NEXT:    Value: 0x0
-SYM_SEC_IDS-NEXT:    Size: 0
-SYM_SEC_IDS-NEXT:    Binding: Local (0x0)
-SYM_SEC_IDS-NEXT:    Type: None (0x0)
-SYM_SEC_IDS-NEXT:    Other: 0
-SYM_SEC_IDS-NEXT:    Section: s9 (0xFF01)
-SYM_SEC_IDS-NEXT:  }
-SYM_SEC_IDS-NEXT:  Symbol {
-SYM_SEC_IDS-NEXT:    Name: s9 (37)
-SYM_SEC_IDS-NEXT:    Value: 0x0
-SYM_SEC_IDS-NEXT:    Size: 0
-SYM_SEC_IDS-NEXT:    Binding: Local (0x0)
-SYM_SEC_IDS-NEXT:    Type: None (0x0)
-SYM_SEC_IDS-NEXT:    Other: 0
-SYM_SEC_IDS-NEXT:    Section: s9 (0xFF00)
-SYM_SEC_IDS-NEXT:  }
-SYM_SEC_IDS-NEXT:  Symbol {
-SYM_SEC_IDS-NEXT:    Name: s9 (37)
-SYM_SEC_IDS-NEXT:    Value: 0x0
-SYM_SEC_IDS-NEXT:    Size: 0
-SYM_SEC_IDS-NEXT:    Binding: Local (0x0)
-SYM_SEC_IDS-NEXT:    Type: None (0x0)
-SYM_SEC_IDS-NEXT:    Other: 0
-SYM_SEC_IDS-NEXT:    Section: s9 (0x1982)
-SYM_SEC_IDS-NEXT:  }
-SYM_SEC_IDS-NEXT:  Symbol {
-SYM_SEC_IDS-NEXT:    Name: s9 (37)
-SYM_SEC_IDS-NEXT:    Value: 0x0
-SYM_SEC_IDS-NEXT:    Size: 0
-SYM_SEC_IDS-NEXT:    Binding: Local (0x0)
-SYM_SEC_IDS-NEXT:    Type: None (0x0)
-SYM_SEC_IDS-NEXT:    Other: 0
-SYM_SEC_IDS-NEXT:    Section: s9 (0xFF03)
-SYM_SEC_IDS-NEXT:  }
-SYM_SEC_IDS-NEXT:  Symbol {
-SYM_SEC_IDS-NEXT:    Name: s9 (37)
-SYM_SEC_IDS-NEXT:    Value: 0x0
-SYM_SEC_IDS-NEXT:    Size: 0
-SYM_SEC_IDS-NEXT:    Binding: Local (0x0)
-SYM_SEC_IDS-NEXT:    Type: None (0x0)
-SYM_SEC_IDS-NEXT:    Other: 0
-SYM_SEC_IDS-NEXT:    Section: s9 (0xFF04)
-SYM_SEC_IDS-NEXT:  }
+## Show that the symbols with section indexes around the reserved range still
+## have the right section indexes afterwards.
+# CHECK:         Section: s65279 (0xFEFF)
+# CHECK-NEXT:  }
+## st_shndx == SHN_LORSERVE.
+# CHECK-NEXT:  Symbol {
+# CHECK-NEXT:    Name: sym65280 (
+# 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: s65280 (0xFF00)
+# CHECK-NEXT:  }
+## st_shndx == SHN_ABS.
+# CHECK:         Name: sym65521 (
+# 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: s65521 (0xFFF1)
+# CHECK-NEXT:  }
+## st_shndx == SHN_COMMON.
+# CHECK-NEXT:  Symbol {
+# CHECK-NEXT:    Name: sym65522 (
+# 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: s65522 (0xFFF2)
+# CHECK-NEXT:  }
+## st_shndx == SHN_XINDEX.
+# CHECK:         Name: sym65535 (
+# 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: s65535 (0xFFFF)
+# CHECK-NEXT:  }
+## st_shndx > SHN_XINDEX.
+# CHECK-NEXT:  Symbol {
+# CHECK-NEXT:    Name: sym65536 (
+# 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: s65536 (0x10000)
+# CHECK-NEXT:  }
 
+# SYMS: Symbol table '.symtab' contains 65537 entries

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/strict-no-add.test b/llvm/test/tools/llvm-objcopy/ELF/strict-no-add.test
index c1d944017d4d..1eafc41eaaf6 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/strict-no-add.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/strict-no-add.test
@@ -3,7 +3,7 @@
 
 RUN: %python %p/../Inputs/ungzip.py %p/Inputs/many-sections.o.gz > %t.0
 RUN: echo 'foo' > %t
-RUN: llvm-objcopy -R .text -R s0 -R s1 -R s2 -R s3 -R s4 -R s5 -R s6 %t.0 %t2
+RUN: llvm-objcopy -R 's65[3-9][0-9][0-9]' -R 's6529[0-9]' -R 's652[89][0-9]' %t.0 %t2
 RUN: llvm-objcopy --add-section=.s0=%t --add-section=.s1=%t --add-section=.s2=%t %t2 %t2
 RUN: llvm-readobj --sections %t2 | FileCheck --check-prefix=SECS %s
 


        


More information about the llvm-commits mailing list