From: Stafford Horne <shorne@gmail.com>
To: openrisc@lists.librecores.org
Subject: [OpenRISC] [PATCH 1/8] or1k: Fix static linking when with .rela.got relocations
Date: Fri, 15 May 2020 06:00:11 +0900 [thread overview]
Message-ID: <20200514210018.2749462-2-shorne@gmail.com> (raw)
In-Reply-To: <20200514210018.2749462-1-shorne@gmail.com>
When testing glibc static cases were failing due to the assert of
srelgot failing. Using the reference via htab->root.srelgot
works fine as it is initialized. Also, this contains a few other
fixups made while figuring out the issue.
bfd/ChangeLog:
yyyy-mm-dd Stafford Horne <shorne@gmail.com>
* elf32-or1k.c (or1k_elf_finish_dynamic_symbol): Rename srela
to relgot.
(or1k_elf_relocate_section): Access srelgot via
htab->root.srelgot. Add assertions for srelgot->contents.
Introduce local variable for srelgot to not reuse global
sreloc.
---
bfd/elf32-or1k.c | 43 +++++++++++++++++++++++--------------------
1 file changed, 23 insertions(+), 20 deletions(-)
diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c
index 41e61ac7e2..221a14c5b1 100644
--- a/bfd/elf32-or1k.c
+++ b/bfd/elf32-or1k.c
@@ -1226,7 +1226,6 @@ or1k_elf_relocate_section (bfd *output_bfd,
Elf_Internal_Rela *rel;
Elf_Internal_Rela *relend;
struct elf_or1k_link_hash_table *htab = or1k_elf_hash_table (info);
- bfd *dynobj;
asection *sreloc;
bfd_vma *local_got_offsets;
asection *sgot, *splt;
@@ -1236,7 +1235,6 @@ or1k_elf_relocate_section (bfd *output_bfd,
if (htab == NULL)
return FALSE;
- dynobj = htab->root.dynobj;
local_got_offsets = elf_local_got_offsets (input_bfd);
sreloc = elf_section_data (input_section)->sreloc;
@@ -1254,7 +1252,7 @@ or1k_elf_relocate_section (bfd *output_bfd,
got_sym_value = (hgot->root.u.def.value
+ hgot->root.u.def.section->output_section->vma
+ hgot->root.u.def.section->output_offset);
- got_base = sgot->output_section->vma + sgot->output_offset;
+ got_base = sgot->output_section->vma + sgot->output_offset;
}
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
@@ -1416,16 +1414,16 @@ or1k_elf_relocate_section (bfd *output_bfd,
/* We need to generate a R_OR1K_RELATIVE reloc
for the dynamic linker. */
- srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
+ srelgot = htab->root.srelgot;
BFD_ASSERT (srelgot != NULL);
outrel.r_offset = got_base + off;
outrel.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
outrel.r_addend = relocation;
loc = srelgot->contents;
- loc += (srelgot->reloc_count
- * sizeof (Elf32_External_Rela));
- bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc);
+ loc += (srelgot->reloc_count
+ * sizeof (Elf32_External_Rela));
+ bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
++srelgot->reloc_count;
}
local_got_offsets[r_symndx] |= 1;
@@ -1591,10 +1589,11 @@ or1k_elf_relocate_section (bfd *output_bfd,
{
bfd_vma gotoff;
Elf_Internal_Rela rela;
+ asection *srelgot;
bfd_byte *loc;
int dynamic;
- sreloc = bfd_get_section_by_name (dynobj, ".rela.got");
+ srelgot = htab->root.srelgot;
/* Mark as TLS related GOT entry by setting
bit 2 as well as bit 1. */
@@ -1619,7 +1618,7 @@ or1k_elf_relocate_section (bfd *output_bfd,
BFD_ASSERT (elf_hash_table (info)->hgot == NULL
|| elf_hash_table (info)->hgot->root.u.def.value == 0);
- /* Dynamic entries will require relocations. if we do not need
+ /* Dynamic entries will require relocations. If we do not need
them we will just use the default R_OR1K_NONE and
not set anything. */
dynamic = bfd_link_pic (info)
@@ -1639,6 +1638,8 @@ or1k_elf_relocate_section (bfd *output_bfd,
/* Add DTPMOD and DTPOFF GOT and rela entries. */
for (i = 0; i < 2; ++i)
{
+ BFD_ASSERT (srelgot->contents != NULL);
+
rela.r_offset = got_base + gotoff + i*4;
if (h != NULL && h->dynindx != -1)
{
@@ -1653,9 +1654,9 @@ or1k_elf_relocate_section (bfd *output_bfd,
rela.r_addend = tpoff (info, relocation);
}
- loc = sreloc->contents;
- loc += sreloc->reloc_count++ *
- sizeof (Elf32_External_Rela);
+ loc = srelgot->contents;
+ loc += (srelgot->reloc_count++
+ * sizeof (Elf32_External_Rela));
bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
bfd_put_32 (output_bfd, 0, sgot->contents + gotoff + i*4);
@@ -1674,6 +1675,8 @@ or1k_elf_relocate_section (bfd *output_bfd,
/* Shared IE. */
else if (dynamic)
{
+ BFD_ASSERT (srelgot->contents != NULL);
+
/* Add TPOFF GOT and rela entries. */
rela.r_offset = got_base + gotoff;
if (h != NULL && h->dynindx != -1)
@@ -1687,8 +1690,8 @@ or1k_elf_relocate_section (bfd *output_bfd,
rela.r_addend = tpoff (info, relocation);
}
- loc = sreloc->contents;
- loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
+ loc = srelgot->contents;
+ loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
bfd_put_32 (output_bfd, 0, sgot->contents + gotoff);
@@ -2402,14 +2405,14 @@ or1k_elf_finish_dynamic_symbol (bfd *output_bfd,
&& (h->got.offset & 2) == 0) /* Homemade TLS check. */
{
asection *sgot;
- asection *srela;
+ asection *srelgot;
Elf_Internal_Rela rela;
/* This symbol has an entry in the global offset table. Set it
up. */
sgot = htab->root.sgot;
- srela = htab->root.srelgot;
- BFD_ASSERT (sgot != NULL && srela != NULL);
+ srelgot = htab->root.srelgot;
+ BFD_ASSERT (sgot != NULL && srelgot != NULL);
rela.r_offset = (sgot->output_section->vma
+ sgot->output_offset
@@ -2435,10 +2438,10 @@ or1k_elf_finish_dynamic_symbol (bfd *output_bfd,
rela.r_addend = 0;
}
- loc = srela->contents;
- loc += srela->reloc_count * sizeof (Elf32_External_Rela);
+ loc = srelgot->contents;
+ loc += srelgot->reloc_count * sizeof (Elf32_External_Rela);
bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
- ++srela->reloc_count;
+ ++srelgot->reloc_count;
}
if (h->needs_copy)
--
2.26.2
next prev parent reply other threads:[~2020-05-14 21:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-14 21:00 [OpenRISC] [PATCH 0/8] OpenRISC BFD fixups for Glibc Stafford Horne
2020-05-14 21:00 ` Stafford Horne [this message]
2020-05-14 21:00 ` [OpenRISC] [PATCH 2/8] or1k: Fix dynamic TLS symbol flag Stafford Horne
2020-05-14 21:00 ` [OpenRISC] [PATCH 3/8] or1k: Add TLS mask to handle multiple model access Stafford Horne
2020-05-14 21:00 ` [OpenRISC] [PATCH 4/8] or1k: Fix issue with multiple PCREL relocations Stafford Horne
2020-05-14 21:00 ` [OpenRISC] [PATCH 5/8] or1k: TLS offset to use tcb size and section alignment Stafford Horne
2020-05-14 21:00 ` [OpenRISC] [PATCH 6/8] or1k: refactor: Rename p to sec_relocs Stafford Horne
2020-05-14 21:00 ` [OpenRISC] [PATCH 7/8] or1k: refactor: Rename s to sgot and splt Stafford Horne
2020-05-14 21:00 ` [OpenRISC] [PATCH 8/8] or1k: Add dynamic flag to tpoff Stafford Horne
2020-05-19 13:30 ` [OpenRISC] [PATCH 0/8] OpenRISC BFD fixups for Glibc Nick Clifton
2020-05-19 20:42 ` Stafford Horne
2020-05-20 10:41 ` Nick Clifton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200514210018.2749462-2-shorne@gmail.com \
--to=shorne@gmail.com \
--cc=openrisc@lists.librecores.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox