jahboater
Posts: 5759
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

New major release of GCC

Fri May 08, 2020 9:22 am

GCC 10.1 released.
https://gcc.gnu.org/gcc-10/

This script will download, build, and optionally install it on a Pi4. It must be altered for earlier Pi's.

Code: Select all

#!/bin/bash
# REMEMBER TO UNCOMMENT THE CONFIGURE LINE FOR YOUR TARGET PLATFORM.
# ... and comment out the default of course.

#
#  This is the new GCC version to install.
#
VERSION=10.1.0

#
#  These are the languages the new compiler should support.
#
LANG=c,c++,fortran

#
#  For any computer with less than 2GB of memory.
#
#if [ -f /etc/dphys-swapfile ]; then
#  sudo sed -i 's/^CONF_SWAPSIZE=[0-9]*$/CONF_SWAPSIZE=1024/' /etc/dphys-swapfile
#  sudo /etc/init.d/dphys-swapfile restart
#fi

if [ -d gcc-$VERSION ]; then
  cd gcc-$VERSION
  rm -rf obj
else
  wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-$VERSION/gcc-$VERSION.tar.xz
  tar xf gcc-$VERSION.tar.xz
  rm -f gcc-$VERSION.tar.xz
  cd gcc-$VERSION
  contrib/download_prerequisites
fi
mkdir -p obj
cd obj

#
#  Now run the ./configure which must be checked/edited beforehand.
#  Uncomment the sections below depending on your platform.  You may build
#  on a Pi3 for a target Pi Zero by uncommenting the Pi Zero section.
#  To alter the target directory set --prefix=<dir>
#  For a very quick buid try: --disable-bootstrap
#

# Pi3+, Pi3, Pi4 (32-bit)
../configure --enable-languages=$LANG --with-cpu=cortex-a72 \
  --with-fpu=neon-fp-armv8 --with-float=hard --build=arm-linux-gnueabihf \
  --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf

# Pi4 (64-bit)
#../configure --enable-languages=$LANG --with-cpu=cortex-a72

# Pi Zero's
#../configure --enable-languages=$LANG --with-cpu=arm1176jzf-s \
#  --with-fpu=vfp --with-float=hard --build=arm-linux-gnueabihf \
#  --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf

# x86_64
#../configure --disable-multilib --enable-languages=$LANG

# Old Pi2
#../configure --enable-languages=$LANG --with-cpu=cortex-a7 \
#  --with-fpu=neon-vfpv4 --with-float=hard --build=arm-linux-gnueabihf \
#  --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf

#
#  Now build GCC which will take a long time.  This could range from
#  3 hours on a 4GB Pi4 up to about 50 hours on a Pi Zero.  It can be
#  left to complete overnight (or over the weekend for a Pi Zero :-)
#  The most likely causes of failure are lack of disk space, lack of
#  swap space or memory, or the wrong configure section uncommented.
#  The new compiler is placed in /usr/local/bin, the existing compiler remains
#  in /usr/bin and may be used by giving its version gcc-6 (say).
#
if make -j `nproc`
then
  echo
  read -p "Do you wish to install the new GCC (y/n)? " yn
  case $yn in
   [Yy]* ) sudo make install ;;
	 * ) exit ;;
  esac
fi

Last edited by jahboater on Mon Jul 06, 2020 7:10 am, edited 1 time in total.
Pi4 8GB running PIOS64

User avatar
buja
Posts: 567
Joined: Wed Dec 31, 2014 8:21 am
Location: Netherlands

Re: New major release of GCC

Fri May 08, 2020 10:57 am

I am compiling GCC 10.1 on a Pi 4B-4GB. Right now it has been running for half an hour, all 4 cores are busy with it and the maximum CPU temperature so far is 68 degrees.

GlowInTheDark
Posts: 683
Joined: Sat Nov 09, 2019 12:14 pm

Re: New major release of GCC

Fri May 08, 2020 11:15 am

Isn't this the part where you tell us why we should care?

I.e., what are the new features? What makes it great? How is it better than anything which preceded it?
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

Heater
Posts: 15949
Joined: Tue Jul 17, 2012 3:02 pm

Re: New major release of GCC

Fri May 08, 2020 11:23 am

Wake me up when it goes to 11. :)

Historically I would have been all of over this. But I doubt there is anything new in the C compiler I might need and since discovering Rust there is no way I'm going back to the nightmare of C++.

I hear rumor that there are people looking into creating Rust front end for GCC. Which would be great. I don't expect to see it happen soon.
Memory in C++ is a leaky abstraction .

jahboater
Posts: 5759
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: New major release of GCC

Fri May 08, 2020 12:01 pm

GlowInTheDark wrote:
Fri May 08, 2020 11:15 am
I.e., what are the new features? What makes it great? How is it better than anything which preceded it?
See:
https://gcc.gnu.org/gcc-10/changes.html
Pi4 8GB running PIOS64

jahboater
Posts: 5759
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: New major release of GCC

Fri May 08, 2020 12:04 pm

Heater wrote:
Fri May 08, 2020 11:23 am
I'm going back to the nightmare of C++
:) There is a more complete C++20 implementation ... :)

For C,
There is more static analysis. This new option takes ages to run but it found a really deep and rare problem in my code.
Unusual and complicated. But it was right and I was eventually able to construct a test case causing the failure.

Code: Select all

 -fanalyzer
       This option enables an static analysis of program flow which looks for "interesting"
       interprocedural paths through the code, and issues warnings for problems found on
       them.

       This analysis is much more expensive than other GCC warnings.

       Enabling this option effectively enables the following warnings:

       -Wanalyzer-double-fclose -Wanalyzer-double-free
       -Wanalyzer-exposure-through-output-file -Wanalyzer-file-leak
       -Wanalyzer-free-of-non-heap -Wanalyzer-malloc-leak -Wanalyzer-possible-null-argument
       -Wanalyzer-possible-null-dereference -Wanalyzer-null-argument
       -Wanalyzer-null-dereference -Wanalyzer-stale-setjmp-buffer
       -Wanalyzer-tainted-array-index -Wanalyzer-unsafe-call-within-signal-handler
       -Wanalyzer-use-after-free -Wanalyzer-use-of-pointer-in-stale-stack-frame
Pi4 8GB running PIOS64

Heater
Posts: 15949
Joined: Tue Jul 17, 2012 3:02 pm

Re: New major release of GCC

Fri May 08, 2020 1:56 pm

jahboater wrote:
Fri May 08, 2020 12:04 pm
There is a more complete C++20 implementation
Yawn.
jahboater wrote:
Fri May 08, 2020 12:04 pm
For C,
There is more static analysis.
OKaaay, now you have my attention. That is mighty cool.

Static analysis in GCC 10: https://developers.redhat.com/blog/2020 ... in-gcc-10/
Memory in C++ is a leaky abstraction .

DarkElvenAngel
Posts: 802
Joined: Tue Mar 20, 2018 9:53 pm

Re: New major release of GCC

Fri May 08, 2020 2:12 pm

buja wrote:
Fri May 08, 2020 10:57 am
I am compiling GCC 10.1 on a Pi 4B-4GB. Right now it has been running for half an hour, all 4 cores are busy with it and the maximum CPU temperature so far is 68 degrees.
How long did it take to compile?

I will be running this but how do I install it so I can use either 10 or I believe 8 is the raspbian stock.

Is it just symlinks?

jahboater
Posts: 5759
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: New major release of GCC

Fri May 08, 2020 2:50 pm

DarkElvenAngel wrote:
Fri May 08, 2020 2:12 pm
How long did it take to compile?
I built it to include C, C++, and Fortran. It took 3.5 hours on my Pi4.
DarkElvenAngel wrote:
Fri May 08, 2020 2:12 pm
I will be running this but how do I install it so I can use either 10 or I believe 8 is the raspbian stock.
Just type "cc" or "gcc" to get GCC 10. You can use the original compiler (GCC 8) by giving "gcc-8"
gcc -v tells you the version.

Use the script provided above. It will download and build it.
At the end you are given the option of installing it.
If you have only 1GB, then uncomment the section at the start which adds some swap.

The manual page ("man gcc") is installed as well.
Pi4 8GB running PIOS64

DarkElvenAngel
Posts: 802
Joined: Tue Mar 20, 2018 9:53 pm

Re: New major release of GCC

Fri May 08, 2020 3:13 pm

