From dbd1e97e32057af2841e5150daa2e2d4cb046a3b Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Tue, 27 Jan 2015 23:40:05 +1030 Subject: PowerPC64 changes for xlc The changes to reorder sections for better relro protection on powerpc64, 3e2b0f31, 23283c1b, and 5ad18f16, run into a problem with xlc. xlc -qdatalocal puts global variables into .toc, which means that .toc must be writable. The simplest way to accomplish this is to edit the linker script to remove .toc sections from .got on detecting xlc object files. bfd/ * elf64-ppc.h (struct ppc64_elf_params): Add "object_in_toc". * elf64-ppc.c (ppc64_elf_add_symbol_hook): Assume that global symbols in .toc indicate xlc compiled code that might require a rw .toc. ld/ * emulparams/elf64ppc.sh (INITIAL_READWRITE_SECTIONS): Define. * emultempl/ppc64elf.em (params): Init new field. (ppc_after_open): New function. (LDEMUL_AFTER_OPEN): Define. * ldlang.c (lang_final): Whitespace fix. ld/testsuite/ * ld-powerpc/tocvar.d, * ld-powerpc/tocvar.s: New test. * ld-powerpc/tocnovar.d, * ld-powerpc/tocnovar.s: New test. * ld-powerpc/powerpc.exp: Run tocvar and tocnovar. --- bfd/ChangeLog | 6 ++++++ bfd/elf64-ppc.c | 8 ++++++++ bfd/elf64-ppc.h | 3 +++ 3 files changed, 17 insertions(+) (limited to 'bfd') diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 581b312..f5a50fa 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2015-01-28 Alan Modra + + * elf64-ppc.h (struct ppc64_elf_params): Add "object_in_toc". + * elf64-ppc.c (ppc64_elf_add_symbol_hook): Assume that global symbols + in .toc indicate xlc compiled code that might require a rw .toc. + 2015-01-28 James Bowman * Makefile.am: Add FT32 files. diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index 8c7c3b7..da37465 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -4836,6 +4836,14 @@ ppc64_elf_add_symbol_hook (bfd *ibfd, isym->st_shndx = SHN_UNDEF; } } + else if (*sec != NULL + && strcmp ((*sec)->name, ".toc") == 0 + && ELF_ST_TYPE (isym->st_info) == STT_OBJECT) + { + struct ppc_link_hash_table *htab = ppc_hash_table (info); + if (htab != NULL) + htab->params->object_in_toc = 1; + } if ((STO_PPC64_LOCAL_MASK & isym->st_other) != 0) { diff --git a/bfd/elf64-ppc.h b/bfd/elf64-ppc.h index 8c627a4..19f72b5 100644 --- a/bfd/elf64-ppc.h +++ b/bfd/elf64-ppc.h @@ -57,6 +57,9 @@ struct ppc64_elf_params /* Whether to generate out-of-line register save/restore for gcc -Os code. */ int save_restore_funcs; + + /* Set when a potential variable is detected in .toc. */ + int object_in_toc; }; bfd_boolean ppc64_elf_init_stub_bfd -- cgit v1.1