mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-20 15:53:29 +08:00
5474d94f03
Variables defined in shared libraries are copied into an executable's .bss section when code in the executable is non-PIC and thus would require dynamic text relocations to access the variable directly in the shared library. Recent x86 toolchains also copy variables into the executable to gain a small speed improvement. The problem is that if the variable was originally read-only, the copy in .bss is writable, potentially opening a security hole. This patch cures that problem by putting the copy in a section that becomes read-only after ld.so relocation, provided -z relro is in force. The patch also fixes a microblaze linker segfault on attempting to use dynamic bss variables. bfd/ PR ld/20995 * elf-bfd.h (struct elf_link_hash_table): Add sdynrelro and sreldynrelro. (struct elf_backend_data): Add want_dynrelro. * elfxx-target.h (elf_backend_want_dynrelro): Define. (elfNN_bed): Update initializer. * elflink.c (_bfd_elf_create_dynamic_sections): Create sdynrelro and sreldynrelro sections. * elf32-arm.c (elf32_arm_adjust_dynamic_symbol): Place variables copied into the executable from read-only sections into sdynrelro. (elf32_arm_size_dynamic_sections): Handle sdynrelro. (elf32_arm_finish_dynamic_symbol): Select sreldynrelro for dynamic relocs in sdynrelro. (elf_backend_want_dynrelro): Define. * elf32-hppa.c (elf32_hppa_adjust_dynamic_symbol) (elf32_hppa_size_dynamic_sections, elf32_hppa_finish_dynamic_symbol) (elf_backend_want_dynrelro): As above. * elf32-i386.c (elf_i386_adjust_dynamic_symbol) (elf_i386_size_dynamic_sections, elf_i386_finish_dynamic_symbol) (elf_backend_want_dynrelro): As above. * elf32-metag.c (elf_metag_adjust_dynamic_symbol) (elf_metag_size_dynamic_sections, elf_metag_finish_dynamic_symbol) (elf_backend_want_dynrelro): As above. * elf32-microblaze.c (microblaze_elf_adjust_dynamic_symbol) (microblaze_elf_size_dynamic_sections) (microblaze_elf_finish_dynamic_symbol) (elf_backend_want_dynrelro): As above. * elf32-nios2.c (nios2_elf32_finish_dynamic_symbol) (nios2_elf32_adjust_dynamic_symbol) (nios2_elf32_size_dynamic_sections) (elf_backend_want_dynrelro): As above. * elf32-or1k.c (or1k_elf_finish_dynamic_symbol) (or1k_elf_adjust_dynamic_symbol, or1k_elf_size_dynamic_sections) (elf_backend_want_dynrelro): As above. * elf32-ppc.c (ppc_elf_adjust_dynamic_symbol) (ppc_elf_size_dynamic_sections, ppc_elf_finish_dynamic_symbol) (elf_backend_want_dynrelro): As above. * elf32-s390.c (elf_s390_adjust_dynamic_symbol) (elf_s390_size_dynamic_sections, elf_s390_finish_dynamic_symbol) (elf_backend_want_dynrelro): As above. * elf32-tic6x.c (elf32_tic6x_adjust_dynamic_symbol) (elf32_tic6x_size_dynamic_sections) (elf32_tic6x_finish_dynamic_symbol) (elf_backend_want_dynrelro): As above. * elf32-tilepro.c (tilepro_elf_adjust_dynamic_symbol) (tilepro_elf_size_dynamic_sections) (tilepro_elf_finish_dynamic_symbol) (elf_backend_want_dynrelro): As above. * elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol) (ppc64_elf_size_dynamic_sections, ppc64_elf_finish_dynamic_symbol) (elf_backend_want_dynrelro): As above. * elf64-s390.c (elf_s390_adjust_dynamic_symbol) (elf_s390_size_dynamic_sections, elf_s390_finish_dynamic_symbol) (elf_backend_want_dynrelro): As above. * elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol) (elf_x86_64_size_dynamic_sections) (elf_x86_64_finish_dynamic_symbol) (elf_backend_want_dynrelro): As above. * elfnn-aarch64.c (elfNN_aarch64_adjust_dynamic_symbol) (elfNN_aarch64_size_dynamic_sections) (elfNN_aarch64_finish_dynamic_symbol) (elf_backend_want_dynrelro): As above. * elfnn-riscv.c (riscv_elf_adjust_dynamic_symbol) (riscv_elf_size_dynamic_sections, riscv_elf_finish_dynamic_symbol) (elf_backend_want_dynrelro): As above. * elfxx-mips.c (_bfd_mips_elf_adjust_dynamic_symbol) (_bfd_mips_elf_size_dynamic_sections) (_bfd_mips_vxworks_finish_dynamic_symbol): As above. * elfxx-sparc.c (_bfd_sparc_elf_adjust_dynamic_symbol) (_bfd_sparc_elf_size_dynamic_sections) (_bfd_sparc_elf_finish_dynamic_symbol): As above. * elfxx-tilegx.c (tilegx_elf_adjust_dynamic_symbol) (tilegx_elf_size_dynamic_sections) (tilegx_elf_finish_dynamic_symbol): As above. * elf32-mips.c (elf_backend_want_dynrelro): Define. * elf64-mips.c (elf_backend_want_dynrelro): Define. * elf32-sparc.c (elf_backend_want_dynrelro): Define. * elf64-sparc.c (elf_backend_want_dynrelro): Define. * elf32-tilegx.c (elf_backend_want_dynrelro): Define. * elf64-tilegx.c (elf_backend_want_dynrelro): Define. * elf32-microblaze.c (microblaze_elf_adjust_dynamic_symbol): Tidy. (microblaze_elf_size_dynamic_sections): Handle sdynbss. * elf32-nios2.c (nios2_elf32_size_dynamic_sections): Make use of linker shortcuts to dynamic sections rather than comparing names. Correctly set "got" flag. ld/ PR ld/20995 * testsuite/ld-arm/farcall-mixed-app-v5.d: Update to suit changed stub hash table traversal caused by section id increment. Accept the previous output too. * testsuite/ld-arm/farcall-mixed-app.d: Likewise. * testsuite/ld-arm/farcall-mixed-lib-v4t.d: Likewise. * testsuite/ld-arm/farcall-mixed-lib.d: Likewise. * testsuite/ld-elf/pr20995a.s, * testsuite/ld-elf/pr20995b.s, * testsuite/ld-elf/pr20995.r: New test. * testsuite/ld-elf/elf.exp: Run it.
84 lines
2.2 KiB
Makefile
84 lines
2.2 KiB
Makefile
|
|
tmpdir/farcall-mixed-app-v5: file format elf32-(little|big)arm
|
|
architecture: armv4t, flags 0x00000112:
|
|
EXEC_P, HAS_SYMS, D_PAGED
|
|
start address 0x.*
|
|
|
|
Disassembly of section .plt:
|
|
|
|
.* <.plt>:
|
|
.*: e52de004 push {lr} ; \(str lr, \[sp, #-4\]!\)
|
|
.*: e59fe004 ldr lr, \[pc, #4\] ; .* <.*>
|
|
.*: e08fe00e add lr, pc, lr
|
|
.*: e5bef008 ldr pc, \[lr, #8\]!
|
|
.*: .*
|
|
.* <lib_func2@plt>:
|
|
.*: e28fc6.* add ip, pc, #.*
|
|
.*: e28cca.* add ip, ip, #.* ; 0x.*
|
|
.*: e5bcf.* ldr pc, \[ip, #.*\]!.*
|
|
.* <lib_func1@plt>:
|
|
.*: e28fc6.* add ip, pc, #.*
|
|
.*: e28cca.* add ip, ip, #.* ; 0x.*
|
|
.*: e5bcf.* ldr pc, \[ip, #.*\]!.*
|
|
|
|
Disassembly of section .text:
|
|
|
|
.* <_start>:
|
|
.*: e1a0c00d mov ip, sp
|
|
.*: e92dd800 push {fp, ip, lr, pc}
|
|
.*: eb000008 bl .* <__app_func_veneer>
|
|
.*: ebfffff5 bl .* <lib_func1@plt>
|
|
.*: ebfffff1 bl .* <lib_func2@plt>
|
|
.*: e89d6800 ldm sp, {fp, sp, lr}
|
|
.*: e12fff1e bx lr
|
|
.*: e1a00000 nop ; \(mov r0, r0\)
|
|
|
|
.* <app_tfunc_close>:
|
|
.*: b500 push {lr}
|
|
.*: f7ff efdc blx .* <lib_func2@plt>
|
|
.*: bd00 pop {pc}
|
|
.*: 4770 bx lr
|
|
.*: 46c0 nop ; \(mov r8, r8\)
|
|
#...
|
|
|
|
.* <__app_func_veneer>:
|
|
.*: e51ff004 ldr pc, \[pc, #-4\] ; .* <__app_func_veneer\+0x4>
|
|
.*: 02100000 .word 0x02100000
|
|
|
|
Disassembly of section .far_arm:
|
|
|
|
.* <app_func>:
|
|
.*: e1a0c00d mov ip, sp
|
|
.*: e92dd800 push {fp, ip, lr, pc}
|
|
.*: eb00000(6|8) bl .* <__lib_func1_veneer>
|
|
.*: eb00000(7|5) bl .* <__lib_func2_veneer>
|
|
.*: e89d6800 ldm sp, {fp, sp, lr}
|
|
.*: e12fff1e bx lr
|
|
.*: e1a00000 nop ; \(mov r0, r0\)
|
|
.*: e1a00000 nop ; \(mov r0, r0\)
|
|
|
|
.* <app_func2>:
|
|
.*: e12fff1e bx lr
|
|
#...
|
|
|
|
.* <__lib_func(1|2)_veneer>:
|
|
.*: e51ff004 ldr pc, \[pc, #-4\] ; .* <__lib_func(1|2)_veneer\+0x4>
|
|
.*: 000081(e8|dc) .word 0x000081(e8|dc)
|
|
.* <__lib_func(2|1)_veneer>:
|
|
.*: e51ff004 ldr pc, \[pc, #-4\] ; .* <__lib_func(2|1)_veneer\+0x4>
|
|
.*: 000081(dc|e8) .word 0x000081(dc|e8)
|
|
|
|
Disassembly of section .far_thumb:
|
|
|
|
.* <app_tfunc>:
|
|
.*: b500 push {lr}
|
|
.*: f000 e806 blx .* <__lib_func2_from_thumb>
|
|
.*: bd00 pop {pc}
|
|
.*: 4770 bx lr
|
|
.*: 46c0 nop ; \(mov r8, r8\)
|
|
#...
|
|
|
|
.* <__lib_func2_from_thumb>:
|
|
.*: e51ff004 ldr pc, \[pc, #-4\] ; 2200014 <__lib_func2_from_thumb\+0x4>
|
|
.*: 000081dc .word 0x000081dc
|