binutils/

* readelf.c (debug_apply_rela_addends): New function, extracted from..
	(display_debug_info): ..here.
	(display_debug_frames): Call debug_apply_rela_addends.  Don't do
	DW_EH_PE_pcrel adjustment for ET_REL.
gas/testsuite/
	* gas/cfi/cfi-alpha-1.d: Adjust for readelf fix.
	* gas/cfi/cfi-alpha-3.d: Likewise.
	* gas/cfi/cfi-i386.d: Likewise.
	* gas/cfi/cfi-m68k.d: Likewise.
	* gas/cfi/cfi-ppc-1.d: Likewise.
	* gas/cfi/cfi-s390-1.d: Likewise.
	* gas/cfi/cfi-s390x-1.d: Likewise.
	* gas/cfi/cfi-sh-1.d: Likewise.
	* gas/cfi/cfi-sparc-1.d: Likewise.
	* gas/cfi/cfi-sparc64-1.d: Likewise.
	* gas/cfi/cfi-x86_64.d: Likewise.
This commit is contained in:
Alan Modra 2004-08-16 00:09:20 +00:00
parent 2a80c17810
commit d84de024e6
14 changed files with 181 additions and 130 deletions

View File

@ -1,3 +1,10 @@
2004-08-16 Alan Modra <amodra@bigpond.net.au>
* readelf.c (debug_apply_rela_addends): New function, extracted from..
(display_debug_info): ..here.
(display_debug_frames): Call debug_apply_rela_addends. Don't do
DW_EH_PE_pcrel adjustment for ET_REL.
2004-08-06 Andreas Schwab <schwab@suse.de>
* readelf.c (dump_relocations): Fix typo when calculating

View File

