Project

General

Profile

Bug #8007

want sys/stddef.h for offsetof and container_of macros

Added by Toomas Soome over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
kernel
Start date:
2017-03-28
Due date:
% Done:

100%

Estimated time:
Difficulty:
Bite-size
Tags:
Gerrit CR:

Description

The current uts/common/sys/sysmacros.h does attempt to protect offsetof() and container_of() macros from getting exposed to userland stddef.h by using construct:

#if (defined(_KERNEL) || defined(_FAKE_KERNEL)) && !defined(_KMEMUSER)
..
#endif

However, the i86pc and i86xpv dboot is built with -D_BOOT -D_KMEMUSER -U_KERNEL and is therefore excluded from offsetof() and container_of() macros. To solve this issue, we need to update the conditional expression.

History

#1

Updated by Toomas Soome over 3 years ago

Sample error case from building dboot bits:

+ /opt/gcc/4.4.4/bin/gcc -fident -finline -fno-inline-functions -fno-builtin -fno-asm -fdiagnostics-show-option -nodefaultlibs -D__sun -Wall -Wextra -std=gnu99 -Werror -Wno-missing-braces -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused -Wno-empty-body -Wno-parentheses -Wno-uninitialized -Wno-char-subscripts -Wno-unused-variable -Wno-unused-function -Wno-unused-label -Wno-type-limits -Wno-clobbered -Wno-empty-body -Wno-unused-value -fno-inline-small-functions -fno-inline-functions-called-once -fno-ipa-cp -O -D_BOOT -ffreestanding -D_BOOT_TARGET_amd64 -D_MACHDEP -D_KMEMUSER -U_KERNEL -D_I32LPx -I/code/illumos-gate/usr/src/common -I/code/illumos-gate/usr/src/common/util -I../../i86pc -I/code/illumos-gate/usr/src/common -I../../i86xpv -I../../common/xen -I../../intel -nostdinc -I../../common -c -o dboot/obj64/dboot_multiboot2.o ../../i86pc/dboot/dboot_multiboot2.c 
cc1: warnings being treated as errors
../../i86pc/dboot/dboot_multiboot2.c: In function 'dboot_multiboot2_mmap_nentries':
../../i86pc/dboot/dboot_multiboot2.c:329: error: implicit declaration of function 'offsetof' [-Wimplicit-function-declaration]
../../i86pc/dboot/dboot_multiboot2.c:329: error: expected expression before 'multiboot_tag_mmap_t'
*** Error code 1
dmake: Fatal error: Command failed for target `dboot/obj64/dboot_multiboot2.o'
Current working directory /code/illumos-gate/usr/src/uts/i86pc/unix
*** Error code 1
#2

Updated by Toomas Soome over 3 years ago

  • Subject changed from uts: sysmacros.h should allow offsetof for early boot to need sys/sysdef.h for offsetof and container_of macros

So far the idea has developed to:

Create sys/sysdef.h, move offsetof and container_of macros from sys/sysmacros.h to it, and remove offsetof from iso/stddef_iso.h. include sys/sysdef.h from both head/sysdef.h and sys/sysmacros.h.

Since we provide the same definition, in guarded header, we will not get into the conflicts, and we get a bit cleaned up headers in return.

#3

Updated by Gordon Ross over 3 years ago

  • Subject changed from need sys/sysdef.h for offsetof and container_of macros to want sys/stddef.h for offsetof and container_of macros
#4

Updated by Andrew Stormont over 3 years ago

Why don't we put stuff in stddef.h like the spec says?
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/stddef.h.html

#5

Updated by Toomas Soome over 3 years ago

Andrew Stormont wrote:

Why don't we put stuff in stddef.h like the spec says?
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/stddef.h.html

The #include <stddef.h> (usr/src/head/stddef.h) does provide many (all?) of them, however, if we should move some to sys/stddef.h or not - I think it is separate issue and entirely open for discussions.

#6

Updated by Electric Monk over 3 years ago

  • Status changed from In Progress to Closed
  • % Done changed from 90 to 100

git commit ff7af0d3beb1bddf8bb93afc2e9042dc3828be3d

commit  ff7af0d3beb1bddf8bb93afc2e9042dc3828be3d
Author: Toomas Soome <tsoome@me.com>
Date:   2017-04-24T08:36:11.000Z

    8007 want sys/stddef.h for offsetof and container_of macros
    Reviewed by: Gordon Ross <gordon.w.ross@gmail.com>
    Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
    Reviewed by: Andrew Stormont <andyjstormont@gmail.com>
    Reviewed by: Dan McDonald <danmcd@omniti.com>
    Reviewed by: Yuri Pankov <yuri.pankov@gmail.com>
    Approved by: Hans Rosenfeld <hans.rosenfeld@joyent.com>

#7

Updated by Electric Monk over 3 years ago

git commit 6175f5a92a3a312be8142de7390d92df1d05bd75

commit  6175f5a92a3a312be8142de7390d92df1d05bd75
Author: Toomas Soome <tsoome@me.com>
Date:   2017-04-26T10:44:35.000Z

    8007 want sys/stddef.h for offsetof and container_of macros (fix container_of visibility)
    Reviewed by: Igor Kozhukhov <igor@dilos.org>
    Reviewed by: Adam Stevko <adam.stevko@gmail.com>
    Reviewed by: Joshua M. Clulow <josh@sysmgr.org>
    Approved by: Joshua M. Clulow <josh@sysmgr.org>

Also available in: Atom PDF