binutils-gdb/ld/testsuite/ld-elf/linux-x86.S

92 lines
1.4 KiB
ArmAsm
Raw Normal View History

x86: Add a GNU_PROPERTY_X86_ISA_1_USED note if needed When -z separate-code, which is enabled by default for Linux/x86, is used to create executable, ld won't place any data in the code-only PT_LOAD segment. If there are no data sections placed before the code-only PT_LOAD segment, the program headers won't be mapped into any PT_LOAD segment. When the executable tries to access it (based on the program header address passed in AT_PHDR), it will lead to segfault. This patch inserts a GNU_PROPERTY_X86_ISA_1_USED note if there may be no data sections before the text section so that the first PT_LOAD segment won't be code-only and will contain the program header. Testcases are adjusted to either pass "-z noseparate-code" to ld or discard the .note.gnu.property section. A Linux/x86 run-time test is added. bfd/ PR ld/23428 * elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): If the separate code program header is needed, make sure that the first read-only PT_LOAD segment has no code by adding a GNU_PROPERTY_X86_ISA_1_USED note. ld/ PR ld/23428 * testsuite/ld-elf/linux-x86.S: New file. * testsuite/ld-elf/linux-x86.exp: Likewise. * testsuite/ld-elf/pr23428.c: Likewise. * testsuite/ld-elf/sec64k.exp: Pass "-z noseparate-code" to ld for Linux/x86 targets. * testsuite/ld-i386/abs-iamcu.d: Likewise. * testsuite/ld-i386/abs.d: Likewise. * testsuite/ld-i386/pr12718.d: Likewise. * testsuite/ld-i386/pr12921.d: Likewise. * testsuite/ld-x86-64/abs-k1om.d: Likewise. * testsuite/ld-x86-64/abs-l1om.d: Likewise. * testsuite/ld-x86-64/abs.d: Likewise. * testsuite/ld-x86-64/pr12718.d: Likewise. * testsuite/ld-x86-64/pr12921.d: Likewise. * testsuite/ld-linkonce/zeroeh.ld: Discard .note.gnu.property section. * testsuite/ld-scripts/print-memory-usage.t: Likewise. * testsuite/ld-scripts/size-2.t: Likewise. * testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Use ld to create executable if language is "asm".
2018-07-21 00:18:47 +08:00
.text
.globl _start
.type _start,@function
.p2align 4
_start:
xorl %ebp, %ebp
#ifdef __LP64__
popq %rdi
movq %rsp, %rsi
andq $~15, %rsp
#elif defined __x86_64__
mov (%rsp),%edi
addl $4,%esp
movl %esp, %esi
andl $~15, %esp
#else
popl %esi
movl %esp, %ecx
andl $~15, %esp
subl $8,%esp
pushl %ecx
pushl %esi
#endif
call main
hlt
.type syscall, @function
.globl syscall
.p2align 4
syscall:
#ifdef __x86_64__
movq %rdi, %rax /* Syscall number -> rax. */
movq %rsi, %rdi /* shift arg1 - arg5. */
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %r10
movq %r9, %r8
movq 8(%rsp),%r9 /* arg6 is on the stack. */
syscall /* Do the system call. */
#else
push %ebp
push %edi
push %esi
push %ebx
mov 0x2c(%esp),%ebp
mov 0x28(%esp),%edi
mov 0x24(%esp),%esi
mov 0x20(%esp),%edx
mov 0x1c(%esp),%ecx
mov 0x18(%esp),%ebx
mov 0x14(%esp),%eax
int $0x80
pop %ebx
pop %esi
pop %edi
pop %ebp
#endif
ret /* Return to caller. */
.size syscall, .-syscall
.section .note.GNU-stack,"",@progbits
.section ".note.gnu.property", "a"
#ifdef __LP64__
.p2align 3
#else
.p2align 2
#endif
.long 1f - 0f /* name length */
.long 5f - 2f /* data length */
.long 5 /* note type */
0: .asciz "GNU" /* vendor name */
1:
#ifdef __LP64__
.p2align 3
#else
.p2align 2
#endif
2: .long 0xc0000002 /* pr_type. */
.long 4f - 3f /* pr_datasz. */
3:
.long 0x2
4:
#ifdef __LP64__
.p2align 3
#else
.p2align 2
#endif
5: