Files
clang-p2996/lld/test/elf/phdr.test
Chandler Carruth c9cdc502f3 Fix a comparison function to actually be a SWO so that it conforms to
the spec required by std::sort and friends.

Ordering things this way also dramatically simplifies the code as
short-circuit ensures we can skip all of the negative tests.

I've left one FIXME where we're establishing a fairly arbitrary
ordering. Previously, the function compared all types as equal except
for the ones it explicitly handled, but it didn't delegate correctly to
the atomflags when doing so, and so it would fail to be a SWO. The two
possible fixes are to stop comparing the atom flags entirely, or to
establish some arbitrary ordering of the types.

Since it was pure luck which ordering of unequal types we ended up with
previously (the caller was std::sort, not std::stable_sort) I chose to
make the ordering explicit and guaranteed. This seems like the best
conservative approach as I suspect we would want to switch to
stable_sort otherwise in order to have deterministic output.

Differential Revision: http://reviews.llvm.org/D8266

llvm-svn: 231968
2015-03-11 21:34:33 +00:00

100 lines
2.9 KiB
Plaintext

# This test checks emission for program header for ELF binaries
RUN: lld -flavor gnu -target i386-linux -o %t1 -e main %p/Inputs/phdr.i386 \
RUN: && llvm-readobj -program-headers %t1 | FileCheck -check-prefix=I386 %s
RUN: lld -flavor gnu -target x86_64-linux -o %t1 -e _start %p/Inputs/relocs.x86-64 -static \
RUN: && llvm-objdump -p %t1 | FileCheck %s -check-prefix=X86_64
I386: ProgramHeaders [
I386-NEXT: ProgramHeader {
I386-NEXT: Type: PT_PHDR (0x6)
I386-NEXT: Offset: 0x34
I386-NEXT: VirtualAddress: 0x34
I386-NEXT: PhysicalAddress: 0x34
I386-NEXT: FileSize: 224
I386-NEXT: MemSize: 224
I386-NEXT: Flags [ (0x5)
I386-NEXT: PF_R (0x4)
I386-NEXT: PF_X (0x1)
I386-NEXT: ]
I386-NEXT: Alignment: 8
I386-NEXT: }
I386-NEXT: ProgramHeader {
I386-NEXT: Type: PT_INTERP (0x3)
I386-NEXT: Offset: 0x114
I386-NEXT: VirtualAddress: 0x114
I386-NEXT: PhysicalAddress: 0x114
I386-NEXT: FileSize: 28
I386-NEXT: MemSize: 28
I386-NEXT: Flags [ (0x4)
I386-NEXT: PF_R (0x4)
I386-NEXT: ]
I386-NEXT: Alignment: 1
I386-NEXT: }
I386-NEXT: ProgramHeader {
I386-NEXT: Type: PT_LOAD (0x1)
I386-NEXT: Offset: 0x0
I386-NEXT: VirtualAddress: 0x0
I386-NEXT: PhysicalAddress: 0x0
I386-NEXT: FileSize: 556
I386-NEXT: MemSize: 556
I386-NEXT: Flags [ (0x5)
I386-NEXT: PF_R (0x4)
I386-NEXT: PF_X (0x1)
I386-NEXT: ]
I386-NEXT: Alignment: 4096
I386-NEXT: }
I386-NEXT: ProgramHeader {
I386-NEXT: Type: PT_LOAD (0x1)
I386-NEXT: Offset: 0x1000
I386-NEXT: VirtualAddress: 0x1000
I386-NEXT: PhysicalAddress: 0x1000
I386-NEXT: FileSize: 260
I386-NEXT: MemSize: 260
I386-NEXT: Flags [ (0x6)
I386-NEXT: PF_R (0x4)
I386-NEXT: PF_W (0x2)
I386-NEXT: ]
I386-NEXT: Alignment: 4096
I386-NEXT: }
I386-NEXT: ProgramHeader {
I386-NEXT: Type: PT_LOAD (0x1)
I386-NEXT: Offset: 0x4000
I386-NEXT: VirtualAddress: 0x4000
I386-NEXT: PhysicalAddress: 0x4000
I386-NEXT: FileSize: 4
I386-NEXT: MemSize: 8
I386-NEXT: Flags [ (0x6)
I386-NEXT: PF_R (0x4)
I386-NEXT: PF_W (0x2)
I386-NEXT: ]
I386-NEXT: Alignment: 16384
I386-NEXT: }
I386-NEXT: ProgramHeader {
I386-NEXT: Type: PT_DYNAMIC (0x2)
I386-NEXT: Offset: 0x1FC
I386-NEXT: VirtualAddress: 0x1FC
I386-NEXT: PhysicalAddress: 0x1FC
I386-NEXT: FileSize: 48
I386-NEXT: MemSize: 48
I386-NEXT: Flags [ (0x4)
I386-NEXT: PF_R (0x4)
I386-NEXT: ]
I386-NEXT: Alignment: 4
I386-NEXT: }
I386-NEXT: ProgramHeader {
I386-NEXT: Type: PT_GNU_EH_FRAME (0x6474E550)
I386-NEXT: Offset: 0x1F4
I386-NEXT: VirtualAddress: 0x1F4
I386-NEXT: PhysicalAddress: 0x1F4
I386-NEXT: FileSize: 8
I386-NEXT: MemSize: 8
I386-NEXT: Flags [ (0x4)
I386-NEXT: PF_R (0x4)
I386-NEXT: ]
I386-NEXT: Alignment: 4
I386-NEXT: }
X86_64: LOAD off 0x0000000000000000
X86_64: LOAD off 0x0000000000001000