Discussion:
[PATCH 0/6] [ARC] Fixes for GlibC port support.
c***@gmail.com
2018-09-13 15:38:33 UTC
Permalink
Hello everyone,

Please find some ARC specific patches to the linker, related to the soon
to be upstreamed port of Glibc.
Looking forward to your review and comments.

Best regards,
Cupertino Miranda
c***@gmail.com
2018-09-13 15:38:34 UTC
Permalink
From: Cupertino Miranda <***@synopsys.com>

Change location where GOT information is collected for ARC target, avoiding
posible use conflicts of the previous .got field in the symbols hash_entry.

bfd/
2018-03-01 Cupertino Miranda <***@synopsys.com>

* arc-got.h (get_got_entry_list_for_symbol): Changed.
* ef32-arc.c (struct elf_arc_link_hash_entry): Moved and changed.
(elf_arc_link_hash_newfunc): Changed.
(arc_elf_link_hash_table_create): Removed old initializations.
(elf_arc_relocate_section, elf_arc_finish_dynamic_symbol): Changed.
---
bfd/arc-got.h | 6 +++--
bfd/elf32-arc.c | 77 +++++++++++++++++++++++++++++++--------------------------
2 files changed, 46 insertions(+), 37 deletions(-)

diff --git a/bfd/arc-got.h b/bfd/arc-got.h
index a86061b..81ce88f 100644
--- a/bfd/arc-got.h
+++ b/bfd/arc-got.h
@@ -156,9 +156,11 @@ get_got_entry_list_for_symbol (bfd *abfd,
unsigned long r_symndx,
struct elf_link_hash_entry *h)
{
- if (h != NULL)
+ struct elf_arc_link_hash_entry *h1 =
+ ((struct elf_arc_link_hash_entry *) h);
+ if (h1 != NULL)
{
- return &h->got.glist;
+ return &h1->got_ents;
}
else
{
diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
index 62366a7..f498668 100644
--- a/bfd/elf32-arc.c
+++ b/bfd/elf32-arc.c
@@ -160,6 +160,18 @@ struct arc_relocation_data
const char * symbol_name;
};

+/* ARC ELF linker hash entry. */
+struct elf_arc_link_hash_entry
+{
+ struct elf_link_hash_entry root;
+
+ /* Track dynamic relocs copied for this symbol. */
+ struct elf_dyn_relocs *dyn_relocs;
+
+ struct got_entry *got_ents;
+};
+
+
/* Should be included at this location due to static declarations
defined before this point. */
#include "arc-got.h"
@@ -281,15 +293,6 @@ struct arc_reloc_map
unsigned char elf_reloc_val;
};

-/* ARC ELF linker hash entry. */
-struct elf_arc_link_hash_entry
-{
- struct elf_link_hash_entry root;
-
- /* Track dynamic relocs copied for this symbol. */
- struct elf_dyn_relocs *dyn_relocs;
-};
-
/* ARC ELF linker hash table. */
struct elf_arc_link_hash_table
{
@@ -301,28 +304,28 @@ elf_arc_link_hash_newfunc (struct bfd_hash_entry *entry,
struct bfd_hash_table *table,
const char *string)
{
+ struct elf_arc_link_hash_entry * ret =
+ (struct elf_arc_link_hash_entry *) entry;
+
/* Allocate the structure if it has not already been allocated by a
subclass. */
- if (entry == NULL)
- {
- entry = (struct bfd_hash_entry *)
- bfd_hash_allocate (table,
- sizeof (struct elf_arc_link_hash_entry));
- if (entry == NULL)
- return entry;
- }
+ if (ret == NULL)
+ ret = (struct elf_arc_link_hash_entry *)
+ bfd_hash_allocate (table, sizeof (struct elf_arc_link_hash_entry));
+ if (ret == NULL)
+ return (struct bfd_hash_entry *) ret;

/* Call the allocation method of the superclass. */
- entry = _bfd_elf_link_hash_newfunc (entry, table, string);
- if (entry != NULL)
+ ret = ((struct elf_arc_link_hash_entry *)
+ _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
+ table, string));
+ if (ret != NULL)
{
- struct elf_arc_link_hash_entry *eh;
-
- eh = (struct elf_arc_link_hash_entry *) entry;
- eh->dyn_relocs = NULL;
+ ret->dyn_relocs = NULL;
+ ret->got_ents = NULL;
}

- return entry;
+ return (struct bfd_hash_entry *) ret;
}

