--- old/usr/src/cmd/fm/fmadm/common/faulty.c	2016-02-25 15:39:32.842666456 -0500
+++ new/usr/src/cmd/fm/fmadm/common/faulty.c	2016-02-25 15:39:32.855453874 -0500
@@ -45,8 +45,7 @@
 #include <sys/smbios.h>
 #include <libdevinfo.h>
 #include <stdlib.h>
-
-#define	offsetof(s, m)	((size_t)(&(((s*)0)->m)))
+#include <stddef.h>
 
 /*
  * Fault records are added to catalog by calling add_fault_record_to_catalog()
--- old/usr/src/cmd/mdb/common/modules/ii/ii.c	2016-02-25 15:39:33.379530811 -0500
+++ new/usr/src/cmd/mdb/common/modules/ii/ii.c	2016-02-25 15:39:33.391901803 -0500
@@ -23,6 +23,8 @@
  * Use is subject to license terms.
  */
 
+#include <stddef.h>
+
 #include <sys/types.h>
 #include <sys/mdb_modapi.h>
 
@@ -36,8 +38,6 @@
 
 #include <sys/nsctl/nsvers.h>
 
-#define	offsetof(s, m)  ((size_t)(&((s *)0)->m))
-
 
 const mdb_bitmask_t bi_flags_bits[] = {
 	{ "DSW_GOLDEN", DSW_GOLDEN, DSW_GOLDEN },
--- old/usr/src/cmd/mdb/common/modules/libumem/misc.h	2016-02-25 15:39:33.828357573 -0500
+++ new/usr/src/cmd/mdb/common/modules/libumem/misc.h	2016-02-25 15:39:33.841248186 -0500
@@ -26,16 +26,13 @@
 #ifndef	_MDBMOD_MISC_H
 #define	_MDBMOD_MISC_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <mdb/mdb_modapi.h>
+#include <stddef.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#define	offsetof(s, m)	((size_t)(&(((s *)0)->m)))
-
 extern int umem_debug(uintptr_t, uint_t, int, const mdb_arg_t *);
 
 extern int umem_set_standalone(void);
--- old/usr/src/cmd/pools/poolstat/poolstat.c	2016-02-25 15:39:34.241276363 -0500
+++ new/usr/src/cmd/pools/poolstat/poolstat.c	2016-02-25 15:39:34.253736171 -0500
@@ -35,6 +35,7 @@
 #include <ctype.h>
 #include <limits.h>
 #include <errno.h>
+#include <stddef.h>
 
 #include <pool.h>
 #include "utils.h"
@@ -46,8 +47,6 @@
 #define	TEXT_DOMAIN	"SYS_TEST"
 #endif
 
-/* calculate offset of a particular element in a structure	*/
-#define	offsetof(s, m)  ((size_t)(&(((s *)0)->m)))
 #define	addrof(s)  ((char **)&(s))
 
 /* verify if a field is printable in respect of the current option flags */
--- old/usr/src/cmd/stat/common/acquire_iodevs.c	2016-02-25 15:39:34.776074100 -0500
+++ new/usr/src/cmd/stat/common/acquire_iodevs.c	2016-02-25 15:39:34.788750893 -0500
@@ -29,6 +29,7 @@
 #include <sys/dktp/fdisk.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <stddef.h>
 #include <unistd.h>
 #include <strings.h>
 #include <errno.h>
@@ -147,9 +148,6 @@
  * right position in the list. This index is an AVL tree of all the
  * iodev_snapshot in the list.
  */
-
-#define	offsetof(s, m)	(size_t)(&(((s *)0)->m))	/* for avl_create */
-
 static int
 avl_iodev_cmp(const void* is1, const void* is2)
 {
--- old/usr/src/common/nvpair/nvpair.c	2016-02-25 15:39:35.262264705 -0500
+++ new/usr/src/common/nvpair/nvpair.c	2016-02-25 15:39:35.275524461 -0500
@@ -36,16 +36,15 @@
 #include <sys/varargs.h>
 #include <sys/ddi.h>
 #include <sys/sunddi.h>
+#include <sys/sysmacros.h>
 #else
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
 #include <strings.h>
+#include <stddef.h>
 #endif
 
-#ifndef	offsetof
-#define	offsetof(s, m)		((size_t)(&(((s *)0)->m)))
-#endif
 #define	skip_whitespace(p)	while ((*(p) == ' ') || (*(p) == '\t')) p++
 
 /*
--- old/usr/src/head/iso/stddef_iso.h	2016-02-25 15:39:35.892334378 -0500
+++ new/usr/src/head/iso/stddef_iso.h	2016-02-25 15:39:35.904869104 -0500
@@ -80,11 +80,15 @@
 }
 #endif /* end of namespace std */
 
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
+#define	offsetof(s, m) __builtin_offsetof(s, m)
+#else
 #if __cplusplus >= 199711L
 #define	offsetof(s, m)  (std::size_t)(&(((s *)0)->m))
 #else
 #define	offsetof(s, m)  (size_t)(&(((s *)0)->m))
 #endif
+#endif	/* GNUC, etc. */
 
 #ifdef	__cplusplus
 }
--- old/usr/src/lib/libumem/common/misc.h	2016-02-25 15:39:36.333477420 -0500
+++ new/usr/src/lib/libumem/common/misc.h	2016-02-25 15:39:36.346134487 -0500
@@ -27,13 +27,12 @@
 #ifndef	_MISC_H
 #define	_MISC_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <sys/time.h>
 #include <thread.h>
 #include <pthread.h>
 #include <stdarg.h>
+#include <stddef.h>
 
 #ifdef	__cplusplus
 extern "C" {
@@ -45,14 +44,6 @@
 extern caddr_t umem_max_stack;		/* min stack address for audit log */
 
 /*
- * various utility functions
- * These are globally implemented.
- */
-
-#undef	offsetof
-#define	offsetof(s, m)	((size_t)(&(((s *)0)->m)))
-
-/*
  * a safe printf  -- do not use for error messages.
  */
 void debug_printf(const char *format, ...);
--- old/usr/src/lib/lvm/libmeta/common/meta_statconcise.c	2016-02-25 15:39:36.751463132 -0500
+++ new/usr/src/lib/lvm/libmeta/common/meta_statconcise.c	2016-02-25 15:39:36.764204377 -0500
@@ -23,8 +23,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <meta.h>
 #include <assert.h>
 #include <ctype.h>
@@ -32,6 +30,7 @@
 #include <meta.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stddef.h>
 #include <strings.h>
 #include <sys/lvm/md_mddb.h>
 #include <sys/lvm/md_names.h>
@@ -161,7 +160,6 @@
  */
 #define	MAXSIZEMDRECNAME	20
 #define	NAMEWIDTH		16
-#define	offsetof(s, m)	((size_t)(&(((s *)0)->m)))
 #define	NOT_PHYSICAL_DEV	0
 #define	PHYSICAL_DEV		1
 
--- old/usr/src/uts/common/avs/ns/rdc/rdc.c	2016-02-25 15:39:37.285212791 -0500
+++ new/usr/src/uts/common/avs/ns/rdc/rdc.c	2016-02-25 15:39:37.297593709 -0500
@@ -33,6 +33,7 @@
 #include <sys/modctl.h>
 #include <sys/cred.h>
 #include <sys/ddi.h>
+#include <sys/sysmacros.h>
 #include <sys/unistat/spcs_s.h>
 #include <sys/unistat/spcs_s_k.h>
 #include <sys/unistat/spcs_errors.h>
@@ -521,14 +522,6 @@
 	return (0);
 }
 
-
-/*
- * Yet another standard thing that is not standard ...
- */
-#ifndef	offsetof
-#define	offsetof(s, m)	((size_t)(&((s *)0)->m))
-#endif
-
 /*
  * Build a 32bit rdc_set structure and copyout to the user level.
  */
--- old/usr/src/uts/common/avs/ns/rdc/rdc_io.c	2016-02-25 15:39:37.766850449 -0500
+++ new/usr/src/uts/common/avs/ns/rdc/rdc_io.c	2016-02-25 15:39:37.780178736 -0500
@@ -29,6 +29,7 @@
 #include <sys/kmem.h>
 #include <sys/conf.h>
 #include <sys/errno.h>
+#include <sys/sysmacros.h>
 
 #ifdef _SunOS_5_6
 /*
@@ -5639,13 +5640,6 @@
 	return (rc);
 }
 
-/*
- * Yet another standard thing that is not standard ...
- */
-#ifndef offsetof
-#define	offsetof(s, m)	((size_t)(&((s *)0)->m))
-#endif
-
 static int
 rdc_status(void *arg, int mode, rdc_config_t *uparms, spcs_s_info_t kstatus)
 {
--- old/usr/src/uts/common/avs/ns/sv/sv.c	2016-02-25 15:39:38.645496013 -0500
+++ new/usr/src/uts/common/avs/ns/sv/sv.c	2016-02-25 15:39:38.658500095 -0500
@@ -74,6 +74,7 @@
 #include <sys/cmn_err.h>
 #include <sys/modctl.h>
 #include <sys/ddi.h>
+#include <sys/sysmacros.h>
 #include <sys/sunddi.h>
 #include <sys/sunldi.h>
 #include <sys/nsctl/nsvers.h>
@@ -2415,11 +2416,6 @@
 	return (0);
 }
 
-
-#ifndef offsetof
-#define	offsetof(s, m)	((size_t)(&((s *)0)->m))
-#endif
-
 /*
  * re-write the size of the current partition
  */
--- old/usr/src/uts/common/inet/ipf/netinet/ip_fil.h	2016-02-25 15:39:39.249012813 -0500
+++ new/usr/src/uts/common/inet/ipf/netinet/ip_fil.h	2016-02-25 15:39:39.261767409 -0500
@@ -672,9 +672,6 @@
 
 #define	FR_NOLOGTAG	0
 
-#ifndef	offsetof
-#define	offsetof(t,m)	(size_t)((&((t *)0)->m))
-#endif
 #define	FR_CMPSIZ	(sizeof(struct frentry) - \
 			 offsetof(struct frentry, fr_func))
 
