Problems compiling gfortran in Cygwin with large memory requirements - gcc

My computer (intel core i7 CPU, 20 GB RAM, 2TB HDD) is running Windows 8 and I usually boot up the Linux VM to do my programming, but I am currently trying to run a Fortran program natively in Windows 8 using Cygwin. I am writing a program which has large memory requirements and I am creating a double precision array of size 13943 x Nfiles where I let Nfiles vary and I am trying to make it as large as possible while still remaining under 20 GB of RAM.
I notice that when I get to around Nfiles = 17000 it uses about 1.77 GB of RAM. However, when I raise Nfiles to 20000, I get a compilation error of
gfortran -ffixed-line-length-132 -fimplicit-none -O2 -o smear_sfs.exe xdriver.F90 modules.o
/usr/lib/gcc/x86_64-pc-cygwin/4.8.1/crtbegin.o:cygming-crtbegin.c:(.text+0x2b): relocation truncated to fit: R_X86_64_PC32 against symbol `__imp_GetModuleHandleA' defined in .idata$5 section in /usr/lib/w32api/libkernel32.a(dysgbs00548.o)
/usr/lib/gcc/x86_64-pc-cygwin/4.8.1/crtbegin.o:cygming-crtbegin.c:(.text+0x47): relocation truncated to fit: R_X86_64_PC32 against symbol `__imp_GetProcAddress' defined in .idata$5 section in /usr/lib/w32api/libkernel32.a(dysgbs00598.o)
/usr/lib/gcc/x86_64-pc-cygwin/4.8.1/../../../../x86_64-pc-cygwin/bin/ld: /usr/lib/gcc/x86_64-pc-cygwin/4.8.1/crtbegin.o: bad reloc address 0x0 in section `.pdata'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.1/../../../../x86_64-pc-cygwin/bin/ld: final link failed: Invalid operation
collect2: error: ld returned 1 exit status
Makefile:30: recipe for target `smear_sfs' failed
make: *** [smear_sfs] Error 1
But after searching online I cannot figure out what the problem is. gfortran -v reveals the following information
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/4.8.1/lto-wrapper.exe
Target: x86_64-pc-cygwin
Configured with: /cygdrive/i/szsz/tmpp/cygwin64/gcc/gcc-4.8.1-3/src/gcc-4.8.1/configure --srcdir=/cygdrive/i/szsz/tmpp/cygwin64/gcc/gcc-4.8.1-3/src/gcc-4.8.1 --prefix=/usr --exec- prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --datadir=/usr/share --localstatedir=/var --sysconfdir=/etc --datarootdir=/usr/share --docdir=/usr/share/doc/gcc -C --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --disable-__cxa_atexit --with-dwarf2 --with-tune=generic --enable-languages=c,c++,fortran,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmath-support --enable-libssp --enable-libgcj-sublibs --disable-java-awt --disable-symvers --with-ecj-jar=/usr/share/java/ecj.jar --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix --without-libintl-prefix --with-system-zlib
Thread model: posix
gcc version 4.8.1 (GCC)
so it seems like I am correctly using a 64-bit compiler on a 64-bit OS.
Any ideas?

Related

warnings while trying to compile old linux kernel with gcc 12.1.0

I am currently hunting a bug using git bisect in linux staging-testing tree.
Some commits are giving following errors after I try to build them:
subcmd-util.h:58:31: error: pointer may be used after ‘realloc’ [-Werror=use-after-free]
58 | ret = realloc(ptr, 1);
check.c:2867:58: error: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 9 [-Werror=format-truncation=]
2867 | snprintf(pvname, sizeof(pvname), "pv_ops[%d]", idx);
I tried adding -Wno-error=use-after-free to KBUILD_FLAGS in main Makefile, tried adding
KBUILD_CFLAGS += $(call cc-disable-warning, use-after-free)
I even tried removing -Werror from CFLAGS in Makefile in folder where problematic files are located, but nothing worked.
More information:
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.artixlinux.org/ --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror --with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.1.0 (GCC)
Linux staging tree: git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git.
One of the commits that gives following warnings: 2ab9c9675fe892e7fe9fa8c0a6125e2b40d2889d.
To compile older version of kernel I needed older compiler ("Linux kernel sources are in general not forward-compatible with new compilers"). In my case the kernel version was 5.16.0 and I could compile it with gcc 11. If you have gcc 11 specific warnings then try gcc 10 and so on.
Except CC flags, I also needed set to HOSTCC flags to use gcc-11 compiler:
make HOSTCC=gcc-11 CC=gcc-11

g++ 9.2.1 on modern Intel: any way at all to get CMPXCHG16B instructions generated from C++11 atomic<> or C11 atomic_compare_exchange_strong

I simply want an instruction, not a library call, for speed when I'm using atomic<> with 16-byte types.
Duh: the main reason anyone uses atomic<> with 16-byte types is surely for speed!
The man page is teasing me:
-mcx16
This option enables GCC to generate "CMPXCHG16B" instructions in 64-bit code to implement compare-and-exchange operations on 16-byte aligned 128-bit objects. This is useful for atomic updates of data structures exceeding one machine word in size. The compiler uses this instruction to implement __sync Builtins. However, for __atomic Builtins operating on 128-bit integers, a library call is always used.
I'd even welcome an assembly version, though for odd reasons I'm using C11, not C++11. (A C++11 solution would certainly be welcome enough though!)
This is my compiler:
> g++ -v
Using built-in specs.
COLLECT_GCC=/usr/bin/g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.2.1 20190827 (Red Hat 9.2.1-1) (GCC)

Compile libgcc.a and libstd++.a for 32 bits

Good afternoon,
If I'm here today is because I encounter some compilation problems.
For a project, I would like to compile gcc in order to have libgcc.a and libstd++.a for 32 bits.
Unfortunatly I have some problems.
Here are the command lines I used to configure and compile the wanted libraries:
CC="gcc -m32" CXX="g++ -m32" CFLAGS="-O1 -march=i686 -gtoggle" CXXFLAGS="-O1 -march=i686 -gtoggle" ; ../src/gcc/gcc-8.1.0/configure --prefix=/path/compiled/x86/O1/gcc --enable-languages=c,c++ --enable-static i686-linux-gnu
make all-gcc
make install-target-libgcc
When I execute last command line I have those errors:
/usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:985: libgcc_s.so] Error 1
My machine:
Archlinux 64 bits, up to date
Output of gcc -v:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/8.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp
Thread model: posix
gcc version 8.1.0 (GCC)
Thank you for your help !
EDIT: ANSWER HERE
SO for those who wants to know how to compile libgcc and libstdc++ for 32 on a x86_64 machine:
./configure --target=$TARGET --disable-nls --enable-languages=c,c++ --without-headers --prefix=/path/
make all-gcc
make all-target-libgcc
make all-target-libstdc++-v3
make install-gcc
make install-target-libgcc
make install-target-libstdc++-v3
make clean
Then go to the folder containing your new installation, you'll normaly have two folders: lib32 and lib64. Inside lib32, there is the 32 bits version of libgcc and libstdc++ and in lib64, their 64 bits version.
Enjoy !

How to enable Aarch32 instruction set on ARMv8-a?

