ld/x86: Add -z report-relative-reloc
Linker generated relative relocations don't have symbol info: [hjl@gnu-cfl-2 tmpdir]$ readelf -rW dump Relocation section '.rela.dyn' at offset 0x180 contains 2 entries: Offset Info Type Sym. Value Symbol's Name + Addend 00002f70 00000008 R_X86_64_RELATIVE 1000 00002f68 00000025 R_X86_64_IRELATIVE 1007 [hjl@gnu-cfl-2 tmpdir]$ Add -z report-relative-reloc to x86 ELF linker to report dynamic relative relocations: [hjl@gnu-cfl-2 tmpdir]$ ../ld-new -pie -melf32_x86_64 -z report-relative-reloc -o dump report-reloc-1.o dump: R_X86_64_IRELATIVE (offset: 0x00002f68, info: 0x00000025, addend: 0x00001007) against 'ifunc' for section '.data.rel.ro.local' in report-reloc-1.o dump: R_X86_64_RELATIVE (offset: 0x00002f70, info: 0x00000008, addend: 0x00001000) against '_start' for section '.data.rel.ro.local' in report-reloc-1.o [hjl@gnu-cfl-2 tmpdir]$ It can be used to map relative relocations to corresponding symbols. bfd/ * elf-linker-x86.h (elf_linker_x86_params): Add report_relative_reloc. * elf32-i386.c (elf_i386_relocate_section): Call _bfd_x86_elf_link_report_relative_reloc to report relative relocations for -z report-relative-reloc. (elf_i386_finish_dynamic_symbol): Likewse. * elf64-x86-64.c (elf_x86_64_relocate_section): Likewse. (elf_x86_64_finish_dynamic_symbol): Likewse. * elfxx-x86.c (_bfd_x86_elf_link_report_relative_reloc): New function. * elfxx-x86.h (_bfd_x86_elf_link_report_relative_reloc): New prototype. ld/ * NEWS: Mention -z report-relative-reloc. * ld.texi: Document -z report-relative-reloc. * emulparams/elf32_x86_64.sh: Source x86-report-relative.sh. * emulparams/elf_i386.sh: Likewse. * emulparams/elf_x86_64.sh: Likewse. * emulparams/x86-report-relative.sh: New file. * testsuite/ld-i386/report-reloc-1.d: Likewse. * testsuite/ld-i386/report-reloc-1.l: Likewse. * testsuite/ld-i386/report-reloc-1.s: Likewse. * testsuite/ld-x86-64/report-reloc-1-x32.d: Likewse. * testsuite/ld-x86-64/report-reloc-1.d: Likewse. * testsuite/ld-x86-64/report-reloc-1.l: Likewse. * testsuite/ld-x86-64/report-reloc-1.s: Likewse. * testsuite/ld-i386/i386.exp: Run report-reloc-1. * testsuite/ld-x86-64/x86-64.exp: Run report-reloc-1 and report-reloc-1-x32.
This commit is contained in:
parent
ad92f33d38
commit
68b007788a
@ -1,3 +1,18 @@
|
|||||||
|
2021-01-15 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
|
* elf-linker-x86.h (elf_linker_x86_params): Add
|
||||||
|
report_relative_reloc.
|
||||||
|
* elf32-i386.c (elf_i386_relocate_section): Call
|
||||||
|
_bfd_x86_elf_link_report_relative_reloc to report relative
|
||||||
|
relocations for -z report-relative-reloc.
|
||||||
|
(elf_i386_finish_dynamic_symbol): Likewse.
|
||||||
|
* elf64-x86-64.c (elf_x86_64_relocate_section): Likewse.
|
||||||
|
(elf_x86_64_finish_dynamic_symbol): Likewse.
|
||||||
|
* elfxx-x86.c (_bfd_x86_elf_link_report_relative_reloc): New
|
||||||
|
function.
|
||||||
|
* elfxx-x86.h (_bfd_x86_elf_link_report_relative_reloc): New
|
||||||
|
prototype.
|
||||||
|
|
||||||
2021-01-16 Alan Modra <amodra@gmail.com>
|
2021-01-16 Alan Modra <amodra@gmail.com>
|
||||||
|
|
||||||
* compress.c (decompress_contents): Tidy inflateEnd result test.
|
* compress.c (decompress_contents): Tidy inflateEnd result test.
|
||||||
|
@ -61,6 +61,9 @@ struct elf_linker_x86_params
|
|||||||
/* TRUE if --dynamic-linker is passed at command-line. */
|
/* TRUE if --dynamic-linker is passed at command-line. */
|
||||||
unsigned int has_dynamic_linker : 1;
|
unsigned int has_dynamic_linker : 1;
|
||||||
|
|
||||||
|
/* Report relative relocations. */
|
||||||
|
unsigned int report_relative_reloc : 1;
|
||||||
|
|
||||||
/* X86-64 ISA level needed. */
|
/* X86-64 ISA level needed. */
|
||||||
unsigned int isa_level;
|
unsigned int isa_level;
|
||||||
|
|
||||||
|
@ -2409,6 +2409,12 @@ elf_i386_relocate_section (bfd *output_bfd,
|
|||||||
|
|
||||||
/* This symbol is resolved locally. */
|
/* This symbol is resolved locally. */
|
||||||
outrel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
|
outrel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
|
||||||
|
|
||||||
|
if (htab->params->report_relative_reloc)
|
||||||
|
_bfd_x86_elf_link_report_relative_reloc
|
||||||
|
(info, input_section, h, sym,
|
||||||
|
"R_386_IRELATIVE", &outrel);
|
||||||
|
|
||||||
bfd_put_32 (output_bfd,
|
bfd_put_32 (output_bfd,
|
||||||
(h->root.u.def.value
|
(h->root.u.def.value
|
||||||
+ h->root.u.def.section->output_section->vma
|
+ h->root.u.def.section->output_section->vma
|
||||||
@ -2532,6 +2538,12 @@ elf_i386_relocate_section (bfd *output_bfd,
|
|||||||
+ htab->elf.sgot->output_offset
|
+ htab->elf.sgot->output_offset
|
||||||
+ off);
|
+ off);
|
||||||
outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
|
outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
|
||||||
|
|
||||||
|
if (htab->params->report_relative_reloc)
|
||||||
|
_bfd_x86_elf_link_report_relative_reloc
|
||||||
|
(info, input_section, h, sym, "R_386_RELATIVE",
|
||||||
|
&outrel);
|
||||||
|
|
||||||
elf_append_rel (output_bfd, s, &outrel);
|
elf_append_rel (output_bfd, s, &outrel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2738,6 +2750,11 @@ elf_i386_relocate_section (bfd *output_bfd,
|
|||||||
/* This symbol is local, or marked to become local. */
|
/* This symbol is local, or marked to become local. */
|
||||||
relocate = TRUE;
|
relocate = TRUE;
|
||||||
outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
|
outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
|
||||||
|
|
||||||
|
if (htab->params->report_relative_reloc)
|
||||||
|
_bfd_x86_elf_link_report_relative_reloc
|
||||||
|
(info, input_section, h, sym, "R_386_RELATIVE",
|
||||||
|
&outrel);
|
||||||
}
|
}
|
||||||
|
|
||||||
sreloc = elf_section_data (input_section)->sreloc;
|
sreloc = elf_section_data (input_section)->sreloc;
|
||||||
@ -2769,6 +2786,12 @@ elf_i386_relocate_section (bfd *output_bfd,
|
|||||||
+ input_section->output_section->vma
|
+ input_section->output_section->vma
|
||||||
+ input_section->output_offset;
|
+ input_section->output_offset;
|
||||||
outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
|
outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
|
||||||
|
|
||||||
|
if (htab->params->report_relative_reloc)
|
||||||
|
_bfd_x86_elf_link_report_relative_reloc
|
||||||
|
(info, input_section, h, sym, "R_386_RELATIVE",
|
||||||
|
&outrel);
|
||||||
|
|
||||||
sreloc = elf_section_data (input_section)->sreloc;
|
sreloc = elf_section_data (input_section)->sreloc;
|
||||||
if (sreloc == NULL)
|
if (sreloc == NULL)
|
||||||
abort ();
|
abort ();
|
||||||
@ -3664,6 +3687,11 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd,
|
|||||||
+ h->root.u.def.section->output_offset),
|
+ h->root.u.def.section->output_offset),
|
||||||
gotplt->contents + got_offset);
|
gotplt->contents + got_offset);
|
||||||
rel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
|
rel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
|
||||||
|
|
||||||
|
if (htab->params->report_relative_reloc)
|
||||||
|
_bfd_x86_elf_link_report_relative_reloc
|
||||||
|
(info, relplt, h, sym, "R_386_IRELATIVE", &rel);
|
||||||
|
|
||||||
/* R_386_IRELATIVE comes last. */
|
/* R_386_IRELATIVE comes last. */
|
||||||
plt_index = htab->next_irelative_index--;
|
plt_index = htab->next_irelative_index--;
|
||||||
}
|
}
|
||||||
@ -3762,6 +3790,7 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd,
|
|||||||
{
|
{
|
||||||
Elf_Internal_Rela rel;
|
Elf_Internal_Rela rel;
|
||||||
asection *relgot = htab->elf.srelgot;
|
asection *relgot = htab->elf.srelgot;
|
||||||
|
const char *relative_reloc_name = NULL;
|
||||||
|
|
||||||
/* This symbol has an entry in the global offset table. Set it
|
/* This symbol has an entry in the global offset table. Set it
|
||||||
up. */
|
up. */
|
||||||
@ -3802,6 +3831,7 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd,
|
|||||||
+ h->root.u.def.section->output_offset),
|
+ h->root.u.def.section->output_offset),
|
||||||
htab->elf.sgot->contents + h->got.offset);
|
htab->elf.sgot->contents + h->got.offset);
|
||||||
rel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
|
rel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
|
||||||
|
relative_reloc_name = "R_386_IRELATIVE";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
goto do_glob_dat;
|
goto do_glob_dat;
|
||||||
@ -3844,6 +3874,7 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd,
|
|||||||
{
|
{
|
||||||
BFD_ASSERT((h->got.offset & 1) != 0);
|
BFD_ASSERT((h->got.offset & 1) != 0);
|
||||||
rel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
|
rel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
|
||||||
|
relative_reloc_name = "R_386_RELATIVE";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -3854,6 +3885,11 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd,
|
|||||||
rel.r_info = ELF32_R_INFO (h->dynindx, R_386_GLOB_DAT);
|
rel.r_info = ELF32_R_INFO (h->dynindx, R_386_GLOB_DAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (relative_reloc_name != NULL
|
||||||
|
&& htab->params->report_relative_reloc)
|
||||||
|
_bfd_x86_elf_link_report_relative_reloc
|
||||||
|
(info, relgot, h, sym, relative_reloc_name, &rel);
|
||||||
|
|
||||||
elf_append_rel (output_bfd, relgot, &rel);
|
elf_append_rel (output_bfd, relgot, &rel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2784,6 +2784,11 @@ elf_x86_64_relocate_section (bfd *output_bfd,
|
|||||||
outrel.r_addend = (h->root.u.def.value
|
outrel.r_addend = (h->root.u.def.value
|
||||||
+ h->root.u.def.section->output_section->vma
|
+ h->root.u.def.section->output_section->vma
|
||||||
+ h->root.u.def.section->output_offset);
|
+ h->root.u.def.section->output_offset);
|
||||||
|
|
||||||
|
if (htab->params->report_relative_reloc)
|
||||||
|
_bfd_x86_elf_link_report_relative_reloc
|
||||||
|
(info, input_section, h, sym,
|
||||||
|
"R_X86_64_IRELATIVE", &outrel);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2940,6 +2945,12 @@ elf_x86_64_relocate_section (bfd *output_bfd,
|
|||||||
+ off);
|
+ off);
|
||||||
outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
|
outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
|
||||||
outrel.r_addend = relocation;
|
outrel.r_addend = relocation;
|
||||||
|
|
||||||
|
if (htab->params->report_relative_reloc)
|
||||||
|
_bfd_x86_elf_link_report_relative_reloc
|
||||||
|
(info, input_section, h, sym, "R_X86_64_RELATIVE",
|
||||||
|
&outrel);
|
||||||
|
|
||||||
elf_append_rela (output_bfd, s, &outrel);
|
elf_append_rela (output_bfd, s, &outrel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3221,6 +3232,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
|
|||||||
Elf_Internal_Rela outrel;
|
Elf_Internal_Rela outrel;
|
||||||
bfd_boolean skip, relocate;
|
bfd_boolean skip, relocate;
|
||||||
asection *sreloc;
|
asection *sreloc;
|
||||||
|
const char *relative_reloc_name = NULL;
|
||||||
|
|
||||||
/* When generating a shared object, these relocations
|
/* When generating a shared object, these relocations
|
||||||
are copied into the output file to be resolved at run
|
are copied into the output file to be resolved at run
|
||||||
@ -3259,6 +3271,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
|
|||||||
relocate = TRUE;
|
relocate = TRUE;
|
||||||
outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
|
outrel.r_info = htab->r_info (0, R_X86_64_RELATIVE);
|
||||||
outrel.r_addend = relocation + rel->r_addend;
|
outrel.r_addend = relocation + rel->r_addend;
|
||||||
|
relative_reloc_name = "R_X86_64_RELATIVE";
|
||||||
}
|
}
|
||||||
else if (r_type == R_X86_64_64
|
else if (r_type == R_X86_64_64
|
||||||
&& !ABI_64_P (output_bfd))
|
&& !ABI_64_P (output_bfd))
|
||||||
@ -3267,6 +3280,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
|
|||||||
outrel.r_info = htab->r_info (0,
|
outrel.r_info = htab->r_info (0,
|
||||||
R_X86_64_RELATIVE64);
|
R_X86_64_RELATIVE64);
|
||||||
outrel.r_addend = relocation + rel->r_addend;
|
outrel.r_addend = relocation + rel->r_addend;
|
||||||
|
relative_reloc_name = "R_X86_64_RELATIVE64";
|
||||||
/* Check addend overflow. */
|
/* Check addend overflow. */
|
||||||
if ((outrel.r_addend & 0x80000000)
|
if ((outrel.r_addend & 0x80000000)
|
||||||
!= (rel->r_addend & 0x80000000))
|
!= (rel->r_addend & 0x80000000))
|
||||||
@ -3333,6 +3347,12 @@ elf_x86_64_relocate_section (bfd *output_bfd,
|
|||||||
goto check_relocation_error;
|
goto check_relocation_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (relative_reloc_name
|
||||||
|
&& htab->params->report_relative_reloc)
|
||||||
|
_bfd_x86_elf_link_report_relative_reloc
|
||||||
|
(info, input_section, h, sym, relative_reloc_name,
|
||||||
|
&outrel);
|
||||||
|
|
||||||
elf_append_rela (output_bfd, sreloc, &outrel);
|
elf_append_rela (output_bfd, sreloc, &outrel);
|
||||||
|
|
||||||
/* If this reloc is against an external symbol, we do
|
/* If this reloc is against an external symbol, we do
|
||||||
@ -4292,6 +4312,11 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
|
|||||||
rela.r_addend = (h->root.u.def.value
|
rela.r_addend = (h->root.u.def.value
|
||||||
+ h->root.u.def.section->output_section->vma
|
+ h->root.u.def.section->output_section->vma
|
||||||
+ h->root.u.def.section->output_offset);
|
+ h->root.u.def.section->output_offset);
|
||||||
|
|
||||||
|
if (htab->params->report_relative_reloc)
|
||||||
|
_bfd_x86_elf_link_report_relative_reloc
|
||||||
|
(info, relplt, h, sym, "R_X86_64_IRELATIVE", &rela);
|
||||||
|
|
||||||
/* R_X86_64_IRELATIVE comes last. */
|
/* R_X86_64_IRELATIVE comes last. */
|
||||||
plt_index = htab->next_irelative_index--;
|
plt_index = htab->next_irelative_index--;
|
||||||
}
|
}
|
||||||
@ -4409,6 +4434,7 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
|
|||||||
{
|
{
|
||||||
Elf_Internal_Rela rela;
|
Elf_Internal_Rela rela;
|
||||||
asection *relgot = htab->elf.srelgot;
|
asection *relgot = htab->elf.srelgot;
|
||||||
|
const char *relative_reloc_name = NULL;
|
||||||
|
|
||||||
/* This symbol has an entry in the global offset table. Set it
|
/* This symbol has an entry in the global offset table. Set it
|
||||||
up. */
|
up. */
|
||||||
@ -4447,6 +4473,7 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
|
|||||||
rela.r_addend = (h->root.u.def.value
|
rela.r_addend = (h->root.u.def.value
|
||||||
+ h->root.u.def.section->output_section->vma
|
+ h->root.u.def.section->output_section->vma
|
||||||
+ h->root.u.def.section->output_offset);
|
+ h->root.u.def.section->output_offset);
|
||||||
|
relative_reloc_name = "R_X86_64_IRELATIVE";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
goto do_glob_dat;
|
goto do_glob_dat;
|
||||||
@ -4494,6 +4521,7 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
|
|||||||
rela.r_addend = (h->root.u.def.value
|
rela.r_addend = (h->root.u.def.value
|
||||||
+ h->root.u.def.section->output_section->vma
|
+ h->root.u.def.section->output_section->vma
|
||||||
+ h->root.u.def.section->output_offset);
|
+ h->root.u.def.section->output_offset);
|
||||||
|
relative_reloc_name = "R_X86_64_RELATIVE";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -4505,6 +4533,11 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
|
|||||||
rela.r_addend = 0;
|
rela.r_addend = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (relative_reloc_name != NULL
|
||||||
|
&& htab->params->report_relative_reloc)
|
||||||
|
_bfd_x86_elf_link_report_relative_reloc
|
||||||
|
(info, relgot, h, sym, relative_reloc_name, &rela);
|
||||||
|
|
||||||
elf_append_rela (output_bfd, relgot, &rela);
|
elf_append_rela (output_bfd, relgot, &rela);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1742,6 +1742,53 @@ _bfd_x86_elf_link_fixup_ifunc_symbol (struct bfd_link_info *info,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Report relative relocation. */
|
||||||
|
|
||||||
|
void
|
||||||
|
_bfd_x86_elf_link_report_relative_reloc
|
||||||
|
(struct bfd_link_info *info, asection *asect,
|
||||||
|
struct elf_link_hash_entry *h, Elf_Internal_Sym *sym,
|
||||||
|
const char *reloc_name, const void *reloc)
|
||||||
|
{
|
||||||
|
const char *name;
|
||||||
|
bfd *abfd;
|
||||||
|
const Elf_Internal_Rela *rel = (const Elf_Internal_Rela *) reloc;
|
||||||
|
char r_offset[30], r_info[30];
|
||||||
|
|
||||||
|
/* Use the output BFD for linker created sections. */
|
||||||
|
if ((asect->flags & SEC_LINKER_CREATED) != 0)
|
||||||
|
abfd = info->output_bfd;
|
||||||
|
else
|
||||||
|
abfd = asect->owner;
|
||||||
|
|
||||||
|
if (h != NULL && h->root.root.string != NULL)
|
||||||
|
name = h->root.root.string;
|
||||||
|
else
|
||||||
|
name = bfd_elf_sym_name (abfd, &elf_symtab_hdr (abfd), sym, NULL);
|
||||||
|
|
||||||
|
bfd_sprintf_vma (abfd, r_offset, rel->r_offset);
|
||||||
|
bfd_sprintf_vma (abfd, r_info, rel->r_info);
|
||||||
|
|
||||||
|
if (asect->use_rela_p)
|
||||||
|
{
|
||||||
|
char r_addend[30];
|
||||||
|
|
||||||
|
bfd_sprintf_vma (abfd, r_addend, rel->r_addend);
|
||||||
|
|
||||||
|
info->callbacks->einfo
|
||||||
|
(_("%pB: %s (offset: 0x%s, info: 0x%s, addend: 0x%s) against "
|
||||||
|
"'%s' " "for section '%pA' in %pB\n"),
|
||||||
|
info->output_bfd, reloc_name, r_offset, r_info, r_addend,
|
||||||
|
name, asect, abfd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
info->callbacks->einfo
|
||||||
|
(_("%pB: %s (offset: 0x%s, info: 0x%s) against '%s' for section "
|
||||||
|
"'%pA' in %pB\n"),
|
||||||
|
info->output_bfd, reloc_name, r_offset, r_info, name,
|
||||||
|
asect, abfd);
|
||||||
|
}
|
||||||
|
|
||||||
/* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
|
/* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
|
||||||
|
|
||||||
bfd_boolean
|
bfd_boolean
|
||||||
|
@ -686,6 +686,10 @@ extern void _bfd_x86_elf_link_fixup_ifunc_symbol
|
|||||||
(struct bfd_link_info *, struct elf_x86_link_hash_table *,
|
(struct bfd_link_info *, struct elf_x86_link_hash_table *,
|
||||||
struct elf_link_hash_entry *, Elf_Internal_Sym *sym);
|
struct elf_link_hash_entry *, Elf_Internal_Sym *sym);
|
||||||
|
|
||||||
|
extern void _bfd_x86_elf_link_report_relative_reloc
|
||||||
|
(struct bfd_link_info *, asection *, struct elf_link_hash_entry *,
|
||||||
|
Elf_Internal_Sym *, const char *, const void *);
|
||||||
|
|
||||||
#define bfd_elf64_mkobject \
|
#define bfd_elf64_mkobject \
|
||||||
_bfd_x86_elf_mkobject
|
_bfd_x86_elf_mkobject
|
||||||
#define bfd_elf32_mkobject \
|
#define bfd_elf32_mkobject \
|
||||||
|
19
ld/ChangeLog
19
ld/ChangeLog
@ -1,3 +1,22 @@
|
|||||||
|
2021-01-15 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
|
* NEWS: Mention -z report-relative-reloc.
|
||||||
|
* ld.texi: Document -z report-relative-reloc.
|
||||||
|
* emulparams/elf32_x86_64.sh: Source x86-report-relative.sh.
|
||||||
|
* emulparams/elf_i386.sh: Likewse.
|
||||||
|
* emulparams/elf_x86_64.sh: Likewse.
|
||||||
|
* emulparams/x86-report-relative.sh: New file.
|
||||||
|
* testsuite/ld-i386/report-reloc-1.d: Likewse.
|
||||||
|
* testsuite/ld-i386/report-reloc-1.l: Likewse.
|
||||||
|
* testsuite/ld-i386/report-reloc-1.s: Likewse.
|
||||||
|
* testsuite/ld-x86-64/report-reloc-1-x32.d: Likewse.
|
||||||
|
* testsuite/ld-x86-64/report-reloc-1.d: Likewse.
|
||||||
|
* testsuite/ld-x86-64/report-reloc-1.l: Likewse.
|
||||||
|
* testsuite/ld-x86-64/report-reloc-1.s: Likewse.
|
||||||
|
* testsuite/ld-i386/i386.exp: Run report-reloc-1.
|
||||||
|
* testsuite/ld-x86-64/x86-64.exp: Run report-reloc-1 and
|
||||||
|
report-reloc-1-x32.
|
||||||
|
|
||||||
2021-01-16 Alan Modra <amodra@gmail.com>
|
2021-01-16 Alan Modra <amodra@gmail.com>
|
||||||
|
|
||||||
PR 26002
|
PR 26002
|
||||||
|
3
ld/NEWS
3
ld/NEWS
@ -1,5 +1,8 @@
|
|||||||
-*- text -*-
|
-*- text -*-
|
||||||
|
|
||||||
|
* Add -z report-relative-reloc to x86 ELF linker to report dynamic
|
||||||
|
relative relocations.
|
||||||
|
|
||||||
Changes in 2.36:
|
Changes in 2.36:
|
||||||
|
|
||||||
* Add libdep plugin, for linking dependencies of static libraries that
|
* Add libdep plugin, for linking dependencies of static libraries that
|
||||||
|
@ -4,6 +4,7 @@ source_sh ${srcdir}/emulparams/dynamic_undefined_weak.sh
|
|||||||
source_sh ${srcdir}/emulparams/reloc_overflow.sh
|
source_sh ${srcdir}/emulparams/reloc_overflow.sh
|
||||||
source_sh ${srcdir}/emulparams/call_nop.sh
|
source_sh ${srcdir}/emulparams/call_nop.sh
|
||||||
source_sh ${srcdir}/emulparams/cet.sh
|
source_sh ${srcdir}/emulparams/cet.sh
|
||||||
|
source_sh ${srcdir}/emulparams/x86-report-relative.sh
|
||||||
source_sh ${srcdir}/emulparams/x86-64-level.sh
|
source_sh ${srcdir}/emulparams/x86-64-level.sh
|
||||||
source_sh ${srcdir}/emulparams/static.sh
|
source_sh ${srcdir}/emulparams/static.sh
|
||||||
SCRIPT_NAME=elf
|
SCRIPT_NAME=elf
|
||||||
|
@ -3,6 +3,7 @@ source_sh ${srcdir}/emulparams/extern_protected_data.sh
|
|||||||
source_sh ${srcdir}/emulparams/dynamic_undefined_weak.sh
|
source_sh ${srcdir}/emulparams/dynamic_undefined_weak.sh
|
||||||
source_sh ${srcdir}/emulparams/call_nop.sh
|
source_sh ${srcdir}/emulparams/call_nop.sh
|
||||||
source_sh ${srcdir}/emulparams/cet.sh
|
source_sh ${srcdir}/emulparams/cet.sh
|
||||||
|
source_sh ${srcdir}/emulparams/x86-report-relative.sh
|
||||||
source_sh ${srcdir}/emulparams/x86-64-level.sh
|
source_sh ${srcdir}/emulparams/x86-64-level.sh
|
||||||
source_sh ${srcdir}/emulparams/static.sh
|
source_sh ${srcdir}/emulparams/static.sh
|
||||||
SCRIPT_NAME=elf
|
SCRIPT_NAME=elf
|
||||||
|
@ -4,6 +4,7 @@ source_sh ${srcdir}/emulparams/dynamic_undefined_weak.sh
|
|||||||
source_sh ${srcdir}/emulparams/reloc_overflow.sh
|
source_sh ${srcdir}/emulparams/reloc_overflow.sh
|
||||||
source_sh ${srcdir}/emulparams/call_nop.sh
|
source_sh ${srcdir}/emulparams/call_nop.sh
|
||||||
source_sh ${srcdir}/emulparams/cet.sh
|
source_sh ${srcdir}/emulparams/cet.sh
|
||||||
|
source_sh ${srcdir}/emulparams/x86-report-relative.sh
|
||||||
source_sh ${srcdir}/emulparams/x86-64-level.sh
|
source_sh ${srcdir}/emulparams/x86-64-level.sh
|
||||||
source_sh ${srcdir}/emulparams/x86-64-lam.sh
|
source_sh ${srcdir}/emulparams/x86-64-lam.sh
|
||||||
source_sh ${srcdir}/emulparams/static.sh
|
source_sh ${srcdir}/emulparams/static.sh
|
||||||
|
11
ld/emulparams/x86-report-relative.sh
Normal file
11
ld/emulparams/x86-report-relative.sh
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
PARSE_AND_LIST_OPTIONS_X86_REPORT_RELATIVE='
|
||||||
|
fprintf (file, _("\
|
||||||
|
-z report-relative-reloc Report relative relocations\n"));
|
||||||
|
'
|
||||||
|
PARSE_AND_LIST_ARGS_CASE_Z_X86_REPORT_RELATIVE='
|
||||||
|
else if (strcmp (optarg, "report-relative-reloc") == 0)
|
||||||
|
params.report_relative_reloc = 1;
|
||||||
|
'
|
||||||
|
|
||||||
|
PARSE_AND_LIST_OPTIONS="$PARSE_AND_LIST_OPTIONS $PARSE_AND_LIST_OPTIONS_X86_REPORT_RELATIVE"
|
||||||
|
PARSE_AND_LIST_ARGS_CASE_Z="$PARSE_AND_LIST_ARGS_CASE_Z $PARSE_AND_LIST_ARGS_CASE_Z_X86_REPORT_RELATIVE"
|
@ -1426,6 +1426,10 @@ relocation, if supported. Specifying @samp{common-page-size} smaller
|
|||||||
than the system page size will render this protection ineffective.
|
than the system page size will render this protection ineffective.
|
||||||
Don't create an ELF @code{PT_GNU_RELRO} segment if @samp{norelro}.
|
Don't create an ELF @code{PT_GNU_RELRO} segment if @samp{norelro}.
|
||||||
|
|
||||||
|
@item report-relative-reloc
|
||||||
|
Report dynamic relative relocations generated by linker. Supported for
|
||||||
|
Linux/i386 and Linux/x86_64.
|
||||||
|
|
||||||
@item separate-code
|
@item separate-code
|
||||||
@itemx noseparate-code
|
@itemx noseparate-code
|
||||||
Create separate code @code{PT_LOAD} segment header in the object. This
|
Create separate code @code{PT_LOAD} segment header in the object. This
|
||||||
|
@ -506,6 +506,7 @@ run_dump_test "pr18815"
|
|||||||
run_dump_test "pr19939a"
|
run_dump_test "pr19939a"
|
||||||
run_dump_test "pr19939b"
|
run_dump_test "pr19939b"
|
||||||
run_dump_test "tlsdesc2"
|
run_dump_test "tlsdesc2"
|
||||||
|
run_dump_test "report-reloc-1"
|
||||||
|
|
||||||
proc undefined_weak {cflags ldflags} {
|
proc undefined_weak {cflags ldflags} {
|
||||||
set testname "Undefined weak symbol"
|
set testname "Undefined weak symbol"
|
||||||
|
10
ld/testsuite/ld-i386/report-reloc-1.d
Normal file
10
ld/testsuite/ld-i386/report-reloc-1.d
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#source: report-reloc-1.s
|
||||||
|
#as: --32
|
||||||
|
#ld: -pie -melf_i386 -z report-relative-reloc
|
||||||
|
#warning_output: report-reloc-1.l
|
||||||
|
#readelf: -r --wide
|
||||||
|
|
||||||
|
Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 2 entries:
|
||||||
|
+Offset +Info +Type +Sym.* Value +Symbol's Name
|
||||||
|
[0-9a-f]+ +[0-9a-f]+ +R_386_RELATIVE +
|
||||||
|
[0-9a-f]+ +[0-9a-f]+ +R_386_IRELATIVE +
|
2
ld/testsuite/ld-i386/report-reloc-1.l
Normal file
2
ld/testsuite/ld-i386/report-reloc-1.l
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
tmpdir/dump: R_386_IRELATIVE \(offset: 0x0+2000, info: 0x0+2a\) against 'ifunc' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o
|
||||||
|
tmpdir/dump: R_386_RELATIVE \(offset: 0x0+2004, info: 0x0+8\) against '_start' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o
|
12
ld/testsuite/ld-i386/report-reloc-1.s
Normal file
12
ld/testsuite/ld-i386/report-reloc-1.s
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
.text
|
||||||
|
.globl _start
|
||||||
|
.type ifunc, @gnu_indirect_function
|
||||||
|
_start:
|
||||||
|
lea .Ljmp@GOTOFF(%ebx), %eax
|
||||||
|
ifunc:
|
||||||
|
jmp *(%eax)
|
||||||
|
.section .data.rel.ro.local,"aw",@progbits
|
||||||
|
.align 4
|
||||||
|
.Ljmp:
|
||||||
|
.long ifunc
|
||||||
|
.long _start
|
10
ld/testsuite/ld-x86-64/report-reloc-1-x32.d
Normal file
10
ld/testsuite/ld-x86-64/report-reloc-1-x32.d
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#source: report-reloc-1.s
|
||||||
|
#as: --x32
|
||||||
|
#ld: -pie -melf32_x86_64 -z report-relative-reloc
|
||||||
|
#warning_output: report-reloc-1.l
|
||||||
|
#readelf: -r --wide
|
||||||
|
|
||||||
|
Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 2 entries:
|
||||||
|
+Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend
|
||||||
|
[0-9a-f]+ +[0-9a-f]+ +R_X86_64_RELATIVE +[0-9a-f]+
|
||||||
|
[0-9a-f]+ +[0-9a-f]+ +R_X86_64_IRELATIVE +[0-9a-f]+
|
10
ld/testsuite/ld-x86-64/report-reloc-1.d
Normal file
10
ld/testsuite/ld-x86-64/report-reloc-1.d
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#source: report-reloc-1.s
|
||||||
|
#as: --64
|
||||||
|
#ld: -pie -melf_x86_64 -z report-relative-reloc
|
||||||
|
#warning_output: report-reloc-1.l
|
||||||
|
#readelf: -r --wide
|
||||||
|
|
||||||
|
Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 2 entries:
|
||||||
|
+Offset +Info +Type +Sym.* Value +Symbol's Name \+ Addend
|
||||||
|
[0-9a-f]+ +[0-9a-f]+ +R_X86_64_RELATIVE +[0-9a-f]+
|
||||||
|
[0-9a-f]+ +[0-9a-f]+ +R_X86_64_IRELATIVE +[0-9a-f]+
|
2
ld/testsuite/ld-x86-64/report-reloc-1.l
Normal file
2
ld/testsuite/ld-x86-64/report-reloc-1.l
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
tmpdir/dump: R_X86_64_IRELATIVE \(offset: 0x0+2000, info: 0x0+25, addend: 0x0+1007\) against 'ifunc' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o
|
||||||
|
tmpdir/dump: R_X86_64_RELATIVE \(offset: 0x0+2008, info: 0x0+8, addend: 0x0+1000\) against '_start' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o
|
12
ld/testsuite/ld-x86-64/report-reloc-1.s
Normal file
12
ld/testsuite/ld-x86-64/report-reloc-1.s
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
.text
|
||||||
|
.globl _start
|
||||||
|
.type ifunc, @gnu_indirect_function
|
||||||
|
_start:
|
||||||
|
lea .Ljmp(%rip), %rax
|
||||||
|
ifunc:
|
||||||
|
jmp *(%rax)
|
||||||
|
.section .data.rel.ro.local,"aw",@progbits
|
||||||
|
.align 8
|
||||||
|
.Ljmp:
|
||||||
|
.quad ifunc
|
||||||
|
.quad _start
|
@ -677,6 +677,8 @@ run_dump_test "pr26939"
|
|||||||
run_dump_test "pr26939-x32"
|
run_dump_test "pr26939-x32"
|
||||||
run_dump_test "pr27016a"
|
run_dump_test "pr27016a"
|
||||||
run_dump_test "pr27016b"
|
run_dump_test "pr27016b"
|
||||||
|
run_dump_test "report-reloc-1"
|
||||||
|
run_dump_test "report-reloc-1-x32"
|
||||||
|
|
||||||
proc undefined_weak {cflags ldflags} {
|
proc undefined_weak {cflags ldflags} {
|
||||||
set testname "Undefined weak symbol"
|
set testname "Undefined weak symbol"
|
||||||
|
Loading…
Reference in New Issue
Block a user