From 64d25c44142091760a88c3bc8235c99ddc8cbfa1 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Fri, 12 Aug 2011 19:42:39 +0000 Subject: [PATCH] Add R_X86_64_RELATIVE64 and handle R_X86_64_64 for x32. bfd/ 2011-08-12 H.J. Lu PR ld/13082 * elf64-x86-64.c (x86_64_elf_howto_table): Add R_X86_64_RELATIVE64. (elf_x86_64_relocate_section): Treat R_X86_64_64 like R_X86_64_32 and zero-extend it to 64bit if addend is zero for x32. Generate R_X86_64_RELATIVE64 for x32. include/elf/ 2011-08-12 H.J. Lu PR ld/13082 * x86-64.h (R_X86_64_RELATIVE64): New. ld/testsuite/ 2011-08-12 H.J. Lu PR ld/13082 * ld-x86-64/pr13082-1.s: New. * ld-x86-64/pr13082-1a.d: Likewise. * ld-x86-64/pr13082-1b.d: Likewise. * ld-x86-64/pr13082-2.s: Likewise. * ld-x86-64/pr13082-2a.d: Likewise. * ld-x86-64/pr13082-2b.d: Likewise. * ld-x86-64/pr13082-3.s: Likewise. * ld-x86-64/pr13082-3a.d: Likewise. * ld-x86-64/pr13082-3b.d: Likewise. * ld-x86-64/pr13082-4.s: Likewise. * ld-x86-64/pr13082-4a.d: Likewise. * ld-x86-64/pr13082-4b.d: Likewise. * ld-x86-64/pr13082-5.s: Likewise. * ld-x86-64/pr13082-5a.d: Likewise. * ld-x86-64/pr13082-5b.d: Likewise. * ld-x86-64/pr13082-6.s: Likewise. * ld-x86-64/pr13082-6a.d: Likewise. * ld-x86-64/pr13082-6b.d: Likewise. * ld-x86-64/x86-64.exp: Run pr13082-[1-6][ab]. --- bfd/ChangeLog | 8 ++++++++ bfd/elf64-x86-64.c | 21 +++++++++++++++++++++ ld/testsuite/ChangeLog | 24 ++++++++++++++++++++++++ ld/testsuite/ld-x86-64/pr13082-1.s | 10 ++++++++++ ld/testsuite/ld-x86-64/pr13082-1a.d | 9 +++++++++ ld/testsuite/ld-x86-64/pr13082-1b.d | 9 +++++++++ ld/testsuite/ld-x86-64/pr13082-2.s | 9 +++++++++ ld/testsuite/ld-x86-64/pr13082-2a.d | 9 +++++++++ ld/testsuite/ld-x86-64/pr13082-2b.d | 9 +++++++++ ld/testsuite/ld-x86-64/pr13082-3.s | 10 ++++++++++ ld/testsuite/ld-x86-64/pr13082-3a.d | 9 +++++++++ ld/testsuite/ld-x86-64/pr13082-3b.d | 9 +++++++++ ld/testsuite/ld-x86-64/pr13082-4.s | 10 ++++++++++ ld/testsuite/ld-x86-64/pr13082-4a.d | 9 +++++++++ ld/testsuite/ld-x86-64/pr13082-4b.d | 9 +++++++++ ld/testsuite/ld-x86-64/pr13082-5.s | 12 ++++++++++++ ld/testsuite/ld-x86-64/pr13082-5a.d | 14 ++++++++++++++ ld/testsuite/ld-x86-64/pr13082-5b.d | 13 +++++++++++++ ld/testsuite/ld-x86-64/pr13082-6.s | 11 +++++++++++ ld/testsuite/ld-x86-64/pr13082-6a.d | 13 +++++++++++++ ld/testsuite/ld-x86-64/pr13082-6b.d | 13 +++++++++++++ ld/testsuite/ld-x86-64/x86-64.exp | 12 ++++++++++++ 22 files changed, 252 insertions(+) create mode 100644 ld/testsuite/ld-x86-64/pr13082-1.s create mode 100644 ld/testsuite/ld-x86-64/pr13082-1a.d create mode 100644 ld/testsuite/ld-x86-64/pr13082-1b.d create mode 100644 ld/testsuite/ld-x86-64/pr13082-2.s create mode 100644 ld/testsuite/ld-x86-64/pr13082-2a.d create mode 100644 ld/testsuite/ld-x86-64/pr13082-2b.d create mode 100644 ld/testsuite/ld-x86-64/pr13082-3.s create mode 100644 ld/testsuite/ld-x86-64/pr13082-3a.d create mode 100644 ld/testsuite/ld-x86-64/pr13082-3b.d create mode 100644 ld/testsuite/ld-x86-64/pr13082-4.s create mode 100644 ld/testsuite/ld-x86-64/pr13082-4a.d create mode 100644 ld/testsuite/ld-x86-64/pr13082-4b.d create mode 100644 ld/testsuite/ld-x86-64/pr13082-5.s create mode 100644 ld/testsuite/ld-x86-64/pr13082-5a.d create mode 100644 ld/testsuite/ld-x86-64/pr13082-5b.d create mode 100644 ld/testsuite/ld-x86-64/pr13082-6.s create mode 100644 ld/testsuite/ld-x86-64/pr13082-6a.d create mode 100644 ld/testsuite/ld-x86-64/pr13082-6b.d diff --git a/bfd/ChangeLog b/bfd/ChangeLog index c811179..f76cf77 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +2011-08-12 H.J. Lu + + PR ld/13082 + * elf64-x86-64.c (x86_64_elf_howto_table): Add R_X86_64_RELATIVE64. + (elf_x86_64_relocate_section): Treat R_X86_64_64 like R_X86_64_32 + and zero-extend it to 64bit if addend is zero for x32. Generate + R_X86_64_RELATIVE64 for x32. + 2011-08-09 Matthew Gretton-Dann * bfd-in.h (bfd_elf32_arm_set_target_relocs): Update prototype. diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 7b92097..238c7bd 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -164,6 +164,9 @@ static reloc_howto_type x86_64_elf_howto_table[] = HOWTO(R_X86_64_IRELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_X86_64_IRELATIVE", FALSE, MINUS_ONE, MINUS_ONE, FALSE), + HOWTO(R_X86_64_RELATIVE64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, + bfd_elf_generic_reloc, "R_X86_64_RELATIVE64", FALSE, MINUS_ONE, + MINUS_ONE, FALSE), /* We have a gap in the reloc numbers here. R_X86_64_standard counts the number up to this point, and @@ -3083,6 +3086,16 @@ elf_x86_64_relocate_section (bfd *output_bfd, if (info->relocatable) continue; + if (rel->r_addend == 0 + && r_type == R_X86_64_64 + && !ABI_64_P (output_bfd)) + { + /* For x32, treat R_X86_64_64 like R_X86_64_32 and zero-extend + it to 64bit if addend is zero. */ + r_type = R_X86_64_32; + memset (contents + rel->r_offset + 4, 0, 4); + } + /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it here if it is defined in a non-shared object. */ if (h != NULL @@ -3597,6 +3610,14 @@ elf_x86_64_relocate_section (bfd *output_bfd, outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE); outrel.r_addend = relocation + rel->r_addend; } + else if (r_type == R_X86_64_64 + && !ABI_64_P (output_bfd)) + { + relocate = TRUE; + outrel.r_info = htab->r_info (0, + R_X86_64_RELATIVE64); + outrel.r_addend = relocation + rel->r_addend; + } else { long sindx; diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index 86604a7..013fbeb 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,27 @@ +2011-08-12 H.J. Lu + + PR ld/13082 + * ld-x86-64/pr13082-1.s: New. + * ld-x86-64/pr13082-1a.d: Likewise. + * ld-x86-64/pr13082-1b.d: Likewise. + * ld-x86-64/pr13082-2.s: Likewise. + * ld-x86-64/pr13082-2a.d: Likewise. + * ld-x86-64/pr13082-2b.d: Likewise. + * ld-x86-64/pr13082-3.s: Likewise. + * ld-x86-64/pr13082-3a.d: Likewise. + * ld-x86-64/pr13082-3b.d: Likewise. + * ld-x86-64/pr13082-4.s: Likewise. + * ld-x86-64/pr13082-4a.d: Likewise. + * ld-x86-64/pr13082-4b.d: Likewise. + * ld-x86-64/pr13082-5.s: Likewise. + * ld-x86-64/pr13082-5a.d: Likewise. + * ld-x86-64/pr13082-5b.d: Likewise. + * ld-x86-64/pr13082-6.s: Likewise. + * ld-x86-64/pr13082-6a.d: Likewise. + * ld-x86-64/pr13082-6b.d: Likewise. + + * ld-x86-64/x86-64.exp: Run pr13082-[1-6][ab]. + 2011-08-09 Matthew Gretton-Dann * ld-arm/arm-elf.exp (armelftests): Update for new command-line diff --git a/ld/testsuite/ld-x86-64/pr13082-1.s b/ld/testsuite/ld-x86-64/pr13082-1.s new file mode 100644 index 0000000..6c03e98 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-1.s @@ -0,0 +1,10 @@ + .text + .globl _start +_start: + lea .Ljmp(%rip), %rax +.L1: + jmp *(%rax) + .section .data.rel.ro.local,"aw",@progbits + .align 8 +.Ljmp: + .quad .L1 diff --git a/ld/testsuite/ld-x86-64/pr13082-1a.d b/ld/testsuite/ld-x86-64/pr13082-1a.d new file mode 100644 index 0000000..f0e98ff --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-1a.d @@ -0,0 +1,9 @@ +#source: pr13082-1.s +#name: PR ld/13082-1 (a) +#as: --x32 +#ld: -shared -melf32_x86_64 +#readelf: -r --wide + +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries: + Offset Info Type Sym. Value Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_RELATIVE64 +[0-9a-f]+ diff --git a/ld/testsuite/ld-x86-64/pr13082-1b.d b/ld/testsuite/ld-x86-64/pr13082-1b.d new file mode 100644 index 0000000..f10481f --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-1b.d @@ -0,0 +1,9 @@ +#source: pr13082-1.s +#name: PR ld/13082-1 (b) +#as: --x32 +#ld: -pie -melf32_x86_64 +#readelf: -r --wide + +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries: + Offset Info Type Sym. Value Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_RELATIVE64 +[0-9a-f]+ diff --git a/ld/testsuite/ld-x86-64/pr13082-2.s b/ld/testsuite/ld-x86-64/pr13082-2.s new file mode 100644 index 0000000..d1847a6 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-2.s @@ -0,0 +1,9 @@ + .text + .globl _start +_start: + lea .Ljmp(%rip), %rax + jmp *(%rax) + .section .data.rel.ro.local,"aw",@progbits + .align 8 +.Ljmp: + .quad _start diff --git a/ld/testsuite/ld-x86-64/pr13082-2a.d b/ld/testsuite/ld-x86-64/pr13082-2a.d new file mode 100644 index 0000000..aed33c2 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-2a.d @@ -0,0 +1,9 @@ +#source: pr13082-2.s +#name: PR ld/13082-2 (a) +#as: --x32 +#ld: -shared -melf32_x86_64 +#readelf: -r --wide + +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries: + Offset Info Type Sym. Value Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_32 +[0-9a-f]+ +_start \+ 0 diff --git a/ld/testsuite/ld-x86-64/pr13082-2b.d b/ld/testsuite/ld-x86-64/pr13082-2b.d new file mode 100644 index 0000000..b000e85 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-2b.d @@ -0,0 +1,9 @@ +#source: pr13082-2.s +#name: PR ld/13082-2 (b) +#as: --x32 +#ld: -pie -melf32_x86_64 +#readelf: -r --wide + +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries: + Offset Info Type Sym. Value Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_RELATIVE +[0-9a-f]+ diff --git a/ld/testsuite/ld-x86-64/pr13082-3.s b/ld/testsuite/ld-x86-64/pr13082-3.s new file mode 100644 index 0000000..b76eb0f --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-3.s @@ -0,0 +1,10 @@ + .text + .globl _start +_start: + lea .Ljmp(%rip), %rax + jmp *(%rax) + .section .data.rel.ro.local,"aw",@progbits + .weak func + .align 8 +.Ljmp: + .quad func diff --git a/ld/testsuite/ld-x86-64/pr13082-3a.d b/ld/testsuite/ld-x86-64/pr13082-3a.d new file mode 100644 index 0000000..bf176f9 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-3a.d @@ -0,0 +1,9 @@ +#source: pr13082-3.s +#name: PR ld/13082-3 (a) +#as: --x32 +#ld: -shared -melf32_x86_64 +#readelf: -r --wide + +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries: + Offset Info Type Sym. Value Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_32 +[0-9a-f]+ +func \+ 0 diff --git a/ld/testsuite/ld-x86-64/pr13082-3b.d b/ld/testsuite/ld-x86-64/pr13082-3b.d new file mode 100644 index 0000000..12efaf0 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-3b.d @@ -0,0 +1,9 @@ +#source: pr13082-3.s +#name: PR ld/13082-3 (b) +#as: --x32 +#ld: -pie -melf32_x86_64 +#readelf: -r --wide + +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries: + Offset Info Type Sym. Value Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_32 +[0-9a-f]+ +func \+ 0 diff --git a/ld/testsuite/ld-x86-64/pr13082-4.s b/ld/testsuite/ld-x86-64/pr13082-4.s new file mode 100644 index 0000000..ed8506d --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-4.s @@ -0,0 +1,10 @@ + .text + .globl _start +_start: + lea .Ljmp(%rip), %rax + jmp *(%rax) + .section .data.rel.ro.local,"aw",@progbits + .weak func + .align 8 +.Ljmp: + .quad func + 1 diff --git a/ld/testsuite/ld-x86-64/pr13082-4a.d b/ld/testsuite/ld-x86-64/pr13082-4a.d new file mode 100644 index 0000000..bb2c573 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-4a.d @@ -0,0 +1,9 @@ +#source: pr13082-4.s +#name: PR ld/13082-4 (a) +#as: --x32 +#ld: -shared -melf32_x86_64 +#readelf: -r --wide + +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries: + Offset Info Type Sym. Value Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_64 +[0-9a-f]+ +func \+ 1 diff --git a/ld/testsuite/ld-x86-64/pr13082-4b.d b/ld/testsuite/ld-x86-64/pr13082-4b.d new file mode 100644 index 0000000..cb4d90a --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-4b.d @@ -0,0 +1,9 @@ +#source: pr13082-4.s +#name: PR ld/13082-4 (b) +#as: --x32 +#ld: -pie -melf32_x86_64 +#readelf: -r --wide + +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries: + Offset Info Type Sym. Value Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_64 +[0-9a-f]+ +func \+ 1 diff --git a/ld/testsuite/ld-x86-64/pr13082-5.s b/ld/testsuite/ld-x86-64/pr13082-5.s new file mode 100644 index 0000000..9757fcb --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-5.s @@ -0,0 +1,12 @@ + .text + .globl _start + .globl ifunc + .type ifunc, @gnu_indirect_function +_start: + lea .Ljmp(%rip), %rax +ifunc: + jmp *(%rax) + .section .data.rel.ro.local,"aw",@progbits + .align 8 +.Ljmp: + .quad ifunc diff --git a/ld/testsuite/ld-x86-64/pr13082-5a.d b/ld/testsuite/ld-x86-64/pr13082-5a.d new file mode 100644 index 0000000..e5b0c11 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-5a.d @@ -0,0 +1,14 @@ +#source: pr13082-5.s +#name: PR ld/13082-5 (a) +#as: --x32 +#ld: -shared -melf32_x86_64 +#readelf: -r --wide + +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 2 entries: + Offset Info Type Sym. Value Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_32 +ifunc\(\)+ +ifunc \+ 0 +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_GLOB_DAT +ifunc\(\)+ +ifunc \+ 0 + +Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries: + Offset Info Type Sym. Value Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_JUMP_SLOT +ifunc\(\)+ +ifunc \+ 0 diff --git a/ld/testsuite/ld-x86-64/pr13082-5b.d b/ld/testsuite/ld-x86-64/pr13082-5b.d new file mode 100644 index 0000000..1c5a5e7 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-5b.d @@ -0,0 +1,13 @@ +#source: pr13082-5.s +#name: PR ld/13082-5 (b) +#as: --x32 +#ld: -pie -melf32_x86_64 +#readelf: -r --wide + +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries: + Offset Info Type Sym. Value Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_IRELATIVE +[0-9a-f]+ + +Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries: + Offset Info Type Sym. Value Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_IRELATIVE +[0-9a-f]+ diff --git a/ld/testsuite/ld-x86-64/pr13082-6.s b/ld/testsuite/ld-x86-64/pr13082-6.s new file mode 100644 index 0000000..eb88fb6 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-6.s @@ -0,0 +1,11 @@ + .text + .globl _start + .type ifunc, @gnu_indirect_function +_start: + lea .Ljmp(%rip), %rax +ifunc: + jmp *(%rax) + .section .data.rel.ro.local,"aw",@progbits + .align 8 +.Ljmp: + .quad ifunc diff --git a/ld/testsuite/ld-x86-64/pr13082-6a.d b/ld/testsuite/ld-x86-64/pr13082-6a.d new file mode 100644 index 0000000..9a1a655 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-6a.d @@ -0,0 +1,13 @@ +#source: pr13082-6.s +#name: PR ld/13082-6 (a) +#as: --x32 +#ld: -shared -melf32_x86_64 +#readelf: -r --wide + +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries: + Offset Info Type Sym. Value Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_IRELATIVE +[0-9a-f]+ + +Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries: + Offset Info Type Sym. Value Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_IRELATIVE +[0-9a-f]+ diff --git a/ld/testsuite/ld-x86-64/pr13082-6b.d b/ld/testsuite/ld-x86-64/pr13082-6b.d new file mode 100644 index 0000000..792c348 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr13082-6b.d @@ -0,0 +1,13 @@ +#source: pr13082-6.s +#name: PR ld/13082-6 (b) +#as: --x32 +#ld: -pie -melf32_x86_64 +#readelf: -r --wide + +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries: + Offset Info Type Sym. Value Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_IRELATIVE +[0-9a-f]+ + +Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries: + Offset Info Type Sym. Value Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ +R_X86_64_IRELATIVE +[0-9a-f]+ diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index 2b8721c..77b081b 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -213,6 +213,18 @@ run_dump_test "ia32-3" run_dump_test "lp64-1" run_dump_test "lp64-2" run_dump_test "lp64-3" +run_dump_test "pr13082-1a" +run_dump_test "pr13082-1b" +run_dump_test "pr13082-2a" +run_dump_test "pr13082-2b" +run_dump_test "pr13082-3a" +run_dump_test "pr13082-3b" +run_dump_test "pr13082-4a" +run_dump_test "pr13082-4b" +run_dump_test "pr13082-5a" +run_dump_test "pr13082-5b" +run_dump_test "pr13082-6a" +run_dump_test "pr13082-6b" # Must be native with the C compiler if { [isnative] && [which $CC] != 0 } { -- 2.7.4