--- old/usr/src/uts/common/io/drm/drmP.h	2016-02-25 15:39:39.876471141 -0500
+++ new/usr/src/uts/common/io/drm/drmP.h	2016-02-25 15:39:39.889424313 -0500
@@ -56,6 +56,7 @@
 #include <sys/pmem.h>
 #include <sys/agpgart.h>
 #include <sys/time.h>
+#include <sys/sysmacros.h>
 #include "drm_atomic.h"
 #include "drm.h"
 #include "queue.h"
--- old/usr/src/uts/common/io/sfe/sfe_util.c	2016-02-25 15:39:40.363034087 -0500
+++ new/usr/src/uts/common/io/sfe/sfe_util.c	2016-02-25 15:39:40.376511942 -0500
@@ -52,6 +52,7 @@
 #include <sys/stream.h>		/* required for MBLK* */
 #include <sys/strsun.h>		/* required for mionack() */
 #include <sys/byteorder.h>
+#include <sys/sysmacros.h>
 #include <sys/pci.h>
 #include <inet/common.h>
 #include <inet/led.h>
@@ -107,9 +108,6 @@
 #define	GET_TXBUF(dp, sn)	\
 	&(dp)->tx_buf[SLOT((dp)->tx_slots_base + (sn), (dp)->gc.gc_tx_buf_size)]
 
