* [ARM] Relocation counting during gc sweep
@ 2010-12-14 16:02 Richard Sandiford
2011-07-01 14:26 ` Nick Clifton
0 siblings, 1 reply; 2+ messages in thread
From: Richard Sandiford @ 2010-12-14 16:02 UTC (permalink / raw)
To: binutils; +Cc: Nick Clifton, Richard Earnshaw, Paul Brook
This patch fixes a problem I saw while working on the STT_GNU_IFUNC support.
We can record dynamic relocs for quite a wide range of relocations:
case R_ARM_MOVW_ABS_NC:
case R_ARM_MOVT_ABS:
case R_ARM_THM_MOVW_ABS_NC:
case R_ARM_THM_MOVT_ABS:
[...]
case R_ARM_ABS32:
case R_ARM_ABS32_NOI:
case R_ARM_REL32:
case R_ARM_REL32_NOI:
case R_ARM_MOVW_PREL_NC:
case R_ARM_MOVT_PREL:
case R_ARM_THM_MOVW_PREL_NC:
case R_ARM_THM_MOVT_PREL:
(from elf32_arm_check_relocs) but we only sweep them for four:
if (r_type == R_ARM_ABS32
|| r_type == R_ARM_REL32
|| r_type == R_ARM_ABS32_NOI
|| r_type == R_ARM_REL32_NOI)
for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
if (p->sec == sec)
{
p->count -= 1;
if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
|| ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
p->pc_count -= 1;
if (p->count == 0)
*pp = p->next;
break;
}
This means that, for the attached testcase, we end up with two R_ARM_NONE
relocations for the discarded .text.foo.
Because we're discarding the whole section, it ought to be safe to remove
sec's entry unconditionally. The patch does that by stealing from
elf32-ppc.c.
Tested on arm-linux-gnueabi and arm-eabi. OK to install?
Richard
bfd/
* elf32-arm.c (elf32_arm_gc_sweep_hook): Remove all registered
dynamic relocs for the removed section.
ld/testsuite/
* ld-arm/gc-thumb-lib.s, ld-arm/gc-thumb.s,
ld-arm/gc-thumb.d: New test.
* ld-arm/arm-elf.exp: Run it.
Index: bfd/elf32-arm.c
===================================================================
--- bfd/elf32-arm.c 2010-12-14 15:30:05.000000000 +0000
+++ bfd/elf32-arm.c 2010-12-14 15:34:35.000000000 +0000
@@ -10678,21 +10678,13 @@ elf32_arm_gc_sweep_hook (bfd *
eh->plt_thumb_refcount--;
}
- if (r_type == R_ARM_ABS32
- || r_type == R_ARM_REL32
- || r_type == R_ARM_ABS32_NOI
- || r_type == R_ARM_REL32_NOI)
- for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
- if (p->sec == sec)
- {
- p->count -= 1;
- if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
- || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
- p->pc_count -= 1;
- if (p->count == 0)
- *pp = p->next;
- break;
- }
+ for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
+ if (p->sec == sec)
+ {
+ /* Everything must go for SEC. */
+ *pp = p->next;
+ break;
+ }
}
break;
Index: ld/testsuite/ld-arm/gc-thumb-lib.s
===================================================================
--- /dev/null 2010-12-14 12:47:12.274544604 +0000
+++ ld/testsuite/ld-arm/gc-thumb-lib.s 2010-12-14 15:34:35.000000000 +0000
@@ -0,0 +1,6 @@
+ .data
+ .globl foo
+ .type foo,%object
+ .size foo,4
+foo:
+ .word 0
Index: ld/testsuite/ld-arm/gc-thumb.s
===================================================================
--- /dev/null 2010-12-14 12:47:12.274544604 +0000
+++ ld/testsuite/ld-arm/gc-thumb.s 2010-12-14 15:41:29.000000000 +0000
@@ -0,0 +1,11 @@
+ .arch armv7-a
+ .syntax unified
+ .text
+ .globl _start
+_start:
+ mov pc,lr
+
+ .section .text.foo,"ax",%progbits
+ .thumb
+ movw r0,#:lower16:foo-.
+ movt r0,#:upper16:foo-.
Index: ld/testsuite/ld-arm/gc-thumb.d
===================================================================
--- /dev/null 2010-12-14 12:47:12.274544604 +0000
+++ ld/testsuite/ld-arm/gc-thumb.d 2010-12-14 15:34:35.000000000 +0000
@@ -0,0 +1,2 @@
+
+There are no relocations in this file\.
Index: ld/testsuite/ld-arm/arm-elf.exp
===================================================================
--- ld/testsuite/ld-arm/arm-elf.exp 2010-12-14 15:30:05.000000000 +0000
+++ ld/testsuite/ld-arm/arm-elf.exp 2010-12-14 15:34:35.000000000 +0000
@@ -228,6 +228,12 @@ set armelftests {
{"Unwinding and -gc-sections" "-gc-sections" "" {gc-unwind.s}
{{objdump -sj.data gc-unwind.d}}
"gc-unwind"}
+ {"Thumb and -gc-sections" "-shared -T arm-dyn.ld" "" {gc-thumb-lib.s}
+ {}
+ "gc-thumb-lib.so"}
+ {"Thumb and -gc-sections" "-pie -T arm.ld -gc-sections tmpdir/gc-thumb-lib.so" "" {gc-thumb.s}
+ {{readelf --relocs gc-thumb.d}}
+ "gc-thumb"}
{"arm-pic-veneer" "-static -T arm.ld --pic-veneer" "" {arm-pic-veneer.s}
{{objdump -d arm-pic-veneer.d}}
"arm-pic-veneer"}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [ARM] Relocation counting during gc sweep
2010-12-14 16:02 [ARM] Relocation counting during gc sweep Richard Sandiford
@ 2011-07-01 14:26 ` Nick Clifton
0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2011-07-01 14:26 UTC (permalink / raw)
To: binutils, Richard Earnshaw, Paul Brook, richard.sandiford
Hi Richard,
> bfd/
> * elf32-arm.c (elf32_arm_gc_sweep_hook): Remove all registered
> dynamic relocs for the removed section.
>
> ld/testsuite/
> * ld-arm/gc-thumb-lib.s, ld-arm/gc-thumb.s,
> ld-arm/gc-thumb.d: New test.
> * ld-arm/arm-elf.exp: Run it.
Approved - please apply.
Cheers
Nick
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-07-01 14:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-14 16:02 [ARM] Relocation counting during gc sweep Richard Sandiford
2011-07-01 14:26 ` Nick Clifton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).