Created attachment 7400 [details] source code when i static link the source in attachment with ld relax option,i get a error like this: ~/toolchain/ppc_gcc4.5.2_glibc2.13.0_multi/bin/ppc6xx-softfloat-linux-gnu-gcc -o test pthread_tls_relax_tst.c -lpthread --save-temps --static -Wl,--relax /home/wangdeqiang/gcc4.5.2_glibc2.13.0/src/ppc_multi/build-binutils/ld/ld-new: BFD (GNU Binutils) 2.24 assertion fail /home/wangdeqiang/gcc4.5.2_glibc2.13.0/src/ppc_multi/binutils-2.21/bfd/elf32-ppc.c:7731 when i look into the code , i find ppc_elf_relax_section relax the call to __tls_get_addr, and modify the relocation of tls access in global-dynamic and local-dynamic mode , in fuction ppc_elf_relocate_section when we do tls optimize to change the global-dynamic mode or local-dynamic mode to initial-exec mode, we need the relocation type information, but it is changed in ppc_elf_relax_section, so we got this error. normally powerpc ld always do tls optimize, so i think we should just ignore the tls_get_addr symbol in ppc_elf_relax_section .
my solution is very simple, we just ignore the tls_get_addr in ppc_elf_relax_section: static bfd_boolean ppc_elf_relax_section (bfd *abfd, asection *isec, struct bfd_link_info *link_info, bfd_boolean *again) { ............. while (h->root.type == bfd_link_hash_indirect || h->root.type == bfd_link_hash_warning) h = (struct elf_link_hash_entry *) h->root.u.i.link; + if ((h == htab->tls_get_addr ) && ( (link_info->relocatable || link_info->executable))) + continue;
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "gdb and binutils". The branch, master has been updated via 9f7552cff4367fc58246f72223d7a1de84c660b7 (commit) via 795bc6b3eac9e3f80279df69c05d70fc44eaaa4c (commit) via b407645f7ef086a9a527c8f62499b4255868e748 (commit) from 93ffa5b939aef24f7530a8a400f877bfb24f0a73 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9f7552cff4367fc58246f72223d7a1de84c660b7 commit 9f7552cff4367fc58246f72223d7a1de84c660b7 Author: Alan Modra <amodra@gmail.com> Date: Wed Feb 12 21:04:32 2014 +1030 Fix bad interaction between --relax and tls optimisation Adding long-branch stubs for __tls_get_addr calls that are optimised away is silly. It also causes assertion failures on newer object files that use R_PPC_TLSGD and R_PPC_TLSLD marker relocs, and half-optimised (ie. broken) code for older object files. PR 16546 * elf32-ppc.c (ppc_elf_relax_section): Don't build long-branch stubs for calls to __tls_get_addr that we know will later be optimised away. https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=795bc6b3eac9e3f80279df69c05d70fc44eaaa4c commit 795bc6b3eac9e3f80279df69c05d70fc44eaaa4c Author: Alan Modra <amodra@gmail.com> Date: Wed Feb 12 16:44:36 2014 +1030 Enable ppc476 workaround for ld -r. The Linux kernel builds modules using ld -r. These might need the ppc476 workaround, so enable it for ld -r if sections have sufficient alignment to tell location within a page. bfd/ * elf32-ppc.c (ppc_elf_relax_section): Enable ppc476 workaround for ld -r, when code sections are sufficiently aligned. * elf32-ppc.h (struct ppc_elf_params): Delete pagesize. Add pagesize_p2. ld/ * emultempl/ppc32elf.em (pagesize): New static var. (ppc_after_open_output): Set params.pagesize_p2 from pagesize. (PARSE_AND_LIST_ARGS_CASES): Adjust to use pagesize. https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b407645f7ef086a9a527c8f62499b4255868e748 commit b407645f7ef086a9a527c8f62499b4255868e748 Author: Alan Modra <amodra@gmail.com> Date: Wed Feb 12 21:08:01 2014 +1030 PR15530, mark symbol in executables if it matches dynamic_list For powerpc64 as HJ did earlier for other ELF targets, and a tidy. PR gold/15530 * elf64-ppc.c (ppc64_elf_gc_mark_dynamic_ref): Support --export-dynamic and --dynamic-list marking of symbols. * elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Reorder cheap tests first. ----------------------------------------------------------------------- Summary of changes: bfd/ChangeLog | 21 +++++++++++++ bfd/elf32-ppc.c | 73 ++++++++++++++++++++++++++++++++++++++++++---- bfd/elf32-ppc.h | 2 +- bfd/elf64-ppc.c | 9 ++++- bfd/elflink.c | 11 ++++--- ld/ChangeLog | 6 ++++ ld/emultempl/ppc32elf.em | 13 +++++--- 7 files changed, 116 insertions(+), 19 deletions(-)
Fixed. Memo to self, push patches for PRs separately.
got it,thanks
there is still some problem: if a.o and b.o are partial linked into c.o, and b.o has some tls GD relocs, then __tls_get_addr call in b.o still may be relaxed, those TLS relocs still can't be optimized in final link. so i think maybe we should just ignore the __tls_get_addr
There is very little reason to use --relax with -r unless you're building kernel modules or something similar where there will by no further linking stage. Just don't use --relax with ld -r when you will be doing a later final link.
but ld doesn't forbid using --relax with -r, and i think the best solution is that we shouldn't let ppc_elf_relax_section to handle __tls_get_addr