Files
clang-p2996/lld/test/elf/init_array-order.test
Simon Atanasyan 2aae2b4609 [ELF] Fix incorrect sorting of .init_array / .fini_array sections.
The main problem is in the predicate passed to the `std::stable_sort()`.
This predicate always returns false if **both** section's names do not
start with `.init_array` or `.fini_array` prefixes. In short, it does not
define a strict weak orderng. Suppose we have the following sections:

  .A .init_array.1 .init_array.2

The predicate states that:

  not .init_array.1 < .A
  not .A < .init_array.2
  but .init_array.1 < .init_array.2 !!!

The second problem is that `.init_array` section without number should
go last in the list. Not it has the lowest priority '0' and goes first.

The patch fixes both of the problems.

llvm-svn: 209875
2014-05-30 05:29:46 +00:00

74 lines
1.6 KiB
Plaintext

#RUN: yaml2obj -format=elf %s > %t
#RUN: lld -flavor gnu -target x86_64-linux %t --noinhibit-exec \
#RUN: --output-filetype=yaml | FileCheck %s
!ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Content: "1100000000000000"
AddressAlign: 8
Flags: [SHF_ALLOC, SHF_EXECINSTR]
- Name: .init_array.2
Type: SHT_INIT_ARRAY
Content: "0200000000000000"
AddressAlign: 8
Flags: [SHF_ALLOC]
- Name: .init_array.3
Type: SHT_INIT_ARRAY
Content: "0300000000000000"
AddressAlign: 8
Flags: [SHF_ALLOC]
- Name: .init_array
Type: SHT_INIT_ARRAY
Content: "9900000000000000"
AddressAlign: 8
Flags: [SHF_ALLOC]
- Name: .data
Type: SHT_PROGBITS
Content: "2200000000000000"
AddressAlign: 8
Flags: [SHF_ALLOC, SHF_WRITE]
- Name: .init_array.1
Type: SHT_INIT_ARRAY
Content: "0100000000000000"
AddressAlign: 8
Flags: [SHF_ALLOC]
Symbols:
Local:
- Name: .text
Type: STT_SECTION
Section: .text
- Name: .data
Type: STT_SECTION
Section: .data
- Name: .init_array.3
Type: STT_SECTION
Section: .init_array.3
- Name: .init_array.2
Type: STT_SECTION
Section: .init_array.2
- Name: .init_array.1
Type: STT_SECTION
Section: .init_array.1
- Name: .init_array
Type: STT_SECTION
Section: .init_array
#CHECK: defined-atoms:
#CHECK: content: [ 01,
#CHECK: section-name: .init_array.1
#CHECK: content: [ 02,
#CHECK: section-name: .init_array.2
#CHECK: content: [ 03,
#CHECK: section-name: .init_array.3
#CHECK: content: [ 99,
#CHECK: section-name: .init_array