jahboater wrote:
Fri May 08, 2020 2:50 pm
DarkElvenAngel wrote:
Fri May 08, 2020 2:12 pm
How long did it take to compile?
I built it to include C, C++, and Fortran. It took 3.5 hours on my Pi4.
DarkElvenAngel wrote:
Fri May 08, 2020 2:12 pm
I will be running this but how do I install it so I can use either 10 or I believe 8 is the raspbian stock.
Just type "cc" or "gcc" to get GCC 10. You can use the original compiler (GCC 8) by giving "gcc-8"
gcc -v tells you the version.

Use the script provided above. It will download and build it.
At the end you are given the option of installing it.
If you have only 1GB, then uncomment the section at the start which adds some swap.

The manual page ("man gcc") is installed as well.
Awesome thanks. I have it working away I switched to support all pi models.

Just because I don't really know much about the compiled output. When I build a project and use a compiler that will support all pi models, if that project was compiled only for the latest models would there be a performance increase from the build?

I know the output wouldn't run on say a zero but if I only ran it on a 3 or better?

I hope that makes sense.

ejolson
Posts: 5373
Joined: Tue Mar 18, 2014 11:47 am

Re: New major release of GCC

Fri May 08, 2020 3:31 pm

jahboater wrote:
Fri May 08, 2020 2:50 pm
DarkElvenAngel wrote:
Fri May 08, 2020 2:12 pm
How long did it take to compile?
I built it to include C, C++, and Fortran. It took 3.5 hours on my Pi4.
DarkElvenAngel wrote:
Fri May 08, 2020 2:12 pm
I will be running this but how do I install it so I can use either 10 or I believe 8 is the raspbian stock.
Just type "cc" or "gcc" to get GCC 10. You can use the original compiler (GCC 8) by giving "gcc-8"
gcc -v tells you the version.

Use the script provided above. It will download and build it.
At the end you are given the option of installing it.
If you have only 1GB, then uncomment the section at the start which adds some swap.

The manual page ("man gcc") is installed as well.
One thing that's sure to make Fido's tail start wagging is
GCC 10 Release Notes wrote: Extended characters in identifiers may now be specified directly in the input encoding (UTF-8, by default), in addition to the UCN syntax (\uNNNN or \UNNNNNNNN) that is already supported:

Code: Select all

static const int π = 3;
int get_naïve_pi() {
  return π;
}
A similar idea (but not that of defining π to be 3) was discussed at

viewtopic.php?t=118161

Having implemented the real thing for pcc a few years back

http://pcc.ludd.ltu.se/documentation/

I found a simple hack to make iconv achieve nearly the same result for gcc.
In the end that caused trouble with C++ raw string literals and was rejected. Lewis Hyatt took up the task of making a proper patch a few years later and seems to have done an excellent job.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67224

Hopefully the preprocessor works too. Note this feature has been part of clang and Microsoft C++ for some time.

jahboater
Posts: 5759
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: New major release of GCC

Fri May 08, 2020 5:08 pm

DarkElvenAngel wrote:
Fri May 08, 2020 3:13 pm
I know the output wouldn't run on say a zero but if I only ran it on a 3 or better?
The Cortex-A72 in the Pi4 and the Cortex-A53 in the Pi3 are compatible.
They are used in big.little SoC's where the code may run on either.
I think the advice is to optimize for the faster processor (the A72).

If you ever try building GCC for the Pi Zero, be patient!!!!! it takes about two days (but does work fine).
Pi4 8GB running PIOS64

ejolson
Posts: 5373
Joined: Tue Mar 18, 2014 11:47 am

Re: New major release of GCC

Fri May 08, 2020 5:24 pm

jahboater wrote:
Fri May 08, 2020 5:08 pm
DarkElvenAngel wrote:
Fri May 08, 2020 3:13 pm
I know the output wouldn't run on say a zero but if I only ran it on a 3 or better?
The Cortex-A72 in the Pi4 and the Cortex-A53 in the Pi3 are compatible.
They are used in big.little SoC's where the code may run on either.
I think the advice is to optimize for the faster processor (the A72).

If you ever try building GCC for the Pi Zero, be patient!!!!! it takes about two days (but does work fine).
Are you building it on a Zero? How much and what kind of swap did you use?

DarkElvenAngel
Posts: 802
Joined: Tue Mar 20, 2018 9:53 pm

Re: New major release of GCC

Fri May 08, 2020 5:48 pm

ejolson wrote:
Fri May 08, 2020 5:24 pm
jahboater wrote:
Fri May 08, 2020 5:08 pm
DarkElvenAngel wrote:
Fri May 08, 2020 3:13 pm
I know the output wouldn't run on say a zero but if I only ran it on a 3 or better?
The Cortex-A72 in the Pi4 and the Cortex-A53 in the Pi3 are compatible.
They are used in big.little SoC's where the code may run on either.
I think the advice is to optimize for the faster processor (the A72).

If you ever try building GCC for the Pi Zero, be patient!!!!! it takes about two days (but does work fine).
Are you building it on a Zero? How much and what kind of swap did you use?
Hahaha, no I am not that patient, I'm using a Pi4 4Gb. I'm building for Pi Zero.

jahboater
Posts: 5759
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: New major release of GCC

Fri May 08, 2020 6:24 pm

ejolson wrote:
Fri May 08, 2020 5:24 pm
Are you building it on a Zero? How much and what kind of swap did you use?
No. I have done in the past (with earlier versions of GCC) and just added the usual 1GB of swap with:

Code: Select all

if [ -f /etc/dphys-swapfile ]; then
  sudo sed -i 's/^CONF_SWAPSIZE=[0-9]*$/CONF_SWAPSIZE=1024/' /etc/dphys-swapfile
  sudo /etc/init.d/dphys-swapfile restart
fi
The build works fine, but you have to leave it running over a weekend!
As DarkElvenAngel is trying, it should work cross compiled from a Pi4.

If you take the script at the start of this thread, comment out the Pi3/Pi4 config, uncomment the PiZero config, and uncomment the swapfile bit, it should just run. It does make -j `nproc` so uses its one core.
Actually, with make -j 1 the build might work without adding any extra swap - I cant remember.

Edit: Purely for fun I just started a build off on a Pi Zero :)
I'll let you know next week if it worked .....
Pi4 8GB running PIOS64

DarkElvenAngel
Posts: 802
Joined: Tue Mar 20, 2018 9:53 pm

Re: New major release of GCC

Fri May 08, 2020 7:24 pm

Compile completed it took about 7 hours start to finish and installed

Not too bad.

jahboater
Posts: 5759
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: New major release of GCC

Fri May 08, 2020 7:43 pm

DarkElvenAngel wrote:
Fri May 08, 2020 7:24 pm
Compile completed it took about 7 hours start to finish and installed

Not too bad.
By the way, its actually built it three times!!
Pi4 8GB running PIOS64

DarkElvenAngel
Posts: 802
Joined: Tue Mar 20, 2018 9:53 pm

Re: New major release of GCC

Fri May 08, 2020 7:53 pm

jahboater wrote:
Fri May 08, 2020 7:43 pm
DarkElvenAngel wrote:
Fri May 08, 2020 7:24 pm
Compile completed it took about 7 hours start to finish and installed

Not too bad.
By the way, its actually built it three times!!
Yes I left the verify on, Still good it did eat into 21 Mb of my swap so I would recommend having some swap on, I have 3.81 Gb of memory

Nice and smooth and I tried out the -fanalyzer and it found -Wanalyzer-unsafe-call-within-signal-handler in my serial mouse project not bad very helpful tracing.

GlowInTheDark
Posts: 683
Joined: Sat Nov 09, 2019 12:14 pm

Re: New major release of GCC

Fri May 08, 2020 8:33 pm

The build works fine, but you have to leave it running over a weekend!
As DarkElvenAngel is trying, it should work cross compiled from a Pi4.
It'd be even better if there were complete, concise, repeatable, follow-able instructions for cross-compiling it on your shiny, powerful X64 box (running Linux, of course) - which would go much faster than on the Pi4.
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

Heater
Posts: 15949
Joined: Tue Jul 17, 2012 3:02 pm

Re: New major release of GCC

Fri May 08, 2020 8:43 pm

GlowInTheDark wrote:
Fri May 08, 2020 8:33 pm
It'd be even better if there were complete, concise, repeatable, follow-able instructions for cross-compiling it on your shiny, powerful X64 box (running Linux, of course) - which would go much faster than on the Pi4.
I have been dreaming of such a thing since about 2000.