/* Destroy an ARC ELF linker hash table. */
@@ -352,11 +355,6 @@ arc_elf_link_hash_table_create (bfd *abfd)
return NULL;
}

- ret->elf.init_got_refcount.refcount = 0;
- ret->elf.init_got_refcount.glist = NULL;
- ret->elf.init_got_offset.offset = 0;
- ret->elf.init_got_offset.glist = NULL;
-
ret->elf.root.hash_table_free = elf_arc_link_hash_table_free;

return &ret->elf.root;
@@ -1631,10 +1629,14 @@ elf_arc_relocate_section (bfd * output_bfd,
while (h->root.type == bfd_link_hash_indirect
|| h->root.type == bfd_link_hash_warning)
{
- struct elf_link_hash_entry *h_old = h;
+ struct elf_arc_link_hash_entry *ah_old =
+ (struct elf_arc_link_hash_entry *) h;
h = (struct elf_link_hash_entry *) h->root.u.i.link;
- if (h->got.glist == 0 && h_old->got.glist != h->got.glist)
- h->got.glist = h_old->got.glist;
+ struct elf_arc_link_hash_entry *ah =
+ (struct elf_arc_link_hash_entry *) h;
+
+ if (ah->got_ents == 0 && ah_old->got_ents != ah->got_ents)
+ ah->got_ents = ah_old->got_ents;
}

/* TODO: Need to validate what was the intention. */
@@ -1652,6 +1654,8 @@ elf_arc_relocate_section (bfd * output_bfd,

if (is_reloc_for_GOT (howto) && !bfd_link_pic (info))
{
+ struct elf_arc_link_hash_entry *ah =
+ (struct elf_arc_link_hash_entry *) h;
/* TODO: Change it to use arc_do_relocation with
ARC_32 reloc. Try to use ADD_RELA macro. */
bfd_vma relocation =
@@ -1661,8 +1665,8 @@ elf_arc_relocate_section (bfd * output_bfd,
+ reloc_data.sym_section->output_section->vma)
: 0);

- BFD_ASSERT (h->got.glist);
- bfd_vma got_offset = h->got.glist->offset;
+ BFD_ASSERT (ah->got_ents);
+ bfd_vma got_offset = ah->got_ents->offset;
bfd_put_32 (output_bfd, relocation,
htab->sgot->contents + got_offset);
}
@@ -1974,6 +1978,7 @@ elf_arc_check_relocs (bfd * abfd,
else /* Global one. */
h = sym_hashes[r_symndx - symtab_hdr->sh_info];

+
switch (r_type)
{
case R_ARC_32:
@@ -2420,7 +2425,9 @@ elf_arc_finish_dynamic_symbol (bfd * output_bfd,
create respective dynamic relocs. */
/* TODO: Make function to get list and not access the list directly. */
/* TODO: Move function to relocate_section create this relocs eagerly. */
- create_got_dynrelocs_for_got_info (&h->got.glist,
+ struct elf_arc_link_hash_entry *ah =
+ (struct elf_arc_link_hash_entry *) h;
+ create_got_dynrelocs_for_got_info (&ah->got_ents,
output_bfd,
info,
h);
--
2.9.0
c***@gmail.com
2018-09-16 11:52:54 UTC
Permalink
Hi,
Post by c***@gmail.com
bfd/
* arc-got.h (get_got_entry_list_for_symbol): Changed.
* ef32-arc.c (struct elf_arc_link_hash_entry): Moved and
changed.
(elf_arc_link_hash_newfunc): Changed.
(arc_elf_link_hash_table_create): Removed old initializations.
Changed.
---
bfd/arc-got.h | 6 +++--
bfd/elf32-arc.c | 77 +++++++++++++++++++++++++++++++--------------
------------
2 files changed, 46 insertions(+), 37 deletions(-)
Looks good. Please apply,
Claudiu
c***@gmail.com
2018-09-13 15:38:35 UTC
Permalink
From: Cupertino Miranda <***@synopsys.com>

bfd/
2018-03-01 Cupertino Miranda <***@synopsys.com>

* elf32-arc.c (elf_arc_finish_dynamic_symbol) Return FALSE in case
arc_htab is NULL.
---
bfd/elf32-arc.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
index f498668..3f60d09 100644
--- a/bfd/elf32-arc.c
+++ b/bfd/elf32-arc.c
@@ -2436,6 +2436,9 @@ elf_arc_finish_dynamic_symbol (bfd * output_bfd,
{
struct elf_arc_link_hash_table *arc_htab = elf_arc_hash_table (info);

+ if (arc_htab == NULL)
+ return FALSE;
+
if (h->dynindx == -1
|| (h->root.type != bfd_link_hash_defined
&& h->root.type != bfd_link_hash_defweak)
--
2.9.0
c***@gmail.com
2018-09-16 11:55:35 UTC
Permalink
Hi Cupertino,
Post by c***@gmail.com
bfd/
* elf32-arc.c (elf_arc_finish_dynamic_symbol) Return FALSE in
case
arc_htab is NULL.
---
bfd/elf32-arc.c | 3 +++
1 file changed, 3 insertions(+)
Looks good, please apply,
Claudiu
c***@gmail.com
2018-09-13 15:38:36 UTC
Permalink
From: Cupertino Miranda <***@synopsys.com>

Problem identified in the context of glibc with latest upstream binutils.
Dynamic symbol space was being reserved but, no actual information for the
symbol was being set. Data for the symbol was kept initialized with -1.
No easy test case was possible to be created.

bfd/
2018-03-01 Cupertino Miranda <***@synopsys.com>

* elf32-arc.c (elf_arc_check_relocs): Changed.
---
bfd/elf32-arc.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
index 3f60d09..4d36a41 100644
--- a/bfd/elf32-arc.c
+++ b/bfd/elf32-arc.c
@@ -1976,7 +1976,12 @@ elf_arc_check_relocs (bfd * abfd,
if (r_symndx < symtab_hdr->sh_info) /* Is a local symbol. */
h = NULL;
else /* Global one. */
- h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+ {
+ h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+ while (h->root.type == bfd_link_hash_indirect
+ || h->root.type == bfd_link_hash_warning)
+ h = (struct elf_link_hash_entry *) h->root.u.i.link;
+ }


switch (r_type)
--
2.9.0
c***@gmail.com
2018-09-16 11:57:41 UTC
Permalink
Hi Cupertino,
Post by c***@gmail.com
bfd/
* elf32-arc.c (elf_arc_check_relocs): Changed.
---
bfd/elf32-arc.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
This is ok also. Please apply,
Claudiu
c***@gmail.com
2018-09-13 15:38:37 UTC
Permalink
From: Cupertino Miranda <***@synopsys.com>

A change upstream reveiled this issue, triggering an assert when linking glibc.

bfd/
2018-03-01 Cupertino Miranda <***@synopsys.com>

* elf32-arc.c (elf_arc_check_relocs): Changed.
---
bfd/elf32-arc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
index 4d36a41..180c4dc 100644
--- a/bfd/elf32-arc.c
+++ b/bfd/elf32-arc.c
@@ -2057,7 +2057,8 @@ elf_arc_check_relocs (bfd * abfd,
if (h == NULL)
continue;
else
- h->needs_plt = 1;
+ if (h->forced_local == 0)
+ h->needs_plt = 1;
}

/* Add info to the symbol got_entry_list. */
--
2.9.0
c***@gmail.com
2018-09-16 11:58:52 UTC
Permalink
Hi,
Post by c***@gmail.com
bfd/
* elf32-arc.c (elf_arc_check_relocs): Changed.
---
bfd/elf32-arc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Please apply,
Claudiu
c***@gmail.com
2018-09-13 15:38:38 UTC
Permalink
From: Cupertino Miranda <***@synopsys.com>

This patch fixes glibc testcase in nptl/tls-align.

bfd/
2018-08-01 Cupertino Miranda <***@synopsys.com>

* arc-got.h (relocate_fix_got_relocs_for_got_info): Changed, fixed
TCB_SIZE offsize to include section alignment.
* elf32-arc.c (arc_special_overflow_checks): Likewise.

include/
2018-08-01 Cupertino Miranda <***@synopsys.com>

* arc-reloc.def (ARC_TLS_LE_32): Updated reloc formula.
---
bfd/arc-got.h | 8 +++++++-
bfd/elf32-arc.c | 3 ++-
include/elf/arc-reloc.def | 2 +-
3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/bfd/arc-got.h b/bfd/arc-got.h
index 81ce88f..e32d9b3 100644
--- a/bfd/arc-got.h
+++ b/bfd/arc-got.h
@@ -24,6 +24,9 @@

#define TCB_SIZE (8)

+#define align_power(addr, align) \
+ (((addr) + ((bfd_vma) 1 << (align)) - 1) & (-((bfd_vma) 1 << (align))))
+
enum tls_type_e
{
GOT_UNKNOWN = 0,
@@ -359,7 +362,10 @@ relocate_fix_got_relocs_for_got_info (struct got_entry ** list_p,

bfd_put_32 (output_bfd,
sym_value - sec_vma
- + (elf_hash_table (info)->dynamic_sections_created ? 0 : TCB_SIZE),
+ + (elf_hash_table (info)->dynamic_sections_created
+ ? 0
+ : (align_power (TCB_SIZE,
+ tls_sec->alignment_power))),
htab->sgot->contents + entry->offset
+ (entry->existing_entries == TLS_GOT_MOD_AND_OFF
? 4 : 0));
diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
index 180c4dc..c52e2fb 100644
--- a/bfd/elf32-arc.c
+++ b/bfd/elf32-arc.c
@@ -1218,7 +1218,8 @@ arc_special_overflow_checks (const struct arc_relocation_data reloc_data,
#define _SDA_BASE_ (bfd_signed_vma) (reloc_data.sdata_begin_symbol_vma)
#define TLS_REL (bfd_signed_vma) \
((elf_hash_table (info))->tls_sec->output_section->vma)
-#define TLS_TBSS (8)
+#define TLS_TBSS (align_power(TCB_SIZE, \
+ reloc_data.sym_section->alignment_power))

#define none (0)

diff --git a/include/elf/arc-reloc.def b/include/elf/arc-reloc.def
index a6db724..e1c69c9 100644
--- a/include/elf/arc-reloc.def
+++ b/include/elf/arc-reloc.def
@@ -489,7 +489,7 @@ ARC_RELOC_HOWTO(ARC_TLS_LE_32, 75, \
32, \
replace_word32, \
dont, \
- ( ME ( ( ( ( S + A ) + TCB_SIZE ) - TLS_REL ) ) ))
+ ( ME ( ( ( ( S + A ) + TLS_TBSS ) - TLS_REL ) ) ))

ARC_RELOC_HOWTO(ARC_S25W_PCREL_PLT, 76, \
2, \
--
2.9.0
c***@gmail.com
2018-09-16 12:00:39 UTC
Permalink
Hi,
Post by c***@gmail.com
bfd/
* arc-got.h (relocate_fix_got_relocs_for_got_info): Changed,
fixed
TCB_SIZE offsize to include section alignment.
* elf32-arc.c (arc_special_overflow_checks): Likewise.
include/
* arc-reloc.def (ARC_TLS_LE_32): Updated reloc formula.
Looks also good, please apply,
Claudiu
c***@gmail.com
2018-09-13 15:38:39 UTC
Permalink
From: Cupertino Miranda <***@synopsys.com>

Inserted offset in final section in the GOT entry of type DTSOFF soon to be
relocated by the dynamic loader.

bfd/
2018-09-06 Cupertino Miranda <***@synopsys.com>

* arc-got.h (relocate_fix_got_relocs_for_got_info): Changed. Take TLS
section alignment in consideration for this relocation.
* elf32-arc.c (FINAL_SECTSTART): Added this formula macro.
(ARC_TLS_DTPOFF) Updated reloc to use new created macro instead.
---
bfd/arc-got.h | 10 +++++++---
bfd/elf32-arc.c | 2 ++
include/elf/arc-reloc.def | 2 +-
3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/bfd/arc-got.h b/bfd/arc-got.h
index e32d9b3..07722fd 100644
--- a/bfd/arc-got.h
+++ b/bfd/arc-got.h
@@ -335,7 +335,11 @@ relocate_fix_got_relocs_for_got_info (struct got_entry ** list_p,
bfd_vma sec_vma = tls_sec->output_section->vma;

bfd_put_32 (output_bfd,
- sym_value - sec_vma,
+ sym_value - sec_vma
+ + (elf_hash_table (info)->dynamic_sections_created
+ ? 0
+ : (align_power (TCB_SIZE,
+ tls_sec->alignment_power))),
htab->sgot->contents + entry->offset
+ (entry->existing_entries == TLS_GOT_MOD_AND_OFF
? 4 : 0));
@@ -346,7 +350,7 @@ relocate_fix_got_relocs_for_got_info (struct got_entry ** list_p,
"GOT_TLS_IE"),
(long) (sym_value - sec_vma),
(long) (htab->sgot->output_section->vma
- + htab->sgot->output_offset->vma
+ + htab->sgot->output_offset
+ entry->offset
+ (entry->existing_entries == TLS_GOT_MOD_AND_OFF
? 4 : 0)),
@@ -376,7 +380,7 @@ relocate_fix_got_relocs_for_got_info (struct got_entry ** list_p,
"GOT_TLS_IE"),
(long) (sym_value - sec_vma),
(long) (htab->sgot->output_section->vma
- + htab->sgot->output_offset->vma
+ + htab->sgot->output_offset
+ entry->offset
+ (entry->existing_entries == TLS_GOT_MOD_AND_OFF
? 4 : 0)),
diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
index c52e2fb..7a1b304 100644
--- a/bfd/elf32-arc.c
+++ b/bfd/elf32-arc.c
@@ -1214,6 +1214,8 @@ arc_special_overflow_checks (const struct arc_relocation_data reloc_data,
+ (reloc_data.reloc_offset))))
#define SECTSTART (bfd_signed_vma) (reloc_data.sym_section->output_section->vma \
+ reloc_data.sym_section->output_offset)
+#define FINAL_SECTSTART \
+ (bfd_signed_vma) (reloc_data.sym_section->output_section->vma)
#define JLI (bfd_signed_vma) (reloc_data.sym_section->output_section->vma)
#define _SDA_BASE_ (bfd_signed_vma) (reloc_data.sdata_begin_symbol_vma)
#define TLS_REL (bfd_signed_vma) \
diff --git a/include/elf/arc-reloc.def b/include/elf/arc-reloc.def
index e1c69c9..61edd6e 100644
--- a/include/elf/arc-reloc.def
+++ b/include/elf/arc-reloc.def
@@ -468,7 +468,7 @@ ARC_RELOC_HOWTO(ARC_TLS_DTPOFF, 67, \
32, \
replace_word32, \
dont, \
- ( ME ( S - SECTSTART ) + A ))
+ ( ME ( S - FINAL_SECTSTART ) + A ))

ARC_RELOC_HOWTO(ARC_TLS_DTPOFF_S9, 73, \
2, \
--
2.9.0
c***@gmail.com
2018-09-16 12:02:17 UTC
Permalink
Hi,
Post by c***@gmail.com
bfd/
* arc-got.h (relocate_fix_got_relocs_for_got_info): Changed.
Take TLS
section alignment in consideration for this relocation.
* elf32-arc.c (FINAL_SECTSTART): Added this formula macro.
(ARC_TLS_DTPOFF) Updated reloc to use new created macro
instead.
Any chance to have a test for this issue? Otherwise it looks alright.

Cheers,
Claudiu

Loading...