-#ifndef offsetof
-#define	offsetof(t, m)	((long)&(((t *) 0)->m))
-#endif
 #define	TXFLAG_VTAG(flag)	\
 	(((flag) & GEM_TXFLAG_VTAG) >> GEM_TXFLAG_VTAG_SHIFT)
 
--- old/usr/src/uts/common/io/vscan/vscan_svc.c	2016-02-25 15:39:41.132938289 -0500
+++ new/usr/src/uts/common/io/vscan/vscan_svc.c	2016-02-25 15:39:41.145789368 -0500
@@ -41,6 +41,7 @@
 #include <sys/cred.h>
 #include <sys/list.h>
 #include <sys/vscan.h>
+#include <sys/sysmacros.h>
 
 #define	VS_REQ_MAGIC		0x52515354 /* 'RQST' */
 
@@ -57,7 +58,6 @@
 #define	VS_ACCESS_DENY		2	/* return EACCES */
 
 #define	tolower(C)	(((C) >= 'A' && (C) <= 'Z') ? (C) - 'A' + 'a' : (C))
-#define	offsetof(s, m)	(size_t)(&(((s *)0)->m))
 
 /* global variables - tunable via /etc/system */
 uint32_t vs_reqs_max = VS_REQS_DEFAULT;	/* max scan requests */
--- old/usr/src/uts/common/sys/ecppvar.h	2016-02-25 15:39:41.632259775 -0500
+++ new/usr/src/uts/common/sys/ecppvar.h	2016-02-25 15:39:41.644734688 -0500
@@ -28,6 +28,7 @@
 #define	_SYS_ECPPVAR_H
 
 #include <sys/note.h>
+#include <sys/sysmacros.h>
 
 #ifdef	__cplusplus
 extern "C" {
@@ -513,7 +514,6 @@
  * Other useful macros
  */
 #define	NELEM(a)	(sizeof (a) / sizeof (*(a)))
-#define	offsetof(s, m)	((size_t)(&(((s *)0)->m)))
 
 #ifdef	__cplusplus
 }
--- old/usr/src/uts/common/sys/ib/clients/of/sol_ofs/sol_cma.h	2016-02-25 15:39:42.083231088 -0500
+++ new/usr/src/uts/common/sys/ib/clients/of/sol_ofs/sol_cma.h	2016-02-25 15:39:42.095815074 -0500
@@ -30,14 +30,12 @@
 extern "C" {
 #endif
 
+#include <sys/sysmacros.h>
 
 #include <sys/ib/clients/of/sol_ofs/sol_ofs_common.h>
 #include <sys/ib/clients/of/rdma/rdma_cm.h>
 #include <sys/ib/clients/of/sol_ofs/sol_ib_cma.h> /* Transport Specific */
 
-#if !defined(offsetof)
-#define	offsetof(s, m)		(size_t)(&(((s *)0)->m))
-#endif
 
 #define	IS_UDP_CMID(idp)	((idp)->ps == RDMA_PS_UDP || \
 	(idp)->ps == RDMA_PS_IPOIB)
--- old/usr/src/uts/common/sys/sysmacros.h	2016-02-25 15:39:42.563482703 -0500
+++ new/usr/src/uts/common/sys/sysmacros.h	2016-02-25 15:39:42.575946815 -0500
@@ -370,7 +370,11 @@
 #if (defined(_KERNEL) || defined(_FAKE_KERNEL)) && !defined(_KMEMUSER)
 
 #if !defined(offsetof)
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
+#define	offsetof(s, m) __builtin_offsetof(s, m)
+#else
 #define	offsetof(s, m)	((size_t)(&(((s *)0)->m)))
+#endif
 #endif /* !offsetof */
 
 #define	container_of(m, s, name)			\
--- old/usr/src/uts/common/sys/usb/clients/audio/usb_ac/usb_ac.h	2016-02-25 15:39:42.995686303 -0500
+++ new/usr/src/uts/common/sys/usb/clients/audio/usb_ac/usb_ac.h	2016-02-25 15:39:43.010131719 -0500
@@ -33,6 +33,7 @@
 #endif
 
 #include <sys/sunldi.h>
+#include <sys/sysmacros.h>
 #include <sys/usb/usba/usbai_private.h>
 
 
@@ -329,14 +330,6 @@
 #define	USB_AH_PLUMBED	2
 #define	UNKNOWN_PLUMBED	3
 
-/* other useful macros */
-#define	offsetof(s, m)	((size_t)(&(((s *)0)->m)))
-
-
-
-
-
-
 #define	AF_REGISTERED	0x1
 #define	AD_SETUP	0x10
 
--- old/usr/src/uts/common/sys/usb/clients/video/usbvc/usbvc_var.h	2016-02-25 15:39:43.432265192 -0500
+++ new/usr/src/uts/common/sys/usb/clients/video/usbvc/usbvc_var.h	2016-02-25 15:39:43.444981693 -0500
@@ -32,6 +32,7 @@
 #endif
 
 #include <sys/list.h>
+#include <sys/sysmacros.h>
 #include <sys/usb/usba/usbai_private.h>
 #include <sys/videodev2.h>
 #include <sys/usb/clients/video/usbvc/usbvc.h>
@@ -173,8 +174,6 @@
 #define	PRINT_MASK_DEVMAP	0x00000200
 #define	PRINT_MASK_ALL		0xFFFFFFFF
 
-#define	offsetof(s, m)	((size_t)(&(((s *)0)->m)))
-
 #define	USBVC_MAX_PKTS 40
 
 #define	USBVC_DEFAULT_READ_BUF_NUM 3
--- old/usr/src/uts/common/xen/io/xnb.h	2016-02-25 15:39:43.863779302 -0500
+++ new/usr/src/uts/common/xen/io/xnb.h	2016-02-25 15:39:43.876261242 -0500
@@ -34,14 +34,15 @@
 #include <sys/stream.h>
 #include <sys/ethernet.h>
 #include <sys/hypervisor.h>