@ -8506,6 +8506,88 @@ read_and_display_attr (unsigned long attribute,
return data;
}
/* Apply addends of RELA relocations. */
static int
debug_apply_rela_addends (FILE *file,
Elf_Internal_Shdr *section,
int reloc_size,
unsigned char *sec_data,
unsigned char *start,
unsigned char *end)
{
Elf_Internal_Shdr *relsec;
if (end - start < reloc_size)
return 1;
for (relsec = section_headers;
relsec < section_headers + elf_header.e_shnum;
++relsec)
{
unsigned long nrelas;
Elf_Internal_Rela *rela, *rp;
Elf_Internal_Shdr *symsec;
Elf_Internal_Sym *symtab;
Elf_Internal_Sym *sym;
if (relsec->sh_type != SHT_RELA
|| SECTION_HEADER (relsec->sh_info) != section
|| relsec->sh_size == 0)
continue;
if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
&rela, &nrelas))
return 0;
symsec = SECTION_HEADER (relsec->sh_link);
symtab = GET_ELF_SYMBOLS (file, symsec);
for (rp = rela; rp < rela + nrelas; ++rp)
{
unsigned char *loc;
if (rp->r_offset >= (bfd_vma) (start - sec_data)
&& rp->r_offset < (bfd_vma) (end - sec_data) - reloc_size)
loc = sec_data + rp->r_offset;
else
continue;
if (is_32bit_elf)
{
sym = symtab + ELF32_R_SYM (rp->r_info);
if (ELF32_R_SYM (rp->r_info) != 0
&& ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
{
warn (_("Skipping unexpected symbol type %u\n"),
ELF32_ST_TYPE (sym->st_info));
continue;
}
}
else
{
sym = symtab + ELF64_R_SYM (rp->r_info);
if (ELF64_R_SYM (rp->r_info) != 0
&& ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
{
warn (_("Skipping unexpected symbol type %u\n"),
ELF64_ST_TYPE (sym->st_info));
continue;
}
}
byte_put (loc, rp->r_addend, reloc_size);
}
free (symtab);
free (rela);
break;
}
return 1;
}
static int
display_debug_info (Elf_Internal_Shdr *section,
unsigned char *start,
@ -8522,7 +8604,6 @@ display_debug_info (Elf_Internal_Shdr *section,
while (start < end)
{
DWARF2_Internal_CompUnit compunit;
Elf_Internal_Shdr *relsec;
unsigned char *hdrptr;
unsigned char *cu_abbrev_offset_ptr;
unsigned char *tags;
@ -8552,71 +8633,13 @@ display_debug_info (Elf_Internal_Shdr *section,
compunit.cu_version = byte_get (hdrptr, 2);
hdrptr += 2;
/* Apply addends of RELA relocations. */
for (relsec = section_headers;
relsec < section_headers + elf_header.e_shnum;
++relsec)
{
unsigned long nrelas;
Elf_Internal_Rela *rela, *rp;
Elf_Internal_Shdr *symsec;
Elf_Internal_Sym *symtab;
Elf_Internal_Sym *sym;
cu_offset = start - section_begin;
start += compunit.cu_length + initial_length_size;
if (relsec->sh_type != SHT_RELA
|| SECTION_HEADER (relsec->sh_info) != section
|| relsec->sh_size == 0)
continue;
if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
& rela, & nrelas))
return 0;
symsec = SECTION_HEADER (relsec->sh_link);
symtab = GET_ELF_SYMBOLS (file, symsec);
for (rp = rela; rp < rela + nrelas; ++rp)
{
unsigned char *loc;
if (rp->r_offset >= (bfd_vma) (hdrptr - section_begin)
&& section->sh_size > (bfd_vma) offset_size
&& rp->r_offset <= section->sh_size - offset_size)
loc = section_begin + rp->r_offset;
else
continue;
if (is_32bit_elf)
{
sym = symtab + ELF32_R_SYM (rp->r_info);
if (ELF32_R_SYM (rp->r_info) != 0
&& ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
{
warn (_("Skipping unexpected symbol type %u\n"),
ELF32_ST_TYPE (sym->st_info));
continue;
}
}
else
{
sym = symtab + ELF64_R_SYM (rp->r_info);
if (ELF64_R_SYM (rp->r_info) != 0
&& ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
{
warn (_("Skipping unexpected symbol type %u\n"),
ELF64_ST_TYPE (sym->st_info));
continue;
}
}
byte_put (loc, rp->r_addend, offset_size);
}
free (rela);
break;
}
if (elf_header.e_type == ET_REL
&& !debug_apply_rela_addends (file, section, offset_size,
section_begin, hdrptr, start))
return 0;
cu_abbrev_offset_ptr = hdrptr;
compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
@ -8626,8 +8649,6 @@ display_debug_info (Elf_Internal_Shdr *section,
hdrptr += 1;
tags = hdrptr;
cu_offset = start - section_begin;
start += compunit.cu_length + initial_length_size;
printf (_(" Compilation Unit @ %lx:\n"), cu_offset);
printf (_(" Length: %ld\n"), compunit.cu_length);
@ -9017,6 +9038,11 @@ display_debug_frames (Elf_Internal_Shdr *section,
block_end = saved_start + length + initial_length_size;
cie_id = byte_get (start, offset_size); start += offset_size;
if (elf_header.e_type == ET_REL
&& !debug_apply_rela_addends (file, section, offset_size,
section_start, start, block_end))
return 0;
if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
{
int version;
@ -9181,7 +9207,10 @@ display_debug_frames (Elf_Internal_Shdr *section,
encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
fc->pc_begin = get_encoded_value (start, fc->fde_encoding);
if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel
/* Don't adjust for ET_REL since there's invariably a pcrel
reloc here, which we haven't applied. */
&& elf_header.e_type != ET_REL)
fc->pc_begin += section->sh_addr + (start - section_start);
start += encoded_ptr_size;
fc->pc_range = byte_get (start, encoded_ptr_size);
@ -9380,7 +9409,8 @@ display_debug_frames (Elf_Internal_Shdr *section,
case DW_CFA_set_loc:
vma = get_encoded_value (start, fc->fde_encoding);
if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel
&& elf_header.e_type != ET_REL)
vma += section->sh_addr + (start - section_start);
start += encoded_ptr_size;
if (do_debug_frames_interp)

View File

@ -1,3 +1,17 @@
2004-08-16 Alan Modra <amodra@bigpond.net.au>
* gas/cfi/cfi-alpha-1.d: Adjust for readelf fix.
* gas/cfi/cfi-alpha-3.d: Likewise.
* gas/cfi/cfi-i386.d: Likewise.
* gas/cfi/cfi-m68k.d: Likewise.
* gas/cfi/cfi-ppc-1.d: Likewise.
* gas/cfi/cfi-s390-1.d: Likewise.
* gas/cfi/cfi-s390x-1.d: Likewise.
* gas/cfi/cfi-sh-1.d: Likewise.
* gas/cfi/cfi-sparc-1.d: Likewise.
* gas/cfi/cfi-sparc64-1.d: Likewise.
* gas/cfi/cfi-x86_64.d: Likewise.
2004-08-13 Jan Beulich <jbeulich@novell.com>
* gas/all/altmacro.[sd]: New test.

View File

@ -13,8 +13,8 @@ The section .eh_frame contains:
DW_CFA_def_cfa_reg: r30
DW_CFA_nop
00000014 00000020 00000018 FDE cie=00000000 pc=0000001c..00000050
DW_CFA_advance_loc: 24 to 00000034
00000014 00000020 00000018 FDE cie=00000000 pc=00000000..00000034
DW_CFA_advance_loc: 24 to 00000018
DW_CFA_def_cfa: r15 ofs 32
DW_CFA_offset: r26 at cfa-32
DW_CFA_offset: r9 at cfa-24

View File

@ -13,20 +13,20 @@ The section .eh_frame contains:
DW_CFA_def_cfa_reg: r30
DW_CFA_nop
00000014 00000028 00000018 FDE cie=00000000 pc=0000001c..0000005c
DW_CFA_advance_loc: 4 to 00000020
00000014 00000028 00000018 FDE cie=00000000 pc=00000000..00000040
DW_CFA_advance_loc: 4 to 00000004
DW_CFA_def_cfa_offset: 32
DW_CFA_advance_loc: 4 to 00000024
DW_CFA_advance_loc: 4 to 00000008
DW_CFA_offset: r26 at cfa-32
DW_CFA_advance_loc: 4 to 00000028
DW_CFA_advance_loc: 4 to 0000000c
DW_CFA_offset: r9 at cfa-24
DW_CFA_advance_loc: 4 to 0000002c
DW_CFA_advance_loc: 4 to 00000010
DW_CFA_offset: r15 at cfa-16
DW_CFA_advance_loc: 4 to 00000030
DW_CFA_advance_loc: 4 to 00000014
DW_CFA_offset: r34 at cfa-8
DW_CFA_advance_loc: 4 to 00000034
DW_CFA_advance_loc: 4 to 00000018
DW_CFA_def_cfa_reg: r15
DW_CFA_advance_loc: 36 to 00000058
DW_CFA_advance_loc: 36 to 0000003c
DW_CFA_def_cfa: r30 ofs 0
DW_CFA_nop
DW_CFA_nop

View File

@ -15,33 +15,33 @@ The section .eh_frame contains:
DW_CFA_nop
DW_CFA_nop
00000018 00000014 0000001c FDE cie=00000000 pc=00000020..00000032
DW_CFA_advance_loc: 6 to 00000026
00000018 00000014 0000001c FDE cie=00000000 pc=00000000..00000012
DW_CFA_advance_loc: 6 to 00000006
DW_CFA_def_cfa_offset: 4664
DW_CFA_advance_loc: 11 to 00000031
DW_CFA_advance_loc: 11 to 00000011
DW_CFA_def_cfa_offset: 4
00000030 00000018 00000034 FDE cie=00000000 pc=0000004a..00000057
DW_CFA_advance_loc: 1 to 0000004b
00000030 00000018 00000034 FDE cie=00000000 pc=00000012..0000001f
DW_CFA_advance_loc: 1 to 00000013
DW_CFA_def_cfa_offset: 8
DW_CFA_offset: r5 at cfa-8
DW_CFA_advance_loc: 2 to 0000004d
DW_CFA_advance_loc: 2 to 00000015
DW_CFA_def_cfa_reg: r5
DW_CFA_advance_loc: 9 to 00000056
DW_CFA_advance_loc: 9 to 0000001e
DW_CFA_def_cfa_reg: r4
0000004c 00000014 00000050 FDE cie=00000000 pc=00000073..00000083
DW_CFA_advance_loc: 2 to 00000075
0000004c 00000014 00000050 FDE cie=00000000 pc=0000001f..0000002f
DW_CFA_advance_loc: 2 to 00000021
DW_CFA_def_cfa_reg: r3
DW_CFA_advance_loc: 13 to 00000082
DW_CFA_advance_loc: 13 to 0000002e
DW_CFA_def_cfa: r4 ofs 4
00000064 00000010 00000068 FDE cie=00000000 pc=0000009b..000000a1
00000064 00000010 00000068 FDE cie=00000000 pc=0000002f..00000035
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
00000078 00000010 0000007c FDE cie=00000000 pc=000000b5..000000c4
00000078 00000010 0000007c FDE cie=00000000 pc=00000035..00000044
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop

View File

@ -15,22 +15,22 @@ The section .eh_frame contains:
DW_CFA_nop
DW_CFA_nop
00000018 00000014 0000001c FDE cie=00000000 pc=00000020..0000002c
DW_CFA_advance_loc: 4 to 00000024
00000018 00000014 0000001c FDE cie=00000000 pc=00000000..0000000c
DW_CFA_advance_loc: 4 to 00000004
DW_CFA_def_cfa_offset: 4664
DW_CFA_advance_loc: 6 to 0000002a
DW_CFA_advance_loc: 6 to 0000000a
DW_CFA_def_cfa_offset: 4
00000030 00000018 00000034 FDE cie=00000000 pc=00000038..00000044
DW_CFA_advance_loc: 4 to 0000003c
00000030 00000018 00000034 FDE cie=00000000 pc=0000000c..00000018
DW_CFA_advance_loc: 4 to 00000010
DW_CFA_def_cfa_offset: 8
DW_CFA_offset: r14 at cfa-8
DW_CFA_def_cfa_reg: r14
DW_CFA_advance_loc: 6 to 00000042
DW_CFA_advance_loc: 6 to 00000016
DW_CFA_def_cfa_reg: r15
DW_CFA_nop
0000004c 00000010 00000050 FDE cie=00000000 pc=00000054..00000058
0000004c 00000010 00000050 FDE cie=00000000 pc=00000018..0000001c
DW_CFA_nop
DW_CFA_nop

View File

@ -14,16 +14,16 @@ The section .eh_frame contains:
DW_CFA_def_cfa: r1 ofs 0
00000014 00000020 00000018 FDE cie=00000000 pc=0000001c..0000008c
DW_CFA_advance_loc: 4 to 00000020
00000014 00000020 00000018 FDE cie=00000000 pc=00000000..00000070
DW_CFA_advance_loc: 4 to 00000004
DW_CFA_def_cfa_offset: 48
DW_CFA_advance_loc: 16 to 00000030
DW_CFA_advance_loc: 16 to 00000014
DW_CFA_offset: r27 at cfa-20
DW_CFA_offset: r26 at cfa-24
DW_CFA_offset_extended_sf: r65 at cfa\+4
DW_CFA_advance_loc: 8 to 00000038
DW_CFA_advance_loc: 8 to 0000001c
DW_CFA_offset: r28 at cfa-16
DW_CFA_advance_loc: 8 to 00000040
DW_CFA_advance_loc: 8 to 00000024
DW_CFA_offset: r29 at cfa-12
DW_CFA_nop
DW_CFA_nop

View File

@ -14,8 +14,8 @@ The section .eh_frame contains:
DW_CFA_def_cfa: r15 ofs 96
00000014 00000024 00000018 FDE cie=00000000 pc=0000001c..0000006a
DW_CFA_advance_loc: 4 to 00000020
00000014 00000024 00000018 FDE cie=00000000 pc=00000000..0000004e
DW_CFA_advance_loc: 4 to 00000004
DW_CFA_offset: r15 at cfa-36
DW_CFA_offset: r14 at cfa-40
DW_CFA_offset: r13 at cfa-44
@ -24,7 +24,7 @@ The section .eh_frame contains:
DW_CFA_offset: r10 at cfa-56
DW_CFA_offset: r9 at cfa-60
DW_CFA_offset: r8 at cfa-64
DW_CFA_advance_loc: 22 to 00000036
DW_CFA_advance_loc: 22 to 0000001a
DW_CFA_def_cfa_offset: 192
DW_CFA_nop
DW_CFA_nop

View File

@ -17,8 +17,8 @@ The section .eh_frame contains:
DW_CFA_nop
DW_CFA_nop
00000018 00000024 0000001c FDE cie=00000000 pc=00000020..00000090
DW_CFA_advance_loc: 6 to 00000026
00000018 00000024 0000001c FDE cie=00000000 pc=00000000..00000070
DW_CFA_advance_loc: 6 to 00000006
DW_CFA_offset: r15 at cfa-40
DW_CFA_offset: r14 at cfa-48
DW_CFA_offset: r13 at cfa-56
@ -27,7 +27,7 @@ The section .eh_frame contains:
DW_CFA_offset: r10 at cfa-80
DW_CFA_offset: r9 at cfa-88
DW_CFA_offset: r8 at cfa-96
DW_CFA_advance_loc: 8 to 0000002e
DW_CFA_advance_loc: 8 to 0000000e
DW_CFA_def_cfa_offset: 320
DW_CFA_nop
DW_CFA_nop

View File

@ -12,16 +12,16 @@ The section .eh_frame contains:
DW_CFA_def_cfa: r15 ofs 0
00000014 00000020 00000018 FDE cie=00000000 pc=0000001c..00000048
DW_CFA_advance_loc: 2 to 0000001e
00000014 00000020 00000018 FDE cie=00000000 pc=00000000..0000002c
DW_CFA_advance_loc: 2 to 00000002
DW_CFA_def_cfa_offset: 4
DW_CFA_advance_loc: 2 to 00000020
DW_CFA_advance_loc: 2 to 00000004
DW_CFA_def_cfa_offset: 8
DW_CFA_offset: r15 at cfa-4
DW_CFA_offset: r17 at cfa-8
DW_CFA_advance_loc: 6 to 00000026
DW_CFA_advance_loc: 6 to 0000000a
DW_CFA_def_cfa_reg: r14
DW_CFA_advance_loc: 2 to 00000028
DW_CFA_advance_loc: 2 to 0000000c
DW_CFA_def_cfa_offset: 40
DW_CFA_nop
DW_CFA_nop

View File

@ -14,8 +14,8 @@ The section .eh_frame contains:
DW_CFA_def_cfa: r14 ofs 0
00000014 00000014 00000018 FDE cie=00000000 pc=0000001c..00000040
DW_CFA_advance_loc: 4 to 00000020
00000014 00000014 00000018 FDE cie=00000000 pc=00000000..00000024
DW_CFA_advance_loc: 4 to 00000004
DW_CFA_def_cfa_reg: r30
DW_CFA_GNU_window_save
DW_CFA_register: r15 in r31

View File

@ -17,8 +17,8 @@ The section .eh_frame contains:
DW_CFA_nop
DW_CFA_nop
00000018 00000014 0000001c FDE cie=00000000 pc=00000020..00000050
DW_CFA_advance_loc: 4 to 00000024
00000018 00000014 0000001c FDE cie=00000000 pc=00000000..00000030
DW_CFA_advance_loc: 4 to 00000004
DW_CFA_def_cfa_reg: r30
DW_CFA_GNU_window_save
DW_CFA_register: r15 in r31

View File

@ -15,37 +15,37 @@ The section .eh_frame contains:
DW_CFA_nop
DW_CFA_nop
00000018 00000014 0000001c FDE cie=00000000 pc=00000020..00000034
DW_CFA_advance_loc: 7 to 00000027
00000018 00000014 0000001c FDE cie=00000000 pc=00000000..00000014
DW_CFA_advance_loc: 7 to 00000007
DW_CFA_def_cfa_offset: 4668
DW_CFA_advance_loc: 12 to 00000033
DW_CFA_advance_loc: 12 to 00000013
DW_CFA_def_cfa_offset: 8
00000030 0000001c 00000034 FDE cie=00000000 pc=00000038..00000046
DW_CFA_advance_loc: 1 to 00000039
00000030 0000001c 00000034 FDE cie=00000000 pc=00000014..00000022
DW_CFA_advance_loc: 1 to 00000015
DW_CFA_def_cfa_offset: 16
DW_CFA_offset: r6 at cfa-16
DW_CFA_advance_loc: 3 to 0000003c
DW_CFA_advance_loc: 3 to 00000018
DW_CFA_def_cfa_reg: r6
DW_CFA_advance_loc: 9 to 00000045
DW_CFA_advance_loc: 9 to 00000021
DW_CFA_def_cfa: r7 ofs 8
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
00000050 00000014 00000054 FDE cie=00000000 pc=00000058..0000006b
DW_CFA_advance_loc: 3 to 0000005b
00000050 00000014 00000054 FDE cie=00000000 pc=00000022..00000035
DW_CFA_advance_loc: 3 to 00000025
DW_CFA_def_cfa_reg: r12
DW_CFA_advance_loc: 15 to 0000006a
DW_CFA_advance_loc: 15 to 00000034
DW_CFA_def_cfa_reg: r7
DW_CFA_nop
00000068 00000010 0000006c FDE cie=00000000 pc=00000070..00000076
00000068 00000010 0000006c FDE cie=00000000 pc=00000035..0000003b
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
0000007c 00000010 00000080 FDE cie=00000000 pc=00000084..00000096
0000007c 00000010 00000080 FDE cie=00000000 pc=0000003b..0000004d
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop