openrisc / or1k-glibc

glibc port for or1k
GNU General Public License v2.0
3 stars 7 forks source link

LONG_BIT is not defined #11

Closed bandvig closed 2 years ago

bandvig commented 2 years ago

@stffrdhrn Stafford, I've built toolchain based on

And I'm trying to build busybox. I got the following error message:

networking/tls_aesgcm.c:57:36: error: 'LONG_BIT' undeclared (first use in this function); did you mean 'LONG_MIN'? 57 | ? ((unsigned long)0xE1 << (LONG_BIT-8)) | ^~~~ | LONG_MIN

It is not a big problem. The networking/tls_aesgcm.c is the only file with usage LONG_BIT. I could either add ONG_BIT definition at the beginning of the file or just exclude appropriate applets from busybox configuration. However, I made some short investigation and found that

ifdef __USE_XOPEN

include <bits/xopen_lim.h>

endif

That means __USE_XOPEN is not defined in our toolchain. Perhaps, we should edit glibc configuration for OR1K to force __USE_XOPEN definitions

stffrdhrn commented 2 years ago

I see, __USE_XOPEN is defined in https://github.com/openrisc/or1k-glibc/blob/master/include/features.h#L355 if _XOPEN_SOURCE. It seems _XOPEN_SOURCE is used to control the build environment and should be set by the compiler, I don't see we set it in GCC.

This is according to comments in the same file: https://github.com/openrisc/or1k-glibc/blob/master/include/features.h#L45

   _XOPEN_SOURCE    Includes POSIX and XPG things.  Set to 500 if
            Single Unix conformance is wanted, to 600 for the
            sixth revision, to 700 for the seventh revision.
   _XOPEN_SOURCE_EXTENDED XPG things and X/Open Unix extensions.
   _LARGEFILE_SOURCE    Some more functions for correct standard I/O.

Also see: https://man7.org/linux/man-pages/man7/feature_test_macros.7.html

I am wondering if this is a bug with busybox. I will try the build and trace my self as well.

stffrdhrn commented 2 years ago

I did not have an issue building busybox. Can you show me your output of make V=1 networking/tls_aesgcm.o? Below is mine.

$ make V=1 networking/tls_aesgcm.o

rm -f .kernelrelease
echo 1.36.0.git > .kernelrelease
/home/shorne/work/openrisc/busybox/scripts/gen_build_files.sh /home/shorne/work/openrisc/busybox /home/shorne/work/openrisc/busybox
make -f scripts/Makefile.build obj=scripts/basic
make -f scripts/Makefile.build obj=applets
make -f scripts/Makefile.build obj=.
make -f scripts/Makefile.build obj=scripts
make -f scripts/Makefile.build obj=networking networking/tls_aesgcm.o
  or1k-glibc-linux-gnu-gcc -Wp,-MD,networking/.tls_aesgcm.o.d  -std=gnu99 -Iinclude -Ilibbb  -include include/autoconf.h -D_GNU_SOURCE -DNDEBUG -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DBB_VER='"1.36.0.git"' -I/home/shorne/local/or1ksim/include -I/home/shorne/local/or1k-linux/include -I/home/shorne/local/or1k-elf/include  -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Wunused -Wunused-parameter -Wunused-function -Wunused-value -Wmissing-prototypes -Wmissing-declarations -Wno-format-security -Wdeclaration-after-statement -Wold-style-definition -finline-limit=0 -fno-builtin-strlen -fomit-frame-pointer -ffunction-sections -fdata-sections -fno-guess-branch-probability -funsigned-char -static-libgcc -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-builtin-printf -Os    -DKBUILD_BASENAME='"tls_aesgcm"'  -DKBUILD_MODNAME='"tls_aesgcm"' -c -o networking/tls_aesgcm.o networking/tls_aesgcm.c

Also some of my toolchain details, this is built with the glibc build-many tool (https://github.com/openrisc/or1k-glibc/blob/master/scripts/build-many-glibcs.py):

or1k-glibc-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=or1k-glibc-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/libexec/gcc/or1k-glibc-linux-gnu/12.0.0/lto-wrapper
Target: or1k-glibc-linux-gnu
Configured with: /home/shorne/work/gnu-toolchain/build-many/src/gcc/configure --prefix=/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=or1k-glibc-linux-gnu --with-sysroot=/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot --with-multilib-list=mcmov,mhard-float,mdouble-float --enable-initfini-array --disable-libssp --disable-libcilkrts --with-gmp=/home/shorne/work/gnu-toolchain/build-many/install/host-libraries --with-mpfr=/home/shorne/work/gnu-toolchain/build-many/install/host-libraries --with-mpc=/home/shorne/work/gnu-toolchain/build-many/install/host-libraries --disable-libsanitizer --disable-libstdcxx-pch --enable-languages=c,c++ --enable-shared --enable-threads
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20220107 (experimental) [master revision 32c3a753906:8a9ba017b48:b48d4e6818674898f90d9358378c127511ef0f9f] (GCC) 
bandvig commented 2 years ago

Mine output compiling tls_aesgsm.c:

$make V=1 networking/tls_aesgcm.o
...
  or1k-unknown-linux-gnu-gcc -Wp,-MD,networking/.tls_aesgcm.o.d  -std=gnu99 -Iinclude -Ilibbb  -include include/autoconf.h -D_GNU_SOURCE -DNDEBUG -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DBB_VER='"1.36.0.git"' -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Wunused -Wunused-parameter -Wunused-function -Wunused-value -Wmissing-prototypes -Wmissing-declarations -Wno-format-security -Wdeclaration-after-statement -Wold-style-definition -finline-limit=0 -fno-builtin-strlen -fomit-frame-pointer -ffunction-sections -fdata-sections -fno-guess-branch-probability -funsigned-char -static-libgcc -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-builtin-printf -Os --sysroot="/opt/or1k-glibc/or1k-unknown-linux-gnu/sys-root"    -DKBUILD_BASENAME='"tls_aesgcm"'  -DKBUILD_MODNAME='"tls_aesgcm"' -c -o networking/tls_aesgcm.o networking/tls_aesgcm.c
networking/tls_aesgcm.c: In function 'RIGHTSHIFTX':
networking/tls_aesgcm.c:61:36: error: 'LONG_BIT' undeclared (first use in this function); did you mean 'LONG_MIN'?
   61 |         ? ((unsigned long)0xE1 << (LONG_BIT-8))
      |                                    ^~~~~~~~
      |                                    LONG_MIN
networking/tls_aesgcm.c:61:36: note: each undeclared identifier is reported only once for each function it appears in

My GCC configuration (I do not use multilib):

$ or1k-unknown-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=or1k-unknown-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/opt/or1k-glibc/libexec/gcc/or1k-unknown-linux-gnu/11.2.0/lto-wrapper.exe
Target: or1k-unknown-linux-gnu
Configured with: ../../src/gcc/configure --target=or1k-unknown-linux-gnu --prefix=/opt/or1k-glibc --with-sysroot=/opt/or1k-glibc/or1k-unknown-linux-gnu/sys-root --with-build-time-tools=/opt/or1k-glibc/bin --enable-lto --enable-plugins --enable-__cxa_atexit --with-glibc-version=2.34 --with-cloog=no --with-ppl=no --with-isl=no --disable-multilib --enable-languages=c,c++,lto --enable-threads=posix --disable-gcov --enable-default-ssp=no --disable-libssp --disable-libquadmath --disable-libquadmath-support --with-long-double-64 --disable-decimal-float --disable-libsanitizer --disable-libitm --disable-libvtv --disable-nls --with-system-zlib --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.0 (GCC)

My GLIBC configuration:

../../src/glibc/configure --prefix=/usr --build=x86_64-pc-cygwin --host=${OR1KCC_TARGET} --with-headers=${OR1KCC_SYSROOT}/usr/include --enable-add-ons=nptl --enable-kernel=5.9.0 --disable-mathvec --disable-experimental-malloc --disable-profile --disable-werror libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes
stffrdhrn commented 2 years ago

I cannot really see a bit different in our configs or commands.

This is my config for glibc:

Command: /home/shorne/work/gnu-toolchain/build-many/src/glibc/configure \
   '--prefix=/usr' --enable-profile '--build=x86_64-pc-linux-gnu' \
   '--host=or1k-glibc-linux-gnu' 'CC=or1k-glibc-linux-gnu-gcc' \
   'CXX=or1k-glibc-linux-gnu-g++' 'AR=or1k-glibc-linux-gnu-ar' \
   'AS=or1k-glibc-linux-gnu-as' 'LD=or1k-glibc-linux-gnu-ld' \
   'NM=or1k-glibc-linux-gnu-nm' 'OBJCOPY=or1k-glibc-linux-gnu-objcopy' \
   'OBJDUMP=or1k-glibc-linux-gnu-objdump' 'RANLIB=or1k-glibc-linux-gnu-ranlib' \
   'READELF=or1k-glibc-linux-gnu-readelf' 'STRIP=or1k-glibc-linux-gnu-strip'
stffrdhrn commented 2 years ago

For my current toolchain I have xopen_lim.h at this locations, where is it for you?:

/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/xopen_lim.h
stffrdhrn commented 2 years ago

Also, running the gcc command passing -v I get the below.

Notice the #include <...> search starts here: bit; gcc is implicitly including /home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include

< shorne@antec ~/work/openrisc/busybox > or1k-glibc-linux-gnu-gcc -v -Wp,-MD,networking/.tls_aesgcm.o.d  -std=gnu99 -Iinclude -Ilibbb  -include include/autoconf.h -D_GNU_SOURCE -DNDEBUG -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DBB_VER='"1.36.0.git"' -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Wunused -Wunused-parameter -Wunused-function -Wunused-value -Wmissing-prototypes -Wmissing-declarations -Wno-format-security -Wdeclaration-after-statement -Wold-style-definition -finline-limit=0 -fno-builtin-strlen -fomit-frame-pointer -ffunction-sections -fdata-sections -fno-guess-branch-probability -funsigned-char -static-libgcc -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-builtin-printf -Os    -DKBUILD_BASENAME='"tls_aesgcm"'  -DKBUILD_MODNAME='"tls_aesgcm"' -c -o networking/tls_aesgcm.o networking/tls_aesgcm.c
Using built-in specs.
COLLECT_GCC=or1k-glibc-linux-gnu-gcc
Target: or1k-glibc-linux-gnu
Configured with: /home/shorne/work/gnu-toolchain/build-many/src/gcc/configure --prefix=/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=or1k-glibc-linux-gnu --with-sysroot=/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot --with-multilib-list=mcmov,mhard-float,mdouble-float --enable-initfini-array --disable-libssp --disable-libcilkrts --with-gmp=/home/shorne/work/gnu-toolchain/build-many/install/host-libraries --with-mpfr=/home/shorne/work/gnu-toolchain/build-many/install/host-libraries --with-mpc=/home/shorne/work/gnu-toolchain/build-many/install/host-libraries --disable-libsanitizer --disable-libstdcxx-pch --enable-languages=c,c++ --enable-shared --enable-threads
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20220107 (experimental) [master revision 32c3a753906:8a9ba017b48:b48d4e6818674898f90d9358378c127511ef0f9f] (GCC)
COLLECT_GCC_OPTIONS='-v' '-std=gnu99' '-I' 'include' '-I' 'libbb' '-include' 'include/autoconf.h' '-D' '_GNU_SOURCE' '-D' 'NDEBUG' '-D' '_LARGEFILE_SOURCE' '-D' '_LARGEFILE64_SOURCE' '-D' '_FILE_OFFSET_BITS=64' '-D' 'BB_VER="1.36.0.git"' '-Wall' '-Wshadow' '-Wwrite-strings' '-Wundef' '-Wstrict-prototypes' '-Wunused' '-Wunused-parameter' '-Wunused-function' '-Wunused-value' '-Wmissing-prototypes' '-Wmissing-declarations' '-Wno-format-security' '-Wdeclaration-after-statement' '-Wold-style-definition' '-finline-limit=0' '-fno-builtin-strlen' '-fomit-frame-pointer' '-ffunction-sections' '-fdata-sections' '-fno-guess-branch-probability' '-funsigned-char' '-static-libgcc' '-falign-functions=1' '-falign-jumps=1' '-falign-labels=1' '-falign-loops=1' '-fno-unwind-tables' '-fno-asynchronous-unwind-tables' '-fno-builtin-printf' '-Os' '-D' 'KBUILD_BASENAME="tls_aesgcm"' '-D' 'KBUILD_MODNAME="tls_aesgcm"' '-c' '-o' 'networking/tls_aesgcm.o' '-dumpdir' 'networking/'
 /home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/libexec/gcc/or1k-glibc-linux-gnu/12.0.0/cc1 -quiet -v -I include -I libbb -D _GNU_SOURCE -D NDEBUG -D _LARGEFILE_SOURCE -D _LARGEFILE64_SOURCE -D _FILE_OFFSET_BITS=64 -D BB_VER="1.36.0.git" -D KBUILD_BASENAME="tls_aesgcm" -D KBUILD_MODNAME="tls_aesgcm" -include include/autoconf.h -MD networking/.tls_aesgcm.o.d networking/tls_aesgcm.c -quiet -dumpdir networking/ -dumpbase tls_aesgcm.c -dumpbase-ext .c -Os -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Wunused -Wunused-parameter -Wunused-function -Wunused-value -Wmissing-prototypes -Wmissing-declarations -Wno-format-security -Wdeclaration-after-statement -Wold-style-definition -std=gnu99 -version -finline-limit=0 -fno-builtin-strlen -fomit-frame-pointer -ffunction-sections -fdata-sections -fno-guess-branch-probability -funsigned-char -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-builtin-printf -o /tmp/ccygHKvp.s
GNU C99 (GCC) version 12.0.0 20220107 (experimental) [master revision 32c3a753906:8a9ba017b48:b48d4e6818674898f90d9358378c127511ef0f9f] (or1k-glibc-linux-gnu)
        compiled by GNU C version 11.1.1 20210428 (Red Hat 11.1.1-1), GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version none
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
ignoring nonexistent directory "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
 include
 libbb
 /home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/include
 /home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/include-fixed
 /home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/../../../../or1k-glibc-linux-gnu/include
 /home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include
End of search list.
GNU C99 (GCC) version 12.0.0 20220107 (experimental) [master revision 32c3a753906:8a9ba017b48:b48d4e6818674898f90d9358378c127511ef0f9f] (or1k-glibc-linux-gnu)
        compiled by GNU C version 11.1.1 20210428 (Red Hat 11.1.1-1), GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version none
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 123288496dbced23cdb52147738dc134
COLLECT_GCC_OPTIONS='-v' '-std=gnu99' '-I' 'include' '-I' 'libbb' '-include' 'include/autoconf.h' '-D' '_GNU_SOURCE' '-D' 'NDEBUG' '-D' '_LARGEFILE_SOURCE' '-D' '_LARGEFILE64_SOURCE' '-D' '_FILE_OFFSET_BITS=64' '-D' 'BB_VER="1.36.0.git"' '-Wall' '-Wshadow' '-Wwrite-strings' '-Wundef' '-Wstrict-prototypes' '-Wunused' '-Wunused-parameter' '-Wunused-function' '-Wunused-value' '-Wmissing-prototypes' '-Wmissing-declarations' '-Wno-format-security' '-Wdeclaration-after-statement' '-Wold-style-definition' '-finline-limit=0' '-fno-builtin-strlen' '-fomit-frame-pointer' '-ffunction-sections' '-fdata-sections' '-fno-guess-branch-probability' '-funsigned-char' '-static-libgcc' '-falign-functions=1' '-falign-jumps=1' '-falign-labels=1' '-falign-loops=1' '-fno-unwind-tables' '-fno-asynchronous-unwind-tables' '-fno-builtin-printf' '-Os' '-D' 'KBUILD_BASENAME="tls_aesgcm"' '-D' 'KBUILD_MODNAME="tls_aesgcm"' '-c' '-o' 'networking/tls_aesgcm.o' '-dumpdir' 'networking/'
 /home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/../../../../or1k-glibc-linux-gnu/bin/as -v -I include -I libbb -o networking/tls_aesgcm.o /tmp/ccygHKvp.s
GNU assembler version 2.37.50 (or1k-glibc-linux-gnu) using BFD version (GNU Binutils) 2.37.50.20211028
COMPILER_PATH=/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/libexec/gcc/or1k-glibc-linux-gnu/12.0.0/:/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/libexec/gcc/or1k-glibc-linux-gnu/12.0.0/:/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/libexec/gcc/or1k-glibc-linux-gnu/:/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/:/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/:/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/../../../../or1k-glibc-linux-gnu/bin/
LIBRARY_PATH=/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/:/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/../../../../or1k-glibc-linux-gnu/lib/:/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/lib/:/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-std=gnu99' '-I' 'include' '-I' 'libbb' '-include' 'include/autoconf.h' '-D' '_GNU_SOURCE' '-D' 'NDEBUG' '-D' '_LARGEFILE_SOURCE' '-D' '_LARGEFILE64_SOURCE' '-D' '_FILE_OFFSET_BITS=64' '-D' 'BB_VER="1.36.0.git"' '-Wall' '-Wshadow' '-Wwrite-strings' '-Wundef' '-Wstrict-prototypes' '-Wunused' '-Wunused-parameter' '-Wunused-function' '-Wunused-value' '-Wmissing-prototypes' '-Wmissing-declarations' '-Wno-format-security' '-Wdeclaration-after-statement' '-Wold-style-definition' '-finline-limit=0' '-fno-builtin-strlen' '-fomit-frame-pointer' '-ffunction-sections' '-fdata-sections' '-fno-guess-branch-probability' '-funsigned-char' '-static-libgcc' '-falign-functions=1' '-falign-jumps=1' '-falign-labels=1' '-falign-loops=1' '-fno-unwind-tables' '-fno-asynchronous-unwind-tables' '-fno-builtin-printf' '-Os' '-D' 'KBUILD_BASENAME="tls_aesgcm"' '-D' 'KBUILD_MODNAME="tls_aesgcm"' '-c' '-o' 'networking/tls_aesgcm.o' '-dumpdir' 'networking/tls_aesgcm.'
bandvig commented 2 years ago

My xopen_lim.h is located at /opt/or1k-glibc/or1k-unknown-linux-gnu/sys-root/usr/include/bits/xopen_lim.h But it looks it just not involved into compilation at all (see later).

If I try to compile tls_aesgcm.c alone I receive:

$ or1k-unknown-linux-gnu-gcc  -v -Wp,-MD,networking/.tls_aesgcm.o.d  -std=gnu99 -Iinclude -Ilibbb  -include include/autoconf.h -D_GNU_SOURCE -DNDEBUG -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DBB_VER='"1.36.0.git"' -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Wunused -Wunused-parameter -Wunused-function -Wunused-value -Wmissing-prototypes -Wmissing-declarations -Wno-format-security -Wdeclaration-after-statement -Wold-style-definition -finline-limit=0 -fno-builtin-strlen -fomit-frame-pointer -ffunction-sections -fdata-sections -fno-guess-branch-probability -funsigned-char -static-libgcc -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-builtin-printf -Os    -DKBUILD_BASENAME='"tls_aesgcm"'  -DKBUILD_MODNAME='"tls_aesgcm"' -c -o networking/tls_aesgcm.o networking/tls_aesgcm.c
Using built-in specs.
COLLECT_GCC=or1k-unknown-linux-gnu-gcc
Target: or1k-unknown-linux-gnu
Configured with: ../../src/gcc/configure --target=or1k-unknown-linux-gnu --prefix=/opt/or1k-glibc --with-sysroot=/opt/or1k-glibc/or1k-unknown-linux-gnu/sys-root --with-build-time-tools=/opt/or1k-glibc/bin --enable-lto --enable-plugins --enable-__cxa_atexit --with-glibc-version=2.34 --with-cloog=no --with-ppl=no --with-isl=no --disable-multilib --enable-languages=c,c++,lto --enable-threads=posix --disable-gcov --enable-default-ssp=no --disable-libssp --disable-libquadmath --disable-libquadmath-support --with-long-double-64 --disable-decimal-float --disable-libsanitizer --disable-libitm --disable-libvtv --disable-nls --with-system-zlib --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-std=gnu99' '-I' 'include' '-I' 'libbb' '-include' 'include/autoconf.h' '-D' '_GNU_SOURCE' '-D' 'NDEBUG' '-D' '_LARGEFILE_SOURCE' '-D' '_LARGEFILE64_SOURCE' '-D' '_FILE_OFFSET_BITS=64' '-D' 'BB_VER="1.36.0.git"' '-Wall' '-Wshadow' '-Wwrite-strings' '-Wundef' '-Wstrict-prototypes' '-Wunused' '-Wunused-parameter' '-Wunused-function' '-Wunused-value' '-Wmissing-prototypes' '-Wmissing-declarations' '-Wno-format-security' '-Wdeclaration-after-statement' '-Wold-style-definition' '-finline-limit=0' '-fno-builtin-strlen' '-fomit-frame-pointer' '-ffunction-sections' '-fdata-sections' '-fno-guess-branch-probability' '-funsigned-char' '-static-libgcc' '-falign-functions=1' '-falign-jumps=1' '-falign-labels=1' '-falign-loops=1' '-fno-unwind-tables' '-fno-asynchronous-unwind-tables' '-fno-builtin-printf' '-Os' '-D' 'KBUILD_BASENAME="tls_aesgcm"' '-D' 'KBUILD_MODNAME="tls_aesgcm"' '-c' '-o' 'networking/tls_aesgcm.o' '-dumpdir' 'networking/'
 /opt/or1k-glibc/libexec/gcc/or1k-unknown-linux-gnu/11.2.0/cc1.exe -quiet -v -I include -I libbb -D _GNU_SOURCE -D NDEBUG -D _LARGEFILE_SOURCE -D _LARGEFILE64_SOURCE -D _FILE_OFFSET_BITS=64 -D BB_VER="1.36.0.git" -D KBUILD_BASENAME="tls_aesgcm" -D KBUILD_MODNAME="tls_aesgcm" -include include/autoconf.h -MD networking/.tls_aesgcm.o.d networking/tls_aesgcm.c -quiet -dumpdir networking/ -dumpbase tls_aesgcm.c -dumpbase-ext .c -Os -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Wunused -Wunused-parameter -Wunused-function -Wunused-value -Wmissing-prototypes -Wmissing-declarations -Wno-format-security -Wdeclaration-after-statement -Wold-style-definition -std=gnu99 -version -finline-limit=0 -fno-builtin-strlen -fomit-frame-pointer -ffunction-sections -fdata-sections -fno-guess-branch-probability -funsigned-char -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-builtin-printf -o /tmp/ccPh3Tri.s
GNU C99 (GCC) version 11.2.0 (or1k-unknown-linux-gnu)
        compiled by GNU C version 11.2.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/opt/or1k-glibc/or1k-unknown-linux-gnu/sys-root/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
 include
 libbb
 /opt/or1k-glibc/lib/gcc/or1k-unknown-linux-gnu/11.2.0/include
 /opt/or1k-glibc/lib/gcc/or1k-unknown-linux-gnu/11.2.0/include-fixed
 /opt/or1k-glibc/lib/gcc/or1k-unknown-linux-gnu/11.2.0/../../../../or1k-unknown-linux-gnu/include
 /opt/or1k-glibc/or1k-unknown-linux-gnu/sys-root/usr/include
End of search list.
GNU C99 (GCC) version 11.2.0 (or1k-unknown-linux-gnu)
        compiled by GNU C version 11.2.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 1650a5e16a4cc927bfb5a1dbcbddb237
networking/tls_aesgcm.c: In function 'RIGHTSHIFTX':
networking/tls_aesgcm.c:61:36: error: 'LONG_BIT' undeclared (first use in this function); did you mean 'LONG_MIN'?
   61 |         ? ((unsigned long)0xE1 << (LONG_BIT-8))
      |                                    ^~~~~~~~
      |                                    LONG_MIN
networking/tls_aesgcm.c:61:36: note: each undeclared identifier is reported only once for each function it appears in

I've explored which limits.h appears first in search paths. For my toolchain such limits.h is at /opt/or1k-glibc/lib/gcc/or1k-unknown-linux-gnu/11.2.0/include-fixed/limits.h:

$ cd /opt/or1k-glibc
$ find -name limits.h
./lib/gcc/or1k-unknown-linux-gnu/11.2.0/include-fixed/limits.h
./lib/gcc/or1k-unknown-linux-gnu/11.2.0/install-tools/include/limits.h
./or1k-unknown-linux-gnu/include/c++/11.2.0/tr1/limits.h
./or1k-unknown-linux-gnu/sys-root/usr/include/limits.h
./or1k-unknown-linux-gnu/sys-root/usr/include/linux/limits.h

It is GCC's limits.h not GLIBC's. Namely the limits.h goes to includes (if I add an erroneous string in it compiler reports bug exactly on the string). But it does not include any other headers. And it does not contain macros like LONG_BIT. I think it is the root of my problem.

BTW, I see you use GCC12 (the newer version than mine). Could you check presence limits.h in your toolchain and content of 1-st limits.h in paths?

stffrdhrn commented 2 years ago

I see that could be it. For me I have:

./build-many/install/compilers/or1k-linux-gnu/or1k-glibc-linux-gnu/include/c++/12.0.0/tr1/limits.h
./build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/linux/limits.h
./build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/limits.h
./build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/install-tools/include/limits.h
./build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/include-fixed/limits.h

One thing I can do is dump the pre processed .c file to see what headers its actually included.
This can be interpreted as: https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html

$ make V=1 networking/tls_aesgcm.i

# This shows what is actually going on:
grep lim.*\\.h networking/tls_aesgcm.i
# 1 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/include-fixed/limits.h" 1 3 4
# 34 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/include-fixed/limits.h" 3 4
# 1 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/include-fixed/syslimits.h" 1 3 4
# 1 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/include-fixed/limits.h" 1 3 4
# 203 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/include-fixed/limits.h" 3 4
# 1 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/limits.h" 1 3 4
# 26 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/limits.h" 3 4
# 27 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/limits.h" 2 3 4
# 195 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/limits.h" 3 4
# 1 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/posix1_lim.h" 1 3 4
# 27 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/posix1_lim.h" 3 4
# 28 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/posix1_lim.h" 2 3 4
# 161 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/posix1_lim.h" 3 4
# 1 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/local_lim.h" 1 3 4
# 38 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/local_lim.h" 3 4
# 1 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/linux/limits.h" 1 3 4
# 39 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/local_lim.h" 2 3 4
# 81 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/local_lim.h" 3 4
# 82 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/local_lim.h" 2 3 4
# 162 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/posix1_lim.h" 2 3 4
# 196 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/limits.h" 2 3 4
# 1 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/posix2_lim.h" 1 3 4
# 200 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/limits.h" 2 3 4
# 1 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/xopen_lim.h" 1 3 4
# 64 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/xopen_lim.h" 3 4
# 1 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/uio_lim.h" 1 3 4
# 65 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/xopen_lim.h" 2 3 4
# 204 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/limits.h" 2 3 4
# 204 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/include-fixed/limits.h" 2 3 4
# 8 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/include-fixed/syslimits.h" 2 3 4
# 35 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/include-fixed/limits.h" 2 3 4
# 1 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/sysroot/usr/include/bits/stdio_lim.h" 1 3 4
# 1 "/home/shorne/work/gnu-toolchain/build-many/install/compilers/or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/include-fixed/limits.h" 1 3 4
stffrdhrn commented 2 years ago

I can just publish my toolchain build. Maybe that is easier?

bandvig commented 2 years ago

@stffrdhrn I could not run your toolchain as I use CygWin an it is not a Linux system. Any free soft should be re-built under CygWin environment any case. Could you:

bandvig commented 2 years ago

@stffrdhrn I received your limits.h files. Thank you. In fact your or1k-linux-gnu/lib/gcc/or1k-glibc-linux-gnu/12.0.0/include-fixed/limits.h differs from mine. While your include-fixed/limits.h contains also (lines 32 ... 35):

#ifndef _LIBC_LIMITS_H_
/* Use "..." so that we find syslimits.h only in this same directory.  */
#include "syslimits.h"
#endif

mine does not. I jut replaced mine include-fixed/limits.h with yours and the problem disappeared.

On the other hand it look like your include-fixed/limits.h was some how automatically re-written because it includes license information twice. One time - at the beginning of the file and second time - starting from line 36. That's why I asked you about your way building the toolchain. Do you use an your own script set or build root or something else?

My building approach comes from https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/

stffrdhrn commented 2 years ago

Sorry, I meant to provide it.. I use:

But more recently I just use the build-many tool from glibc:

stffrdhrn commented 2 years ago

You are right that the limits.h file contains the copyright 2 times. As per gcc/gcc/Makefile.in It is joined with several .h files in the gcc build. cat $(srcdir)/limitx.h $(T_GLIMITS_H) $(srcdir)/limity.h > tmp-xlimits.h; \

This is explained here: https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/doc/sourcebuild.texi;h=6095a35cd4565fdb7d758104e80fe6411230f758;hb=HEAD#324

 324 GCC also installs its own version of @code{<limits.h>}; this is generated
 325 from @file{glimits.h}, together with @file{limitx.h} and
 326 @file{limity.h} if the system also has its own version of
 327 @code{<limits.h>}.  (GCC provides its own header because it is
 328 required of ISO C freestanding implementations, but needs to include
 329 the system header from its own header as well because other standards
 330 such as POSIX specify additional values to be defined in
 331 @code{<limits.h>}.)  The system's @code{<limits.h>} header is used via
 332 @file{@var{libsubdir}/include/syslimits.h}, which is copied from
 333 @file{gsyslimits.h} if it does not need fixing to work with GCC; if it
 334 needs fixing, @file{syslimits.h} is the fixed copy.

This seems to maybe explain why you are missing LONG_BIT on cygwin. It seems maybe you need to get gnulib limits-h? https://www.gnu.org/software/gnulib/manual/html_node/limits_002eh.html

bandvig commented 2 years ago

@stffrdhrn I've found a way to overcome the problem. I've just changed building steps. Now my build steps are:

  1. Configure, build and install binutils
  2. Build naked cross compiler following by recommendations from https://wiki.osdev.org/GCC_Cross-Compiler
  3. Install Linux headers
  4. Configure Glibc, install Glibc's headers, build Glibc with previously built naked compiler and install Glibc
  5. Configure, build and install final gcc. The /opt/or1k-newlib/lib/gcc/or1k-elf/11.2.0/include-fixed/limits.h is re-written at stage of installation final gcc. My previous build steps (borrowed from https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/) just didn't do such installation and include-fixed/limits.h stayed unchanged.

Now I've correct include-fixed/limits.h and can build busybox without errors.