Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 828101 - dev-db/sqlite doesn't set byte order during configure
Summary: dev-db/sqlite doesn't set byte order during configure
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: Jakov Smolić
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-12-03 19:19 UTC by 2b57
Modified: 2022-01-15 01:13 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description 2b57 2021-12-03 19:19:17 UTC
Upon looking at sqlite ebuild(s) and comparing it with other distros I've noticed Gentoo doesn't set endianness configure flag. For example, Chimera Linux does it explicitly:  github. com/chimera-linux/cports/blob/master/main/sqlite/template.py#L30#L33

I believe some endianness info should be available from profile?

Reproducible: Always
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2021-12-04 01:33:45 UTC
AFAIK it does seem to wor kfine on big endian without this, but interesting that chimera needed it?
Comment 2 Arfrever Frehtes Taifersar Arahesis 2021-12-04 07:46:25 UTC
There is partial build-time detection of endianness (for some platforms) and fallback run-time detection of endianness, but I can set these macros manually in ebuild for potential minimally better performance on exotic platforms...


src/sqliteInt.h:
> /*
> ** Macros to determine whether the machine is big or little endian,
> ** and whether or not that determination is run-time or compile-time.
> **
> ** For best performance, an attempt is made to guess at the byte-order
> ** using C-preprocessor macros.  If that is unsuccessful, or if
> ** -DSQLITE_BYTEORDER=0 is set, then byte-order is determined
> ** at run-time.
> */
> #ifndef SQLITE_BYTEORDER
> # if defined(i386)      || defined(__i386__)      || defined(_M_IX86) ||    \
>      defined(__x86_64)  || defined(__x86_64__)    || defined(_M_X64)  ||    \
>      defined(_M_AMD64)  || defined(_M_ARM)        || defined(__x86)   ||    \
>      defined(__ARMEL__) || defined(__AARCH64EL__) || defined(_M_ARM64)
> #   define SQLITE_BYTEORDER    1234
> # elif defined(sparc)     || defined(__ppc__) || \
>        defined(__ARMEB__) || defined(__AARCH64EB__)
> #   define SQLITE_BYTEORDER    4321
> # else
> #   define SQLITE_BYTEORDER 0
> # endif
> #endif
> #if SQLITE_BYTEORDER==4321
> # define SQLITE_BIGENDIAN    1
> # define SQLITE_LITTLEENDIAN 0
> # define SQLITE_UTF16NATIVE  SQLITE_UTF16BE
> #elif SQLITE_BYTEORDER==1234
> # define SQLITE_BIGENDIAN    0
> # define SQLITE_LITTLEENDIAN 1
> # define SQLITE_UTF16NATIVE  SQLITE_UTF16LE
> #else
> # ifdef SQLITE_AMALGAMATION
>   const int sqlite3one = 1;
> # else
>   extern const int sqlite3one;
> # endif
> # define SQLITE_BIGENDIAN    (*(char *)(&sqlite3one)==0)
> # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
> # define SQLITE_UTF16NATIVE  (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
> #endif

src/util.c:
> /*
> ** Read or write a four-byte big-endian integer value.
> */
> u32 sqlite3Get4byte(const u8 *p){
> #if SQLITE_BYTEORDER==4321
>   u32 x;
>   memcpy(&x,p,4);
>   return x;
> #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
>   u32 x;
>   memcpy(&x,p,4);
>   return __builtin_bswap32(x);
> #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
>   u32 x;
>   memcpy(&x,p,4);
>   return _byteswap_ulong(x);
> #else
>   testcase( p[0]&0x80 );
>   return ((unsigned)p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
> #endif
> }
> void sqlite3Put4byte(unsigned char *p, u32 v){
> #if SQLITE_BYTEORDER==4321
>   memcpy(p,&v,4);
> #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
>   u32 x = __builtin_bswap32(v);
>   memcpy(p,&x,4);
> #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
>   u32 x = _byteswap_ulong(v);
>   memcpy(p,&x,4);
> #else
>   p[0] = (u8)(v>>24);
>   p[1] = (u8)(v>>16);
>   p[2] = (u8)(v>>8);
>   p[3] = (u8)v;
> #endif
> }

ext/misc/shathree.c:
> /*
> ** Macros to determine whether the machine is big or little endian,
> ** and whether or not that determination is run-time or compile-time.
> **
> ** For best performance, an attempt is made to guess at the byte-order
> ** using C-preprocessor macros.  If that is unsuccessful, or if
> ** -DSHA3_BYTEORDER=0 is set, then byte-order is determined
> ** at run-time.
> */
> #ifndef SHA3_BYTEORDER
> # if defined(i386)     || defined(__i386__)   || defined(_M_IX86) ||    \
>      defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)  ||    \
>      defined(_M_AMD64) || defined(_M_ARM)     || defined(__x86)   ||    \
>      defined(__arm__)
> #   define SHA3_BYTEORDER    1234
> # elif defined(sparc)    || defined(__ppc__)
> #   define SHA3_BYTEORDER    4321
> # else
> #   define SHA3_BYTEORDER 0
> # endif
> #endif
> ...
> /*
> ** Initialize a new hash.  iSize determines the size of the hash
> ** in bits and should be one of 224, 256, 384, or 512.  Or iSize
> ** can be zero to use the default hash size of 256 bits.
> */
> static void SHA3Init(SHA3Context *p, int iSize){
>   memset(p, 0, sizeof(*p));
>   if( iSize>=128 && iSize<=512 ){
>     p->nRate = (1600 - ((iSize + 31)&~31)*2)/8;
>   }else{
>     p->nRate = (1600 - 2*256)/8;
>   }
> #if SHA3_BYTEORDER==1234
>   /* Known to be little-endian at compile-time. No-op */
> #elif SHA3_BYTEORDER==4321
>   p->ixMask = 7;  /* Big-endian */
> #else
>   {
>     static unsigned int one = 1;
>     if( 1==*(unsigned char*)&one ){
>       /* Little endian.  No byte swapping. */
>       p->ixMask = 0;
>     }else{
>       /* Big endian.  Byte swap. */
>       p->ixMask = 7;
>     }
>   }
> #endif
> }
> ...