Raspberry Pi 3 uses a Broadcom SoC with and ARMv8 A53 core. It also uses a 32-bit OS based on Debian Jessie. According to ARM's ARM NEON programming quick reference, Section 3.2, Instruction set:
The ARMv8-A AArch32 instruction set consists of A32 (ARM instruction set, a 32-bit fixed length instruction set) and T32 (Thumb instruction set, a 16-bit fixed length instruction set; Thumb2 instruction set, 16 or 32-bit length instruction set). It is a superset of the ARMv7-A instruction set, so that it retains the backwards compatibility necessary to run existing software. There are some additions to A32 and T32 to maintain alignment with the A64 instruction set, including NEON division, and the Cryptographic Extension instructions. NEON double precision floating point (IEEE compliance) is also supported.
I kind of asked a similar question a while back on the GCC mailing list at How to test Aarch32 execution environment on Aarch64? But I did not quite understand the answer:
Once you're compiling with an arm toolchain the CRC extension can be enabled through -march=armv8-a+crc or selecting an -mcpu option that enables it. To enable the Crypto extension you'll have to specify the right -mfpu option.
My question is simple... How do I enable both CRC and Crypto extensions for the Raspberry Pi 3?
Here are some attempts that don't work.
Attempt (4) is similar to how we do it natively under Aarch64: gcc -march=armv8-a+crc+crypto -mtune=cortex-a53. Attempt (5) actually enables CRC, but I can't seem to get anything else enabled, like PMULL, PMULL2, AES, SHA1 and SHA2.
gcc -D__ARM_FEATURE_CRYPTO -D__ARM_FEATURE_CRC -march=armv8-a+crc+crypto -mcpu=cortex-a53 -mfpu=neon test.cc -o test.exe
gcc -D__ARM_FEATURE_CRYPTO -D__ARM_FEATURE_CRC -march=armv8-a+crc -mcpu=cortex-a53 -mfpu=neon test.cc -o test.exe
gcc -D__ARM_FEATURE_CRYPTO -D__ARM_FEATURE_CRC -march=armv8-a -mcpu=cortex-a53 -mfpu=neon test.cc -o test.exe
gcc -march=armv8-a+crc+crypto -mcpu=cortex-a53 -mfpu=neon test.cc -o test.exe
gcc -march=armv8-a+crc -mcpu=cortex-a53 -mfpu=neon test.cc -o test.exe
gcc -march=armv8-a -mcpu=cortex-a53 -mfpu=neon test.cc -o test.exe
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.9/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Raspbian 4.9.2-10' --with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.9 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-armhf/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-armhf --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-armhf --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-sjlj-exceptions --with-arch=armv6 --with-fpu=vfp --with-float=hard --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 4.9.2 (Raspbian 4.9.2-10)
Quite simply, "the right -mfpu option" should be -mfpu=crypto-neon-fp-armv8.

CodeSourcery ARM cross-compilation

Compiling a simple test.c:
#include <stdio.h>
void main() {
printf("Hello World!\n");
while(1);
}
using CodeSourcery's arm-none-eabi-gcc I got the following errors:
arm-none-eabi-gcc -static test.c -o mytest
/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/bin/ld: warning: cannot find entry symbol _start; defaulting to 00008018
/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text+0x18): undefined reference to `_sbrk'
/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/libc.a(lib_a-writer.o): In function `_write_r':
writer.c:(.text+0x20): undefined reference to `_write'
/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/libc.a(lib_a-closer.o): In function `_close_r':
closer.c:(.text+0x18): undefined reference to `_close'
/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/libc.a(lib_a-fstatr.o): In function `_fstat_r':
fstatr.c:(.text+0x1c): undefined reference to `_fstat'
/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/libc.a(lib_a-isattyr.o): In function `_isatty_r':
isattyr.c:(.text+0x18): undefined reference to `_isatty'
/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/libc.a(lib_a-lseekr.o): In function `_lseek_r':
lseekr.c:(.text+0x20): undefined reference to `_lseek'
/opt/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/libc.a(lib_a-readr.o): In function `_read_r':
readr.c:(.text+0x20): undefined reference to `_read'
collect2: error: ld returned 1 exit status
But if i used my Ubuntu (12.04 LTS 32-bit) 's arm gcc:
arm-linux-gnueabi-gcc -static -o mytest test.c
arm-linux-gnueabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabi/4.6/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/arm-linux-gnueabi/include/c++/4.6.3 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-multilib --disable-sjlj-exceptions --with-arch=armv7-a --with-float=softfp --with-fpu=vfpv3-d16 --with-mode=thumb --disable-werror --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=arm-linux-gnueabi --program-prefix=arm-linux-gnueabi- --includedir=/usr/arm-linux-gnueabi/include --with-headers=/usr/arm-linux-gnueabi/include --with-libs=/usr/arm-linux-gnueabi/lib
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
I have no error generating the output file.
can someone explain?
My best nearest reference (but still I have no success):
Linker error on a C project using eclipse
arm-none-eabi-gcc is a compiler for bare metal arm. I.e. for running on an arm processor where you have no operating system, or where you make your own operating system. That compiler contains the newlib C library, which will provide you with most of a standard C library, but you will have to provide the low level implementations (e.g. somewhere for printf() to actually print, memory management, a file system if you need it). In short, you're much on your own having to bootstrap the processor, C runtime and load the produced code (See e.g. this question))
arm-linux-gnueabi-gcc is a compiler for targeting linux running on arm, a toolchain that'll produce executables running on linux, using the familiar glibc C library and header files.

Resources