From time to time I have even achieved it.
Memory in C++ is a leaky abstraction .

ejolson
Posts: 5373
Joined: Tue Mar 18, 2014 11:47 am

Re: New major release of GCC

Fri May 08, 2020 8:56 pm

Heater wrote:
Fri May 08, 2020 8:43 pm
GlowInTheDark wrote:
Fri May 08, 2020 8:33 pm
It'd be even better if there were complete, concise, repeatable, follow-able instructions for cross-compiling it on your shiny, powerful X64 box (running Linux, of course) - which would go much faster than on the Pi4.
I have been dreaming of such a thing since about 2000.

From time to time I have even achieved it.
The default bootstrap process in which the binary for the new compiler is tested by using it to compile itself posses a not insurmountable problem for cross compiling the compiler: Either skip the bootstrap or use a QEMU environment as done for the binary Gentoo images.

Soon the fastest way will be a many-core Graviton2 instance in the Amazon cloud, unless the Pi 5 comes out first.

Heater
Posts: 15949
Joined: Tue Jul 17, 2012 3:02 pm

Re: New major release of GCC

Fri May 08, 2020 9:04 pm

Not an insurmountable problem. As I say I have done it on occasion, for ARM, MIPS, POWER, RISC V.

Just a different problem every time.
Memory in C++ is a leaky abstraction .

ejolson
Posts: 5373
Joined: Tue Mar 18, 2014 11:47 am

Re: New major release of GCC

Fri May 08, 2020 10:09 pm

Heater wrote:
Fri May 08, 2020 9:04 pm
Not an insurmountable problem. As I say I have done it on occasion, for ARM, MIPS, POWER, RISC V.

Just a different problem every time.
Agreed. Just started a -j4 build of gcc 10.1 on the Pi 4B here with

--enable-languages=c,c++,fortran

and the same options as described in the shell script of the original post to this thread. This is the 2GB model in which swap and the build directories are mounted on an iSCSI drive connected locally through WireGuard. Everything is stock speed. I am interested to know whether it will finish more quickly or slowly compared to the other reports.

Then, it will be on to checking whether 💩 can be used as a variable name.

ejolson
Posts: 5373
Joined: Tue Mar 18, 2014 11:47 am

Re: New major release of GCC

Sat May 09, 2020 2:12 am

ejolson wrote:
Fri May 08, 2020 10:09 pm
I am interested to know whether it will finish more quickly or slowly compared to the other reports.
The command

$ nohup time make -j4 >world.log 2>&1 &

just finished with the report

Code: Select all

43263.01user 3026.42system 3:47:18elapsed 24%CPU (0avgtext+0avgdata 559976maxresident)k
5321056inputs+20579864outputs (53921major+163622952minor)pagefaults 0swaps
which suggests that it took 3 hours and 47 minutes to compile gcc 10.1. Therefore, if people are really seeing 7 hours when using an SD card, then iSCSI over a WireGuard VPN is almost twice as fast.

Update: I just ran the Pi Pie Chart program and the merge sort regression introduced in the 7.x compilers has been fixed. The result is a 61 percent improvement compared to the Rasbian system compiler. More information is available in the thread

viewtopic.php?f=63&t=227177&p=1657704#p1657704

DarkElvenAngel
Posts: 802
Joined: Tue Mar 20, 2018 9:53 pm

Re: New major release of GCC

Sat May 09, 2020 2:33 am

ejolson wrote:
Sat May 09, 2020 2:12 am
ejolson wrote:
Fri May 08, 2020 10:09 pm
I am interested to know whether it will finish more quickly or slowly compared to the other reports.
The command

$ nohup time make -j4 >world.log 2>&1 &

just finished with the report

Code: Select all

43263.01user 3026.42system 3:47:18elapsed 24%CPU (0avgtext+0avgdata 559976maxresident)k
5321056inputs+20579864outputs (53921major+163622952minor)pagefaults 0swaps
which suggests that it took 3 hours and 47 minutes to compile gcc 10.1. Therefore, if people are really seeing 7 hours when using an SD card, then iSCSI over a WireGuard VPN is almost twice as fast.
Was that skipping the verification of the compiler? I wasn't sitting watching the compile the whole time it may have finished sooner. Maybe I'll recompile on my other card and see what time I get.

Return to “C/C++”