Bug 103436

Summary: Compiler or options invalid; UNIX 03 and POSIX.1-2001 applications
Product: p11-glue Reporter: Jeffrey Walton <noloader>
Component: p11-kitAssignee: Stef Walter <stefw>
Status: NEW --- QA Contact:
Severity: normal    
Priority: medium CC: noloader
Version: unspecified   
Hardware: x86-64 (AMD64)   
OS: Solaris   
Whiteboard:
i915 platform: i915 features:

Description Jeffrey Walton 2017-10-24 17:27:59 UTC
I'm working through a Solaris compile. Solaris is a good platform to test on because it often highlights areas where GCC and glibc run a bit fast and loose.

It looks like a flag may be needed for Solaris (-std=c99), and a few standard headers are missing in some source files.

I tried to add -std=c99 to CFLAGS before configuring, but the flag was not picked-up by Autotool's configure.

As far as the missing sentinel, see https://stackoverflow.com/q/2407605/608639. I was not aware it was a transgression.


****************************************

  ...
  CC       common/compat.lo
  CC       common/constants.lo
  CC       common/debug.lo
  CC       common/dict.lo
common/compat.c: In function 'p11_mutex_init':
common/compat.c:170:6: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
  int ret;
      ^
common/compat.c: In function 'p11_dl_error':
common/compat.c:183:2: warning: implicit declaration of function 'strdup' [-Wimplicit-function-declaration]
  return msg ? strdup (msg) : NULL;
  ^
common/compat.c:183:15: warning: incompatible implicit declaration of built-in function 'strdup' [enabled by default]
  return msg ? strdup (msg) : NULL;
               ^
common/compat.c: In function 'getauxval':
common/compat.c:789:3: warning: implicit declaration of function 'issetugid' [-Wimplicit-function-declaration]
   secure = issetugid ();
   ^
common/compat.c:789:3: warning: nested extern declaration of 'issetugid' [-Wnested-externs]
  CC       common/hash.lo
  CC       common/lexer.lo
common/dict.c: In function 'p11_dict_str_hash':
common/dict.c:332:2: warning: missing sentinel in function call [-Wformat=]
  p11_hash_murmur3 (&hash, string, strlen (string), NULL);
  ^
  CC       common/message.lo
  CC       common/path.lo
  CC       common/url.lo
In file included from /usr/include/sys/types.h:12:0,
                 from common/compat.h:40,
                 from common/message.c:46:
/usr/include/sys/feature_tests.h:358:2: error: #error "Compiler or options invalid; UNIX 03 and POSIX.1-2001 applications       require the use of c99"
 #error "Compiler or options invalid; UNIX 03 and POSIX.1-2001 applications \
  ^
  CC       common/library.lo
gmake[2]: *** [common/message.lo] Error 1
gmake[2]: *** Waiting for unfinished jobs....
common/path.c: In function 'expand_homedir':
common/path.c:125:4: warning: missing sentinel in function call [-Wformat=]
    return p11_path_build (env, remainder + 8, NULL);
    ^
common/path.c:130:3: warning: missing sentinel in function call [-Wformat=]
   return p11_path_build (env, remainder, NULL);
   ^
common/path.c:141:3: error: too many arguments to function 'getpwuid_r'
   ret = getpwuid_r (getuid (), &pws, buf, sizeof (buf), &pwd);
   ^
In file included from common/path.c:52:0:
/usr/include/pwd.h:167:23: note: declared here
 extern struct passwd *getpwuid_r(uid_t, struct passwd *, char *, int);
                       ^
common/path.c:141:7: warning: assignment makes integer from pointer without a cast [enabled by default]
   ret = getpwuid_r (getuid (), &pws, buf, sizeof (buf), &pwd);
       ^
common/path.c:152:3: warning: missing sentinel in function call [-Wformat=]
   return p11_path_build (pwd->pw_dir, remainder, NULL);
   ^
