[1/2] z/OS Support: Catching segfaults

Message ID 20200126113756.2009-2-leviathan@libresilicon.com
State Superseded
Headers show
Series
  • Introducing support for cross compiling/linking for the z/OS platform
Related show

Commit Message

David Lanzendörfer Jan. 26, 2020, 11:37 a.m.
From: David Lanzendörfer <leviathan@libresilicon.com>


When handling the z/OS object files in F4SA format certain fields
are blank which caused segfaults in ld during linking.
---
 bfd/linker.c | 2 +-
 ld/ldlang.c  | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

-- 
2.25.0

Comments

Alan Modra Jan. 27, 2020, 7:18 a.m. | #1
On Sun, Jan 26, 2020 at 07:37:53PM +0800, David Lanzenörfer wrote:
> When handling the z/OS object files in F4SA format certain fields

> are blank which caused segfaults in ld during linking.


Where were the segfaults?  As far as I know, bfd_link_hash_lookup is
fine with an empty string,

> @@ -508,7 +508,7 @@ bfd_link_hash_lookup (struct bfd_link_hash_table *table,

>  {

>    struct bfd_link_hash_entry *ret;

>  

> -  if (table == NULL || string == NULL)

> +  if (table == NULL || string == NULL || string[0]=='\0' )


so this isn't OK.  The formatting is wrong too.

> --- a/ld/ldlang.c

> +++ b/ld/ldlang.c

> @@ -6521,6 +6521,8 @@ foreach_start_stop (void (*func) (struct bfd_link_hash_entry *))

>  static void

>  undef_start_stop (struct bfd_link_hash_entry *h)

>  {

> +  if (h==-1)

> +    return;

>    if (h->ldscript_def)

>      return;

>  

> @@ -6586,6 +6588,8 @@ lang_init_startof_sizeof (void)

>  static void

>  set_start_stop (struct bfd_link_hash_entry *h)

>  {

> +  if(h==-1)

> +    return;

>    if (h->ldscript_def

>        || h->type != bfd_link_hash_defined)

>      return;


These also are not OK.  You should prevent whatever caused an entry in
start_stop_syms[] from being -1, rather than papering over the problem
like this.

-- 
Alan Modra
Australia Development Lab, IBM
David Lanzendörfer Jan. 28, 2020, 7:39 a.m. | #2
Hi

> > +  if (table == NULL || string == NULL || string[0]=='\0' )

> so this isn't OK.  The formatting is wrong too.

Ok. I will investigate further here.

> > +  if(h==-1)

> > +    return;

> 

> These also are not OK.  You should prevent whatever caused an entry in

> start_stop_syms[] from being -1, rather than papering over the problem

> like this.

Ok. I will also trace where this undefined hash comes from.

Cheers
David

Patch

diff --git a/bfd/linker.c b/bfd/linker.c
index d8703179e5..9711951ea7 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -508,7 +508,7 @@  bfd_link_hash_lookup (struct bfd_link_hash_table *table,
 {
   struct bfd_link_hash_entry *ret;
 
-  if (table == NULL || string == NULL)
+  if (table == NULL || string == NULL || string[0]=='\0' )
     return NULL;
 
   ret = ((struct bfd_link_hash_entry *)
diff --git a/ld/ldlang.c b/ld/ldlang.c
index e100c0533c..5fbba7e723 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -6521,6 +6521,8 @@  foreach_start_stop (void (*func) (struct bfd_link_hash_entry *))
 static void
 undef_start_stop (struct bfd_link_hash_entry *h)
 {
+  if (h==-1)
+    return;
   if (h->ldscript_def)
     return;
 
@@ -6586,6 +6588,8 @@  lang_init_startof_sizeof (void)
 static void
 set_start_stop (struct bfd_link_hash_entry *h)
 {
+  if(h==-1)
+    return;
   if (h->ldscript_def
       || h->type != bfd_link_hash_defined)
     return;