2
votes

++=UPDATE 1=++ Running through with -E returns the following:

# 100 "/usr/include/sys/byteorder.h" 3
#define BSWAP_64(x) (((uint64_t)(x) << 56) | (((uint64_t)(x) << 40) & 0xff000000000000ULL) | (((uint64_t)(x) << 24) & 0xff0000000000ULL) | (((uint64_t)(x) << 8) & 0xff00000000ULL) | (((uint64_t)(x) >> 8) & 0xff000000ULL) | (((uint64_t)(x) >> 24) & 0xff0000ULL) | (((uint64_t)(x) >> 40) & 0xff00ULL) | ((uint64_t)(x) >> 56))
...
#define _LP64 1
...
# 86 "LALCityHash.c" 2
#define bswap_32(x) BSWAP_32(x)
#define bswap_64(x) BSWAP_64(x)
# 117 "LALCityHash.c"
#define UINT4_in_expected_order(x) (bswap_32(x))
#define UINT8_in_expected_order(x) (bswap_64(x))

It appears to make it through the CPP.

Full content at https://pastebin.com/u6VU9sie

LALCityHash.c source at https://pastebin.com/GfQ3CxBX

--=UPDATE 1=--

I am compiling LIGO software packages for SPARC/Solaris and run into errors. LALCityHash.c provides an alias for BSWAP_64 which doesn't seem to be getting through with the necessary #includes provided in the unmodified code.

I have tried to see if redefining the defines elsewhere helps just in case the "#if defined(__sun) || defined(sun)" lines are not being parsed. Even stripping out the .h includes using the required code locally to the file does not work. I just can't figure out what I am overlooking.

The LALCityHash.c includes the following lines:

#elif defined(__sun) || defined(sun)

#define bswap_32(x) BSWAP_32(x)
:87 =>  #define bswap_64(x) BSWAP_64(x) <=
...
:118 => #define UINT8_in_expected_order(x) (bswap_64(x)) <=
...
static UINT8 Fetch64(const char *p) {
:133 =>   return UINT8_in_expected_order(UNALIGNED_LOAD64(p)); <=
}


Produces both errors below:

implicit declaration of function 'BSWAP_64'
nested extern declaration of 'BSWAP_64'

The OS include file for Solaris is sys/byteorder.h and is defined as the following:

#if defined(_LP64) || defined(_LONGLONG_TYPE)
#if (!defined(__i386) && !defined(__amd64))
#define BSWAP_64(x) (((uint64_t)(x) << 56) | \
            (((uint64_t)(x) << 40) & 0xff000000000000ULL) | \
            (((uint64_t)(x) << 24) & 0xff0000000000ULL) | \
            (((uint64_t)(x) << 8)  & 0xff00000000ULL) | \
            (((uint64_t)(x) >> 8)  & 0xff000000ULL) | \
            (((uint64_t)(x) >> 24) & 0xff0000ULL) | \
            (((uint64_t)(x) >> 40) & 0xff00ULL) | \
            ((uint64_t)(x)  >> 56))
#else /* x86 */
#define BSWAP_64(x) htonll(x)
#endif  /* !__i386 && !__amd64 */
#else /* no uint64_t */
#define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32))
#endif  /* _LP64 || _LONGLONG_TYPE  */
Making all in utilities
gmake[4]: Entering directory '/export/home/tidytibs/ligo/lal-6.19.2/src/utilities'
  CC       LALCityHash.lo
LALCityHash.c: In function 'Fetch64':
LALCityHash.c:87:21: error: implicit declaration of function 'BSWAP_64' [-Werror=implicit-function-declaration]
 #define bswap_64(x) BSWAP_64(x)
                     ^
LALCityHash.c:118:37: note: in expansion of macro 'bswap_64'
 #define UINT8_in_expected_order(x) (bswap_64(x))
                                     ^~~~~~~~
LALCityHash.c:133:10: note: in expansion of macro 'UINT8_in_expected_order'
   return UINT8_in_expected_order(UNALIGNED_LOAD64(p));
          ^~~~~~~~~~~~~~~~~~~~~~~
LALCityHash.c:87:21: error: nested extern declaration of 'BSWAP_64' [-Werror=nested-externs]
 #define bswap_64(x) BSWAP_64(x)
                     ^
LALCityHash.c:118:37: note: in expansion of macro 'bswap_64'
 #define UINT8_in_expected_order(x) (bswap_64(x))
                                     ^~~~~~~~
