aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2018-07-25 15:24:55 +0930
committerAlan Modra <amodra@gmail.com>2018-07-25 16:52:58 +0930
commit491993044ba6cfb2b0fc93c8b3032d5c91cccda5 (patch)
treeef399640acd0e20d9bd6f165015a882f66f0faad /bfd
parentbe3e27bb5554e45d54d7cdc74353dda246239475 (diff)
downloadgdb-491993044ba6cfb2b0fc93c8b3032d5c91cccda5.zip
gdb-491993044ba6cfb2b0fc93c8b3032d5c91cccda5.tar.gz
gdb-491993044ba6cfb2b0fc93c8b3032d5c91cccda5.tar.bz2
Enhance powerpc ld -r --relax
One of the ill effects of ld -r is to mash together sections. That can result in reduced icache performance at runtime due to unexpected movement of code. Another problem is that sections can become too large to link on targets that have limited relative addressing. ld -r --relax attempts to overcome the large section problem for branches by inserting trampolines, but the powerpc support added lots of unnecessary trampolines. This patch trims them somewhat. bfd/ * elf32-ppc.c (ppc_elf_relax_section): Ignore common or undef locals. Avoid trashing toff with added when used as a symbol index. Ignore R_PPC_PLTREL24 addends in unused example code. Avoid creating unnecessary fixups when relocatable. ld/ * testsuite/ld-powerpc/big.s: New file. * testsuite/ld-powerpc/relaxrl.d: New test. * testsuite/ld-powerpc/powerpc.exp: Run new test. * testsuite/ld-powerpc/relaxr.d: Adjust.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog7
-rw-r--r--bfd/elf32-ppc.c33
2 files changed, 34 insertions, 6 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 8efa387..e0e1a46 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,12 @@
2018-07-25 Alan Modra <amodra@gmail.com>
+ * elf32-ppc.c (ppc_elf_relax_section): Ignore common or undef locals.
+ Avoid trashing toff with added when used as a symbol index.
+ Ignore R_PPC_PLTREL24 addends in unused example code. Avoid
+ creating unnecessary fixups when relocatable.
+
+2018-07-25 Alan Modra <amodra@gmail.com>
+
* elf32-arm.c (elf32_arm_nabi_write_core_note): Disable
-Wstringop-truncation warning for gcc-8.0 too.
* elf32-ppc.c (ppc_elf_write_core_note): Likewise.
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index 1ddfc6c1..c289eeb 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -7386,12 +7386,10 @@ ppc_elf_relax_section (bfd *abfd,
{
if (tsec != NULL)
;
- else if (isym->st_shndx == SHN_UNDEF)
- tsec = bfd_und_section_ptr;
else if (isym->st_shndx == SHN_ABS)
tsec = bfd_abs_section_ptr;
- else if (isym->st_shndx == SHN_COMMON)
- tsec = bfd_com_section_ptr;
+ else
+ continue;
toff = isym->st_value;
sym_type = ELF_ST_TYPE (isym->st_info);
@@ -7533,6 +7531,17 @@ ppc_elf_relax_section (bfd *abfd,
if (tsec == isec)
continue;
+ /* toff is used for the symbol index when the symbol is
+ undefined and we're doing a relocatable link, so we can't
+ support addends. It would be possible to do so by
+ putting the addend in one_branch_fixup but addends on
+ branches are rare so it hardly seems worth supporting. */
+ if (bfd_link_relocatable (link_info)
+ && tsec == bfd_und_section_ptr
+ && r_type != R_PPC_PLTREL24
+ && irel->r_addend != 0)
+ continue;
+
/* There probably isn't any reason to handle symbols in
SEC_MERGE sections; SEC_MERGE doesn't seem a likely
attribute for a code section, and we are only looking at
@@ -7556,7 +7565,8 @@ ppc_elf_relax_section (bfd *abfd,
a section symbol should not include the addend; Such an
access is presumed to be an offset from "sym"; The
location of interest is just "sym". */
- if (sym_type == STT_SECTION)
+ if (sym_type == STT_SECTION
+ && r_type != R_PPC_PLTREL24)
toff += irel->r_addend;
toff
@@ -7564,7 +7574,8 @@ ppc_elf_relax_section (bfd *abfd,
elf_section_data (tsec)->sec_info,
toff);
- if (sym_type != STT_SECTION)
+ if (sym_type != STT_SECTION
+ && r_type != R_PPC_PLTREL24)
toff += irel->r_addend;
}
/* PLTREL24 addends are special. */
@@ -7581,6 +7592,16 @@ ppc_elf_relax_section (bfd *abfd,
roff = irel->r_offset;
+ /* Avoid creating a lot of unnecessary fixups when
+ relocatable if the output section size is such that a
+ fixup can be created at final link.
+ The max_branch_offset adjustment allows for some number
+ of other fixups being needed at final link. */
+ if (bfd_link_relocatable (link_info)
+ && (isec->output_section->rawsize - (isec->output_offset + roff)
+ < max_branch_offset - (max_branch_offset >> 4)))
+ continue;
+
/* If the branch is in range, no need to do anything. */
if (tsec != bfd_und_section_ptr
&& (!bfd_link_relocatable (link_info)