This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: gc-sections and DWARF ranges
On Fri, Oct 22, 2010 at 10:04:39AM +1030, Alan Modra wrote:
> On Thu, Oct 21, 2010 at 05:41:00PM -0400, Daniel Jacobowitz wrote:
> > Is there any provision in GNU ld for this that I'm not seeing?
>
> Not that I know of.
What's your opinion of a flat-out hack then? This would need an
update to other targets, but it works for x86_64.
--
Daniel Jacobowitz
CodeSourcery
2010-10-21 Daniel Jacobowitz <dan@codesourcery.com>
* elf-bfd.h (RELOC_AGAINST_DISCARDED_SECTION): Always call
_bfd_clear_contents. Pass it the input section.
* elf32-arm.c (elf32_arm_relocate_section): Use
RELOC_AGAINST_DISCARDED_SECTION.
* libbfd-in.h (_bfd_clear_contents): Add input_section argument.
* libbfd.h: Regenerate.
* reloc.c (_bfd_clear_contents): Take input_section argument.
Use non-zero for .debug_ranges.
(bfd_generic_get_relocated_section_conten): Update _bfd_clear_contents
call.
Index: elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.311
diff -u -p -r1.311 elf-bfd.h
--- elf-bfd.h 21 Oct 2010 12:29:01 -0000 1.311
+++ elf-bfd.h 22 Oct 2010 02:32:50 -0000
@@ -2355,6 +2355,9 @@ extern asection _bfd_elf_large_com_secti
#define RELOC_AGAINST_DISCARDED_SECTION(info, input_bfd, input_section, \
rel, relend, howto, contents) \
{ \
+ _bfd_clear_contents (howto, input_bfd, input_section, \
+ contents + rel->r_offset); \
+ \
if (info->relocatable \
&& (input_section->flags & SEC_DEBUGGING)) \
{ \
@@ -2380,7 +2383,6 @@ extern asection _bfd_elf_large_com_secti
} \
} \
\
- _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset); \
rel->r_info = 0; \
rel->r_addend = 0; \
continue; \
Index: elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.245
diff -u -p -r1.245 elf32-arm.c
--- elf32-arm.c 11 Oct 2010 07:38:53 -0000 1.245
+++ elf32-arm.c 22 Oct 2010 02:32:50 -0000
@@ -9033,15 +9033,8 @@ elf32_arm_relocate_section (bfd *
}
if (sec != NULL && elf_discarded_section (sec))
- {
- /* For relocs against symbols from removed linkonce sections,
- or sections discarded by a linker script, we just want the
- section contents zeroed. Avoid any special processing. */
- _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
- rel->r_info = 0;
- rel->r_addend = 0;
- continue;
- }
+ RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
+ rel, relend, howto, contents);
if (info->relocatable)
{
Index: libbfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd-in.h,v
retrieving revision 1.84
diff -u -p -r1.84 libbfd-in.h
--- libbfd-in.h 18 Aug 2010 12:24:07 -0000 1.84
+++ libbfd-in.h 22 Oct 2010 02:32:50 -0000
@@ -628,7 +628,7 @@ extern bfd_reloc_status_type _bfd_reloca
/* Clear a given location using a given howto. */
extern void _bfd_clear_contents (reloc_howto_type *howto, bfd *input_bfd,
- bfd_byte *location);
+ asection *input_section, bfd_byte *location);
/* Link stabs in sections in the first pass. */
Index: libbfd.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd.h,v
retrieving revision 1.240
diff -u -p -r1.240 libbfd.h
--- libbfd.h 8 Oct 2010 22:34:37 -0000 1.240
+++ libbfd.h 22 Oct 2010 02:32:50 -0000
@@ -633,7 +633,7 @@ extern bfd_reloc_status_type _bfd_reloca
/* Clear a given location using a given howto. */
extern void _bfd_clear_contents (reloc_howto_type *howto, bfd *input_bfd,
- bfd_byte *location);
+ asection *input_section, bfd_byte *location);
/* Link stabs in sections in the first pass. */
Index: reloc.c
===================================================================
RCS file: /cvs/src/src/bfd/reloc.c,v
retrieving revision 1.206
diff -u -p -r1.206 reloc.c
--- reloc.c 8 Oct 2010 22:34:37 -0000 1.206
+++ reloc.c 22 Oct 2010 02:32:50 -0000
@@ -1544,14 +1544,15 @@ _bfd_relocate_contents (reloc_howto_type
return flag;
}
-/* Clear a given location using a given howto, by applying a relocation value
- of zero and discarding any in-place addend. This is used for fixed-up
+/* Clear a given location using a given howto, by applying a fixed relocation
+ value and discarding any in-place addend. This is used for fixed-up
relocations against discarded symbols, to make ignorable debug or unwind
information more obvious. */
void
_bfd_clear_contents (reloc_howto_type *howto,
bfd *input_bfd,
+ asection *input_section,
bfd_byte *location)
{
int size;
@@ -1585,6 +1586,13 @@ _bfd_clear_contents (reloc_howto_type *h
/* Zero out the unwanted bits of X. */
x &= ~howto->dst_mask;
+ /* For a range list, use 1 instead of 0 as placeholder. 0
+ terminates the list. */
+ if (strcmp (bfd_get_section_name (input_bfd, input_section),
+ ".debug_ranges") == 0
+ && (howto->dst_mask & 1) != 0)
+ x |= 1;
+
/* Put the relocated value back in the object file. */
switch (size)
{
@@ -5756,7 +5764,8 @@ bfd_generic_get_relocated_section_conten
"unused", FALSE, 0, 0, FALSE);
p = data + (*parent)->address * bfd_octets_per_byte (input_bfd);
- _bfd_clear_contents ((*parent)->howto, input_bfd, p);
+ _bfd_clear_contents ((*parent)->howto, input_bfd, input_section,
+ p);
(*parent)->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
(*parent)->addend = 0;
(*parent)->howto = &none_howto;