+#include <sys/sysmacros.h>
 #include <xen/public/io/netif.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#define	NET_TX_RING_SIZE  __RING_SIZE((netif_tx_sring_t *)0, PAGESIZE)
-#define	NET_RX_RING_SIZE  __RING_SIZE((netif_rx_sring_t *)0, PAGESIZE)
+#define	NET_TX_RING_SIZE  __CONST_RING_SIZE(netif_tx, PAGESIZE)
+#define	NET_RX_RING_SIZE  __CONST_RING_SIZE(netif_rx, PAGESIZE)
 
 #define	XNBMAXPKT	1500		/* MTU size */
 
--- old/usr/src/uts/common/xen/io/xnf.h	2016-02-25 15:39:44.305244210 -0500
+++ new/usr/src/uts/common/xen/io/xnf.h	2016-02-25 15:39:44.317654337 -0500
@@ -31,8 +31,8 @@
 extern "C" {
 #endif
 
-#define	NET_TX_RING_SIZE  __RING_SIZE((netif_tx_sring_t *)0, PAGESIZE)
-#define	NET_RX_RING_SIZE  __RING_SIZE((netif_rx_sring_t *)0, PAGESIZE)
+#define	NET_TX_RING_SIZE  __CONST_RING_SIZE(netif_tx, PAGESIZE)
+#define	NET_RX_RING_SIZE  __CONST_RING_SIZE(netif_rx, PAGESIZE)
 
 #define	XNF_MAXPKT	1500		/* MTU size */
 #define	XNF_FRAMESIZE	1514		/* frame size including MAC header */
--- old/usr/src/uts/common/xen/public/io/ring.h	2016-02-25 15:39:44.837053431 -0500
+++ new/usr/src/uts/common/xen/public/io/ring.h	2016-02-25 15:39:44.849717932 -0500
@@ -47,9 +47,15 @@
 /*
  * Calculate size of a shared ring, given the total available space for the
  * ring and indexes (_sz), and the name tag of the request/response structure.
- * A ring contains as many entries as will fit, rounded down to the nearest 
+ * A ring contains as many entries as will fit, rounded down to the nearest
  * power of two (so we can mask with (size-1) to loop around).
  */
+#define __CONST_RING_SIZE(_s, _sz) \
+    (__RD32(((_sz) - offsetof(struct _s##_sring, ring)) / \
+       sizeof(((struct _s##_sring *)0)->ring[0])))
+/*
+ * The same for passing in an actual pointer instead of a name tag.
+ */
 #define __RING_SIZE(_s, _sz) \
     (__RD32(((_sz) - (long)(_s)->ring + (long)(_s)) / sizeof((_s)->ring[0])))
 
--- old/usr/src/uts/sun/io/scsi/adapters/sf.c	2016-02-25 15:39:45.279468009 -0500
+++ new/usr/src/uts/sun/io/scsi/adapters/sf.c	2016-02-25 15:39:45.292871217 -0500
@@ -56,9 +56,6 @@
 
 static int sf_bus_config_debug = 0;
 
-/* Why do I have to do this? */
-#define	offsetof(s, m)  (size_t)(&(((s *)0)->m))
-
 #include <sys/scsi/scsi.h>
 #include <sys/fc4/fcal.h>
 #include <sys/fc4/fcp.h>
@@ -77,6 +74,7 @@
 #include <sys/devctl.h>
 #include <sys/scsi/targets/ses.h>
 #include <sys/callb.h>
+#include <sys/sysmacros.h>
 
 static int sf_info(dev_info_t *, ddi_info_cmd_t, void *, void **);
 static int sf_attach(dev_info_t *, ddi_attach_cmd_t);
--- old/usr/src/uts/sun4u/io/rmclomv.c	2016-02-25 15:39:46.224435262 -0500
+++ new/usr/src/uts/sun4u/io/rmclomv.c	2016-02-25 15:39:46.237309434 -0500
@@ -52,8 +52,8 @@
 #include <sys/ddi.h>
 #include <sys/time.h>
 #include <sys/promif.h>
+#include <sys/sysmacros.h>
 
-#define	offsetof(s, m)	(size_t)(&(((s *)0)->m))
 #define	RMCRESBUFLEN	1024
 #define	DATE_TIME_MSG_SIZE	78
 #define	RMCLOMV_WATCHDOG_MODE	"rmclomv-watchdog-mode"