Comment 1 Jeffrey Walton 2017-10-24 17:42:09 UTC
Here's the relevant portion of `cat -n /usr/include/sys/feature_tests.h`:

   346  /*
   347   * It is invalid to compile an XPG3, XPG4, XPG4v2, or XPG5 application
   348   * using c99.  The same is true for POSIX.1-1990, POSIX.2-1992, POSIX.1b,
   349   * and POSIX.1c applications. Likewise, it is invalid to compile an XPG6
   350   * or a POSIX.1-2001 application with anything other than a c99 or later
   351   * compiler.  Therefore, we force an error in both cases.
   352   */
   353  #if defined(_STDC_C99) && (defined(__XOPEN_OR_POSIX) && !defined(_XPG6))
   354  #error "Compiler or options invalid for pre-UNIX 03 X/Open applications \
   355          and pre-2001 POSIX applications"
   356  #elif !defined(_STDC_C99) && \
   357          (defined(__XOPEN_OR_POSIX) && defined(_XPG6))
   358  #error "Compiler or options invalid; UNIX 03 and POSIX.1-2001 applications \
   359          require the use of c99"
   360  #endif
Comment 2 Jeffrey Walton 2017-10-25 00:58:07 UTC
(In reply to Jeffrey Walton from comment #0)
> I'm working through a Solaris compile. Solaris is a good platform to test on
> because it often highlights areas where GCC and glibc run a bit fast and
> loose.
> 
> It looks like a flag may be needed for Solaris (-std=c99), and a few
> standard headers are missing in some source files.

Well, the C99 part was wrong. The program did not need -std=c99 because GCC already defines it. The problem was the _XOPEN_SOURCE macro in compat.c.

The is fixed the `#pragma error ...` stops. It was run after unpacking the tarball.

# On Solaris the script puts /usr/gnu/bin on-path, so we get a useful grep
if [[ "$IS_SOLARIS" -ne "0" ]]; then
    files=$(grep -IR '#define _XOPEN_SOURCE' "$PWD" | cut -f 1 -d ':')
	if [[ ! -z "$files" ]]; then
        echo "$files" | xargs sed -i '/#define _XOPEN_SOURCE/d'
    fi
fi

The getpwuid issue is still outstanding. Solaris is very Posixy, so this is the `getpwuid_r` it provides: http://pubs.opengroup.org/onlinepubs/000095399/functions/getpwnam.html .
Comment 3 Jeffrey Walton 2017-10-25 01:32:37 UTC
(In reply to Jeffrey Walton from comment #2)
> (In reply to Jeffrey Walton from comment #0)
> > I'm working through a Solaris compile. Solaris is a good platform to test on
> > because it often highlights areas where GCC and glibc run a bit fast and
> > loose.
> > 
> > ...
> 
> The getpwuid issue is still outstanding. Solaris is very Posixy, so this is
> the `getpwuid_r` it provides:
> http://pubs.opengroup.org/onlinepubs/000095399/functions/getpwnam.html .

OK, here's the second part of the compile failures. This clears all the compile errors.

To clear the `getpwuid_r` issue, you need to add -D_XOPEN_SORCE=500 to CPPFLAGS before configuration. It avoids the earlier compile problem while making the proper symbols available.

My script to drive things looks like so. The OPT_* arrays are what you would expect from a Bash shell script.

if [[ "$IS_SOLARIS" -ne "0" ]]; then
    OPT_CPPFLAGS+=("-D_XOPEN_SOURCE=500")
fi

    PKG_CONFIG_PATH="${OPT_PKGCONFIG[*]}" \
    CPPFLAGS="${OPT_CPPFLAGS[*]}" \
    CFLAGS="${OPT_CFLAGS[*]}" \
    CXXFLAGS="${OPT_CXXFLAGS[*]}" \
    LDFLAGS="${OPT_LDFLAGS[*]}" \
    LIBS="${OPT_LIBS[*]}" \
./configure "${P11KIT_CONFIG_OPTIONS[@]}"

# On Solaris the script puts /usr/gnu/bin on-path, so we get a useful grep
if [[ "$IS_SOLARIS" -ne "0" ]]; then
	for file in $(grep -IR '#define _XOPEN_SOURCE' "$PWD" | cut -f 1 -d ':' | sort | uniq); do
        echo "Fixing $file"
        sed -i '/#define _XOPEN_SOURCE/d' "$file"
    done
fi

I've got problems reduced to a link error. I'll open a separate bug report for it.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.