• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revisãof0bdd7589a225589c1fda7ce8762663ee9176746 (tree)
Hora2018-04-18 21:20:27
AutorChristophe Lyon <christophe.lyon@st.c...>
CommiterChristophe Lyon

Mensagem de Log

[ARM] FDPIC: Implement Thumb-only PLT for FDPIC.

2018-XX-XX Christophe Lyon <christophe.lyon@st.com>
Mickaël Guêné <mickael.guene@st.com>

bfd/
* elf32-arm.c (elf32_arm_fdpic_thumb_plt_entry): New.
(elf32_arm_plt_needs_thumb_stub_p): Handle thumb-only case.
(elf32_arm_populate_plt_entry): Likewise.
(elf32_arm_output_plt_map_1): Likewise.
(elf32_arm_output_arch_local_syms): Likewise.

ld/testsuite/
* arm-elf.exp: Execute the new FDPIC Thumb-only tests.
* fdpic-main-m.d: New test.
* fdpic-main-m.s: New.
* fdpic-main-m.sym: New.
* fdpic-shared-m.d: New test.
* fdpic-shared-m.s: New.
* fdpic-shared-m.sym: New.

Mudança Sumário

Diff

--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -2290,6 +2290,22 @@ static const bfd_vma elf32_arm_fdpic_plt_entry [] =
22902290 0xe599f000, /* ldr pc, [r9] */
22912291 };
22922292
2293+/* Thumb FDPIC PLT entry. */
2294+/* The last 5 words contain PLT lazy fragment code and data. */
2295+static const bfd_vma elf32_arm_fdpic_thumb_plt_entry [] =
2296+ {
2297+ 0xc00cf8df, /* ldr.w r12, .L1 */
2298+ 0x0c09eb0c, /* add.w r12, r12, r9 */
2299+ 0x9004f8dc, /* ldr.w r9, [r12, #4] */
2300+ 0xf000f8dc, /* ldr.w pc, [r12] */
2301+ 0x00000000, /* .L1 .word foo(GOTOFFFUNCDESC) */
2302+ 0x00000000, /* .L2 .word foo(funcdesc_value_reloc_offset) */
2303+ 0xc008f85f, /* ldr.w r12, .L2 */
2304+ 0xcd04f84d, /* push {r12} */
2305+ 0xc004f8d9, /* ldr.w r12, [r9, #4] */
2306+ 0xf000f8d9, /* ldr.w pc, [r9] */
2307+ };
2308+
22932309 #ifdef FOUR_WORD_PLT
22942310
22952311 /* The first entry in a procedure linkage table looks like
@@ -3620,6 +3636,8 @@ elf32_arm_get_plt_info (bfd *abfd, struct elf32_arm_link_hash_table *globals,
36203636 return TRUE;
36213637 }
36223638
3639+static bfd_boolean using_thumb_only (struct elf32_arm_link_hash_table *globals);
3640+
36233641 /* Return true if the PLT described by ARM_PLT requires a Thumb stub
36243642 before it. */
36253643
@@ -3630,8 +3648,9 @@ elf32_arm_plt_needs_thumb_stub_p (struct bfd_link_info *info,
36303648 struct elf32_arm_link_hash_table *htab;
36313649
36323650 htab = elf32_arm_hash_table (info);
3633- return (arm_plt->thumb_refcount != 0
3634- || (!htab->use_blx && arm_plt->maybe_thumb_refcount != 0));
3651+
3652+ return (!using_thumb_only(htab) && (arm_plt->thumb_refcount != 0
3653+ || (!htab->use_blx && arm_plt->maybe_thumb_refcount != 0)));
36353654 }
36363655
36373656 /* Return a pointer to the head of the dynamic reloc list that should
@@ -9729,6 +9748,10 @@ elf32_arm_populate_plt_entry (bfd *output_bfd, struct bfd_link_info *info,
97299748 }
97309749 else if (htab->fdpic_p)
97319750 {
9751+ const bfd_vma *plt_entry = using_thumb_only(htab)
9752+ ? elf32_arm_fdpic_thumb_plt_entry
9753+ : elf32_arm_fdpic_plt_entry;
9754+
97329755 /* Fill-up Thumb stub if needed. */
97339756 if (elf32_arm_plt_needs_thumb_stub_p (info, arm_plt))
97349757 {
@@ -9737,14 +9760,13 @@ elf32_arm_populate_plt_entry (bfd *output_bfd, struct bfd_link_info *info,
97379760 put_thumb_insn (htab, output_bfd,
97389761 elf32_arm_plt_thumb_stub[1], ptr - 2);
97399762 }
9740- put_arm_insn(htab, output_bfd,
9741- elf32_arm_fdpic_plt_entry[0], ptr + 0);
9742- put_arm_insn(htab, output_bfd,
9743- elf32_arm_fdpic_plt_entry[1], ptr + 4);
9744- put_arm_insn(htab, output_bfd,
9745- elf32_arm_fdpic_plt_entry[2], ptr + 8);
9746- put_arm_insn(htab, output_bfd,
9747- elf32_arm_fdpic_plt_entry[3], ptr + 12);
9763+ /* As we are using 32 bit instructions even for the Thumb
9764+ version, we have to use 'put_arm_insn' instead of
9765+ 'put_thumb_insn'. */
9766+ put_arm_insn(htab, output_bfd, plt_entry[0], ptr + 0);
9767+ put_arm_insn(htab, output_bfd, plt_entry[1], ptr + 4);
9768+ put_arm_insn(htab, output_bfd, plt_entry[2], ptr + 8);
9769+ put_arm_insn(htab, output_bfd, plt_entry[3], ptr + 12);
97489770 bfd_put_32 (output_bfd, got_offset, ptr + 16);
97499771
97509772 if (!(info->flags & DF_BIND_NOW))
@@ -9753,14 +9775,10 @@ elf32_arm_populate_plt_entry (bfd *output_bfd, struct bfd_link_info *info,
97539775 bfd_put_32 (output_bfd,
97549776 htab->root.srelplt->reloc_count * RELOC_SIZE (htab),
97559777 ptr + 20);
9756- put_arm_insn(htab, output_bfd,
9757- elf32_arm_fdpic_plt_entry[6], ptr + 24);
9758- put_arm_insn(htab, output_bfd,
9759- elf32_arm_fdpic_plt_entry[7], ptr + 28);
9760- put_arm_insn(htab, output_bfd,
9761- elf32_arm_fdpic_plt_entry[8], ptr + 32);
9762- put_arm_insn(htab, output_bfd,
9763- elf32_arm_fdpic_plt_entry[9], ptr + 36);
9778+ put_arm_insn(htab, output_bfd, plt_entry[6], ptr + 24);
9779+ put_arm_insn(htab, output_bfd, plt_entry[7], ptr + 28);
9780+ put_arm_insn(htab, output_bfd, plt_entry[8], ptr + 32);
9781+ put_arm_insn(htab, output_bfd, plt_entry[9], ptr + 36);
97649782 }
97659783 }
97669784 else if (using_thumb_only (htab))
@@ -17767,15 +17785,19 @@ elf32_arm_output_plt_map_1 (output_arch_syminfo *osi,
1776717785 }
1776817786 else if (htab->fdpic_p)
1776917787 {
17788+ enum map_symbol_type type = using_thumb_only(htab)
17789+ ? ARM_MAP_THUMB
17790+ : ARM_MAP_ARM;
17791+
1777017792 if (elf32_arm_plt_needs_thumb_stub_p (osi->info, arm_plt))
1777117793 if (!elf32_arm_output_map_sym (osi, ARM_MAP_THUMB, addr - 4))
1777217794 return FALSE;
17773- if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
17795+ if (!elf32_arm_output_map_sym (osi, type, addr))
1777417796 return FALSE;
1777517797 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 16))
1777617798 return FALSE;
1777717799 if (htab->plt_entry_size == 4 * ARRAY_SIZE(elf32_arm_fdpic_plt_entry))
17778- if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr + 24))
17800+ if (!elf32_arm_output_map_sym (osi, type, addr + 24))
1777917801 return FALSE;
1778017802 }
1778117803 else if (using_thumb_only (htab))
@@ -18134,7 +18156,7 @@ elf32_arm_output_arch_local_syms (bfd *output_bfd,
1813418156 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
1813518157 return FALSE;
1813618158 }
18137- else if (using_thumb_only (htab))
18159+ else if (using_thumb_only (htab) && !htab->fdpic_p)
1813818160 {
1813918161 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_THUMB, 0))
1814018162 return FALSE;
--- a/ld/testsuite/ld-arm/arm-elf.exp
+++ b/ld/testsuite/ld-arm/arm-elf.exp
@@ -1043,6 +1043,18 @@ set armfdpiceabitests {
10431043 {{objdump -fdw fdpic-main.d} {objdump -Rw fdpic-main.r}
10441044 {readelf -Ds fdpic-main.sym}}
10451045 "fdpic-main"}
1046+ {"FDPIC ARM shared library little endian M profile"
1047+ "-shared -T fdpic-shared.ld --hash-style=sysv -EL -m armelf_linux_fdpiceabi" ""
1048+ "-EL -fdpic" {fdpic-shared-m.s}
1049+ {{objdump -fdw fdpic-shared-m.d} {objdump -Rw fdpic-shared.r}
1050+ {readelf -Ds fdpic-shared-m.sym}}
1051+ "fdpic-shared.so"}
1052+ {"FDPIC ARM dynamic executable little endian M profile"
1053+ "tmpdir/fdpic-shared.so -T fdpic-main.ld --hash-style=sysv -EL -m armelf_linux_fdpiceabi" ""
1054+ "-EL -fdpic" {fdpic-main-m.s}
1055+ {{objdump -fdw fdpic-main-m.d} {objdump -Rw fdpic-main.r}
1056+ {readelf -Ds fdpic-main-m.sym}}
1057+ "fdpic-main"}
10461058 }
10471059
10481060 # Massage the $armeabitests_common list into run_ld_link_tests standard form.
--- /dev/null
+++ b/ld/testsuite/ld-arm/fdpic-main-m.d
@@ -0,0 +1,73 @@
1+
2+tmpdir/fdpic-main: file format elf32-(little|big)arm
3+architecture: arm.*, flags 0x00000112:
4+EXEC_P, HAS_SYMS, D_PAGED
5+start address 0x.*
6+
7+Disassembly of section .plt:
8+
9+.* <.plt>:
10+ .*: f8df c00c ldr.w ip, \[pc, #12\] ; .* <.plt\+0x10>
11+ .*: eb0c 0c09 add.w ip, ip, r9
12+ .*: f8dc 9004 ldr.w r9, \[ip, #4\]
13+ .*: f8dc f000 ldr.w pc, \[ip\]
14+ .*: 0000000c .word 0x0000000c
15+ .*: 00000000 .word 0x00000000
16+ .*: f85f c008 ldr.w ip, \[pc, #-8\] ; .* <.plt\+0x14>
17+ .*: f84d cd04 str.w ip, \[sp, #-4\]!
18+ .*: f8d9 c004 ldr.w ip, \[r9, #4\]
19+ .*: f8d9 f000 ldr.w pc, \[r9\]
20+ .*: f8df c00c ldr.w ip, \[pc, #12\] ; .* <.plt\+0x38>
21+ .*: eb0c 0c09 add.w ip, ip, r9
22+ .*: f8dc 9004 ldr.w r9, \[ip, #4\]
23+ .*: f8dc f000 ldr.w pc, \[ip]
24+ .*: 00000014 .word 0x00000014
25+ .*: 00000008 .word 0x00000008
26+ .*: f85f c008 ldr.w ip, \[pc, #-8\] ; .* <.plt\+0x3c>
27+ .*: f84d cd04 str.w ip, \[sp, #-4\]!
28+ .*: f8d9 c004 ldr.w ip, \[r9, #4\]
29+ .*: f8d9 f000 ldr.w pc, \[r9\]
30+
31+Disassembly of section .text:
32+
33+.* <_start>:
34+ .*: f000 b800 b.w .* <main>
35+
36+.* <main>:
37+ .*: 4a11 ldr r2, \[pc, #68\] ; .* <main\+0x48>.*
38+ .*: 4b12 ldr r3, \[pc, #72\] ; .* <main\+0x4c>.*
39+ .*: b570 push {r4, r5, r6, lr}
40+ .*: f859 5002 ldr.w r5, \[r9, r2\]
41+ .*: 464c mov r4, r9
42+ .*: f859 3003 ldr.w r3, \[r9, r3\]
43+ .*: 602b str r3, \[r5, #0\]
44+ .*: f7ff ffcb bl .* <.plt>
45+ .*: 4606 mov r6, r0
46+ .*: 46a1 mov r9, r4
47+ .*: 6828 ldr r0, \[r5, #0\]
48+ .*: 46a1 mov r9, r4
49+ .*: f7ff ffd9 bl .* <.plt\+0x28>
50+ .*: 4b0b ldr r3, \[pc, #44\] ; .* <main\+0x50>.*
51+ .*: 46a1 mov r9, r4
52+ .*: 444b add r3, r9
53+ .*: 4618 mov r0, r3
54+ .*: 602b str r3, \[r5, #0\]
55+ .*: 46a1 mov r9, r4
56+ .*: f7ff ffd1 bl .* <.plt\+0x28>
57+ .*: 4b08 ldr r3, \[pc, #32\] ; .* <main\+0x54>.*
58+ .*: 46a1 mov r9, r4
59+ .*: f859 3003 ldr.w r3, \[r9, r3\]
60+ .*: 6818 ldr r0, \[r3, #0\]
61+ .*: 46a1 mov r9, r4
62+ .*: f7ff ffc9 bl .* <.plt\+0x28>
63+ .*: 4630 mov r0, r6
64+ .*: 46a1 mov r9, r4
65+ .*: bd70 pop {r4, r5, r6, pc}
66+ .*: 0000002c .word 0x0000002c
67+ .*: 00000024 .word 0x00000024
68+ .*: 0000001c .word 0x0000001c
69+ .*: 00000028 .word 0x00000028
70+
71+.* <my_local_func>:
72+ .*: 4770 bx lr
73+ .*: bf00 nop
--- /dev/null
+++ b/ld/testsuite/ld-arm/fdpic-main-m.s
@@ -0,0 +1,86 @@
1+ .arch armv7-m
2+ .eabi_attribute 20, 1
3+ .eabi_attribute 21, 1
4+ .eabi_attribute 23, 3
5+ .eabi_attribute 24, 1
6+ .eabi_attribute 25, 1
7+ .eabi_attribute 26, 2
8+ .eabi_attribute 30, 2
9+ .eabi_attribute 34, 1
10+ .eabi_attribute 18, 4
11+ .file "hello.c"
12+ .text
13+ .align 2
14+ .syntax unified
15+ .thumb
16+ .fpu softvfp
17+ .type my_local_func, %function
18+my_local_func:
19+ @ args = 0, pretend = 0, frame = 0
20+ @ frame_needed = 0, uses_anonymous_args = 0
21+ @ link register save eliminated.
22+ bx lr
23+ .size my_local_func, .-my_local_func
24+ .section .text.startup,"ax",%progbits
25+ .align 2
26+ .global _start
27+ .syntax unified
28+ .thumb
29+ .fpu softvfp
30+ .type _start, %function
31+_start:
32+ b main
33+
34+ .global main
35+ .syntax unified
36+ .thumb
37+ .fpu softvfp
38+ .type main, %function
39+main:
40+ @ args = 0, pretend = 0, frame = 0
41+ @ frame_needed = 0, uses_anonymous_args = 0
42+ ldr r2, .L4
43+ ldr r3, .L4+4
44+ push {r4, r5, r6, lr}
45+ ldr r5, [r9, r2]
46+ mov r4, r9
47+ ldr r3, [r9, r3]
48+ str r3, [r5]
49+ bl my_shared_func1(PLT)
50+ mov r6, r0
51+ mov r9, r4
52+ ldr r0, [r5]
53+ mov r9, r4
54+ bl my_shared_func2(PLT)
55+ ldr r3, .L4+8
56+ mov r9, r4
57+ add r3, r3, r9
58+ mov r0, r3
59+ str r3, [r5]
60+ mov r9, r4
61+ bl my_shared_func2(PLT)
62+ ldr r3, .L4+12
63+ mov r9, r4
64+ ldr r3, [r9, r3]
65+ ldr r0, [r3]
66+ mov r9, r4
67+ bl my_shared_func2(PLT)
68+ mov r0, r6
69+ mov r9, r4
70+ pop {r4, r5, r6, pc}
71+.L5:
72+ .align 2
73+.L4:
74+ .word funcptr(GOT)
75+ .word my_shared_func1(GOTFUNCDESC)
76+ .word my_local_func(GOTOFFFUNCDESC)
77+ .word funcptr2(GOT)
78+ .size main, .-main
79+ .global funcptr2
80+ .comm funcptr,4,4
81+ .section .data.rel,"aw",%progbits
82+ .align 2
83+ .type funcptr2, %object
84+ .size funcptr2, 4
85+funcptr2:
86+ .word my_shared_func1(FUNCDESC)
--- /dev/null
+++ b/ld/testsuite/ld-arm/fdpic-main-m.sym
@@ -0,0 +1,14 @@
1+
2+Symbol table for image:
3+ +Num +Buc: +Value +Size +Type +Bind +Vis +Ndx +Name
4+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT +12 _edata
5+ +.. +..: ........ +0 +FUNC +GLOBAL +DEFAULT +UND my_shared_func2
6+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT +12 __bss_start__
7+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT +13 _end
8+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT +13 __bss_end__
9+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT +13 __end__
10+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT + 9 __ROFIXUP_LIST__
11+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT +12 __bss_start
12+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT + 9 __ROFIXUP_END__
13+ +.. +..: ........ +0 +FUNC +GLOBAL +DEFAULT +UND my_shared_func1
14+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT +13 _bss_end__
--- /dev/null
+++ b/ld/testsuite/ld-arm/fdpic-shared-m.d
@@ -0,0 +1,37 @@
1+
2+tmpdir/fdpic-shared.so: file format elf32-(little|big)arm
3+architecture: arm.*, flags 0x00000150:
4+HAS_SYMS, DYNAMIC, D_PAGED
5+start address 0x.*
6+
7+Disassembly of section .plt:
8+
9+.* <.plt>:
10+ .*: f8df c00c ldr.w ip, \[pc, #12\] ; .* <.plt\+0x10>
11+ .*: eb0c 0c09 add.w ip, ip, r9
12+ .*: f8dc 9004 ldr.w r9, \[ip, #4\]
13+ .*: f8dc f000 ldr.w pc, \[ip\]
14+ .*: 0000000c .word 0x0000000c
15+ .*: 00000000 .word 0x00000000
16+ .*: f85f c008 ldr.w ip, \[pc, #-8\] ; .* <.plt\+0x14>
17+ .*: f84d cd04 str.w ip, \[sp, #-4\]!
18+ .*: f8d9 c004 ldr.w ip, \[r9, #4\]
19+ .*: f8d9 f000 ldr.w pc, \[r9\]
20+
21+Disassembly of section .text:
22+
23+.* <my_shared_func1>:
24+ .*: 4770 bx lr
25+ .*: bf00 nop
26+
27+.* <my_shared_func3>:
28+ .*: f04f 0000 mov.w r0, #0
29+ .*: 4770 bx lr
30+ .*: bf00 nop
31+
32+.* <my_shared_func2>:
33+ .*: b510 push {r4, lr}
34+ .*: 464c mov r4, r9
35+ .*: f7ff ffe2 bl .* <.plt>
36+ .*: 46a1 mov r9, r4
37+ .*: bd10 pop {r4, pc}
--- /dev/null
+++ b/ld/testsuite/ld-arm/fdpic-shared-m.s
@@ -0,0 +1,52 @@
1+ .arch armv7-m
2+ .eabi_attribute 20, 1
3+ .eabi_attribute 21, 1
4+ .eabi_attribute 23, 3
5+ .eabi_attribute 24, 1
6+ .eabi_attribute 25, 1
7+ .eabi_attribute 26, 2
8+ .eabi_attribute 30, 2
9+ .eabi_attribute 34, 1
10+ .eabi_attribute 18, 4
11+ .file "shared.c"
12+ .text
13+ .align 2
14+ .global my_shared_func1
15+ .syntax unified
16+ .thumb
17+ .fpu softvfp
18+ .type my_shared_func1, %function
19+my_shared_func1:
20+ @ args = 0, pretend = 0, frame = 0
21+ @ frame_needed = 0, uses_anonymous_args = 0
22+ @ link register save eliminated.
23+ bx lr
24+ .size my_shared_func1, .-my_shared_func1
25+ .align 2
26+ .global my_shared_func3
27+ .syntax unified
28+ .thumb
29+ .fpu softvfp
30+ .type my_shared_func3, %function
31+my_shared_func3:
32+ @ args = 0, pretend = 0, frame = 0
33+ @ frame_needed = 0, uses_anonymous_args = 0
34+ @ link register save eliminated.
35+ mov r0, #0
36+ bx lr
37+ .size my_shared_func3, .-my_shared_func3
38+ .align 2
39+ .global my_shared_func2
40+ .syntax unified
41+ .thumb
42+ .fpu softvfp
43+ .type my_shared_func2, %function
44+my_shared_func2:
45+ @ args = 0, pretend = 0, frame = 0
46+ @ frame_needed = 0, uses_anonymous_args = 0
47+ push {r4, lr}
48+ mov r4, r9
49+ bl my_shared_func3(PLT)
50+ mov r9, r4
51+ pop {r4, pc}
52+ .size my_shared_func2, .-my_shared_func2
--- /dev/null
+++ b/ld/testsuite/ld-arm/fdpic-shared-m.sym
@@ -0,0 +1,15 @@
1+
2+Symbol table for image:
3+ +Num +Buc: +Value +Size +Type +Bind +Vis +Ndx +Name
4+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT +9 _edata
5+ +.. +..: ........ +12 +FUNC +GLOBAL +DEFAULT +6 my_shared_func2
6+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT +9 __bss_start__
7+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT +9 _end
8+ +.. +..: ........ +6 +FUNC +GLOBAL +DEFAULT +6 my_shared_func3
9+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT +9 __bss_end__
10+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT +9 __end__
11+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT +7 __ROFIXUP_LIST__
12+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT +9 __bss_start
13+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT +7 __ROFIXUP_END__
14+ +.. +..: ........ +2 +FUNC +GLOBAL +DEFAULT +6 my_shared_func1
15+ +.. +..: ........ +0 +NOTYPE +GLOBAL +DEFAULT +9 _bss_end__