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

Alan Modra amodra@gmail.com
Mon Jan 27 07:18:00 GMT 2020


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



More information about the Binutils mailing list