LALCityHash.c:133:10: note: in expansion of macro 'UINT8_in_expected_order'
   return UINT8_in_expected_order(UNALIGNED_LOAD64(p));
          ^~~~~~~~~~~~~~~~~~~~~~~
LALCityHash.c: In function 'Fetch32':
LALCityHash.c:86:21: error: implicit declaration of function 'BSWAP_32' [-Werror=implicit-function-declaration]
 #define bswap_32(x) BSWAP_32(x)
                     ^
LALCityHash.c:117:37: note: in expansion of macro 'bswap_32'
 #define UINT4_in_expected_order(x) (bswap_32(x))
                                     ^~~~~~~~
LALCityHash.c:137:10: note: in expansion of macro 'UINT4_in_expected_order'
   return UINT4_in_expected_order(UNALIGNED_LOAD32(p));
          ^~~~~~~~~~~~~~~~~~~~~~~
LALCityHash.c:86:21: error: nested extern declaration of 'BSWAP_32' [-Werror=nested-externs]
 #define bswap_32(x) BSWAP_32(x)
                     ^
LALCityHash.c:117:37: note: in expansion of macro 'bswap_32'
 #define UINT4_in_expected_order(x) (bswap_32(x))
                                     ^~~~~~~~
LALCityHash.c:137:10: note: in expansion of macro 'UINT4_in_expected_order'
   return UINT4_in_expected_order(UNALIGNED_LOAD32(p));
          ^~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
gmake[4]: *** [Makefile:586: LALCityHash.lo] Error 1
1
The first step when dealing with macro-related compiler errors would be to run the code through preprocessor and analyze output. Often error becomes evident. - SergeyA
That code won't define BSWAP_64 unless #if defined(_LP64) || defined(_LONGLONG_TYPE). So maybe on your system, those are not defined. I don't have enough information to suggest anything about BSWAP_32 - rici
I'll update to refine and add comment requested information - nkulowiec
Are you sure byteorder.h is included? - danadam

1 Answers

1
votes

Solved: It appears that LALCityHash.c includes the Solaris sys/byteorder.h which has a define of

#define BSWAP_32(x) (((uint32_t)(x) << 24) | (((uint32_t)(x) << 8) & 0xff0000) | (((uint32_t)(x) >> 8) & 0xff00) | ((uint32_t)(x) >> 24))
#define BSWAP_64(x) (((uint64_t)(x) << 56) | (((uint64_t)(x) << 40) & 0xff000000000000ULL) | (((uint64_t)(x) << 24) & 0xff0000000000ULL) | (((uint64_t)(x) << 8) & 0xff00000000ULL) | (((uint64_t)(x) >> 8) & 0xff000000ULL) | (((uint64_t)(x) >> 24) & 0xff0000ULL) | (((uint64_t)(x) >> 40) & 0xff00ULL) | ((uint64_t)(x) >> 56))

and does another define as an alias

# 86 "LALCityHash.c" 2
#define bswap_32(x) BSWAP_32(x)
#define bswap_64(x) BSWAP_64(x)

Building here doesn't like this.

Instead, replacing the LALCityHash.c "bswap_32/64" definitions with sys/byteorder.h's "BSWAP_32/64" definitions work:

86,87c86,97
< #define bswap_32(x) BSWAP_32(x)
< #define bswap_64(x) BSWAP_64(x)
---
> #define bswap_32(x) (((uint32_t)(x) << 24) | \
>                         (((uint32_t)(x) << 8) & 0xff0000) | \
>                         (((uint32_t)(x) >> 8) & 0xff00) | \
>                         ((uint32_t)(x)  >> 24)) 
> #define bswap_64(x) (((uint64_t)(x) << 56) | \
>                         (((uint64_t)(x) << 40) & 0xff000000000000ULL) | \
>                         (((uint64_t)(x) << 24) & 0xff0000000000ULL) | \
>                         (((uint64_t)(x) << 8)  & 0xff00000000ULL) | \
>                         (((uint64_t)(x) >> 8)  & 0xff000000ULL) | \
>                         (((uint64_t)(x) >> 24) & 0xff0000ULL) | \
>                         (((uint64_t)(x) >> 40) & 0xff00ULL) | \
>                         ((uint64_t)(x)  >> 56))

I still do not see how a valid #define alias of a #define doesn't work here.