Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 1 Jan 2018 20:39:13 +0000 (UTC)
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r327471 - in stable: 10/contrib/binutils/bfd 10/contrib/binutils/include 11/contrib/binutils/bfd 11/contrib/binutils/include 9/contrib/binutils/bfd 9/contrib/binutils/include
Message-ID:  <201801012039.w01KdDE0035819@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dim
Date: Mon Jan  1 20:39:12 2018
New Revision: 327471
URL: https://svnweb.freebsd.org/changeset/base/327471

Log:
  MFC r327164:
  
  Fix clang 6.0.0 compiler warnings in binutils
  
  Latest clang git has a warning -Wnull-pointer-arithmetic which will
  trigger a -Werror failure. Addition and subtraction from a null pointer
  is undefined behaviour and could be optimized into anything.
  
  Furthermore, using the difference between two pointers and casting the
  result back to a pointer is not portable since the size of ptrdiff_t
  does not necessary have to be the same as size of void* (this happens
  e.g. on CHERI). Using intptr_t instead fixes this portability issue and
  the compiler warning.
  
  Submitted by;	Alexander Richardson
  Obtained from:	CheriBSD
  Differential Revision: https://reviews.freebsd.org/D12928

Modified:
  stable/11/contrib/binutils/bfd/elflink.c
  stable/11/contrib/binutils/include/obstack.h
Directory Properties:
  stable/11/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/10/contrib/binutils/bfd/elflink.c
  stable/10/contrib/binutils/include/obstack.h
  stable/9/contrib/binutils/bfd/elflink.c
  stable/9/contrib/binutils/include/obstack.h
Directory Properties:
  stable/10/   (props changed)
  stable/9/   (props changed)
  stable/9/contrib/   (props changed)
  stable/9/contrib/binutils/   (props changed)

Modified: stable/11/contrib/binutils/bfd/elflink.c
==============================================================================
--- stable/11/contrib/binutils/bfd/elflink.c	Mon Jan  1 20:24:16 2018	(r327470)
+++ stable/11/contrib/binutils/bfd/elflink.c	Mon Jan  1 20:39:12 2018	(r327471)
@@ -4815,7 +4815,7 @@ _bfd_elf_archive_symbol_lookup (bfd *abfd,
   len = strlen (name);
   copy = bfd_alloc (abfd, len);
   if (copy == NULL)
-    return (struct elf_link_hash_entry *) 0 - 1;
+    return (struct elf_link_hash_entry *)(intptr_t)-1;
 
   first = p - name + 1;
   memcpy (copy, name, first);
@@ -4927,7 +4927,7 @@ elf_link_add_archive_symbols (bfd *abfd, struct bfd_li
 	    }
 
 	  h = archive_symbol_lookup (abfd, info, symdef->name);
-	  if (h == (struct elf_link_hash_entry *) 0 - 1)
+	  if (h == (struct elf_link_hash_entry *)(intptr_t)-1)
 	    goto error_return;
 
 	  if (h == NULL)

Modified: stable/11/contrib/binutils/include/obstack.h
==============================================================================
--- stable/11/contrib/binutils/include/obstack.h	Mon Jan  1 20:24:16 2018	(r327470)
+++ stable/11/contrib/binutils/include/obstack.h	Mon Jan  1 20:39:12 2018	(r327471)
@@ -119,11 +119,11 @@ extern "C" {
    may ignore the byte-within-word field of the pointer.  */
 
 #ifndef __PTR_TO_INT
-# define __PTR_TO_INT(P) ((P) - (char *) 0)
+# define __PTR_TO_INT(P) ((intptr_t)(P))
 #endif
 
 #ifndef __INT_TO_PTR
-# define __INT_TO_PTR(P) ((P) + (char *) 0)
+# define __INT_TO_PTR(P) ((void*)(intptr_t)(P))
 #endif
 
 /* We need the type of the resulting object.  If __PTRDIFF_TYPE__ is
@@ -427,7 +427,7 @@ __extension__								\
      __o1->maybe_empty_object = 1;					\
    __o1->next_free							\
      = __INT_TO_PTR ((__PTR_TO_INT (__o1->next_free)+__o1->alignment_mask)\
-		     & ~ (__o1->alignment_mask));			\
+		     & ~(intptr_t)(__o1->alignment_mask));			\
    if (__o1->next_free - (char *)__o1->chunk				\
        > __o1->chunk_limit - (char *)__o1->chunk)			\
      __o1->next_free = __o1->chunk_limit;				\



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801012039.w01KdDE0035819>