GCC is buggy

**gcc version 6.2.1 20160830 [gcc-6-branch revision 239856] (SUSE Linux) **

Using the following source code with that compiler,
-rw-rw-r–. 1 leslie leslie **25535 **Nov 11 19:55 fstabxref.c
-rw-rw-r–. 1 leslie leslie 25535 Nov 11 19:55 lsblkexperimental.c

when compiled
-rwxr-xr-x 1 leslie leslie 36848 Nov 12 08:37 fstabxref
-rwxr-xr-x 1 leslie leslie 40952 Nov 12 08:37 lsblkexperimental

By the way, the second source file is identical to the first.

With another gcc (from Fedora 24) and the identical source code from the identical directories

-rwxrwxr-x. 1 leslie leslie 32856 Nov 11 23:40 fstabxref
-rwxrwxr-x. 1 leslie leslie **32862 **Nov 11 23:40 lsblkexperimental

Why is there 4k and 6k extras in the executable code? I used vi to view the fstabxref executable and that code has much of the commented front end of the /* source code in it’s header. */

Both compiled versions execute as expected.

Compiler flags
CFLAGS= -O3 -Wall -Wextra

How do I reinstall gcc?

And what version of openSUSE are you using?
You posting “…(SUSE Linux)” lets me assume that you do not use openSUSE at all.

Hi
It’s Tumbleweed :wink:

I am using Tumbleweed, rolling release, and its current (Yesterday, full update, including kernel). I tried zypper to remove gcc, and then zypper install gcc.

As I mentioned. I have about 100 lines of documentation before my first line of C code. Those lines appear in the executable near the beginning of the executable.

My process is to
a) compile all necessary object files
b) create a library with “AR” and the objects from a)
c) Link the current compile using that library.

So, yes, I am using Tumbleweed, not OpenSuse.

So, yes, I am using Tumbleweed, not OpenSuse.

Actually, that is also openSUSE :wink:

Which Fedora 24 GCC? GCC 4.8, GCC 5 or GCC 6?

Need to check all the GCC 6 compiler options – I suspect that you have tripped over a “new” GCC 6 feature which wasn’t present in the previous releases.

Are OK for “older” (GCC 4.8) compilers – for GCC 6 “-O3” performs optimisation as follows:

Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the -finline-functions, -funswitch-loops, -fpredictive-commoning, -fgcse-after-reload, -ftree-loop-vectorize, -ftree-loop-distribute-patterns, -fsplit-paths -ftree-slp-vectorize, -fvect-cost-model, -ftree-partial-pre and -fipa-cp-clone options.

I’m currently installing the KDE Development world (mostly GCC 48 (default) but, with GCC 6 also being installed) into my Leap 42.2 RC2 VM – will check your issues . . .
By the way, I normally use the following GCC compiler options:

  • Warnings: -Wall -Wextra -Wformat=2
  • Machine: -m64 -mtune=generic

With YaST: search for gcc6 – remove the GCC 6 packages; search for gcc – install the GCC 4.8 or GCC 5 packages as you need.
[HR][/HR]It’s not a bug, it’s a feature!

I forgot to mention update-alternatives:


linux-o020:~ # update-alternatives --display java
java - auto mode
  link best version is /usr/lib64/jvm/jre-1.8.0-openjdk/bin/java
  link currently points to /usr/lib64/jvm/jre-1.8.0-openjdk/bin/java
  link java is /usr/bin/java
  slave java.1.gz is /usr/share/man/man1/java.1.gz
  slave jre is /usr/lib64/jvm/jre
  slave jre_exports is /usr/lib64/jvm-exports/jre
  slave keytool is /usr/bin/keytool
  slave keytool.1.gz is /usr/share/man/man1/keytool.1.gz
  slave orbd is /usr/bin/orbd
  slave orbd.1.gz is /usr/share/man/man1/orbd.1.gz
  slave policytool is /usr/bin/policytool
  slave policytool.1.gz is /usr/share/man/man1/policytool.1.gz
  slave policytool.desktop is /usr/share/applications/policytool.desktop
  slave rmid is /usr/bin/rmid
  slave rmid.1.gz is /usr/share/man/man1/rmid.1.gz
  slave rmiregistry is /usr/bin/rmiregistry
  slave rmiregistry.1.gz is /usr/share/man/man1/rmiregistry.1.gz
  slave servertool is /usr/bin/servertool
  slave servertool.1.gz is /usr/share/man/man1/servertool.1.gz
  slave tnameserv is /usr/bin/tnameserv
  slave tnameserv.1.gz is /usr/share/man/man1/tnameserv.1.gz
/usr/lib64/jvm/jre-1.7.0-openjdk/bin/java - priority 1705
  slave java.1.gz: /usr/share/man/man1/java-java-1.7.0-openjdk.1.gz
  slave jre: /usr/lib64/jvm/jre-1.7.0-openjdk
  slave jre_exports: /usr/lib64/jvm-exports/jre-1.7.0-openjdk
  slave keytool: /usr/lib64/jvm/jre-1.7.0-openjdk/bin/keytool
  slave keytool.1.gz: /usr/share/man/man1/keytool-java-1.7.0-openjdk.1.gz
  slave orbd: /usr/lib64/jvm/jre-1.7.0-openjdk/bin/orbd
  slave orbd.1.gz: /usr/share/man/man1/orbd-java-1.7.0-openjdk.1.gz
  slave policytool: /usr/lib64/jvm/jre-1.7.0-openjdk/bin/policytool
  slave policytool.1.gz: /usr/share/man/man1/policytool-java-1.7.0-openjdk.1.gz
  slave policytool.desktop: /usr/lib64/jvm/java-1.7.0-openjdk-1.7.0/jre/lib/desktop/policytool.desktop
  slave rmid: /usr/lib64/jvm/jre-1.7.0-openjdk/bin/rmid
  slave rmid.1.gz: /usr/share/man/man1/rmid-java-1.7.0-openjdk.1.gz
  slave rmiregistry: /usr/lib64/jvm/jre-1.7.0-openjdk/bin/rmiregistry
  slave rmiregistry.1.gz: /usr/share/man/man1/rmiregistry-java-1.7.0-openjdk.1.gz
  slave servertool: /usr/lib64/jvm/jre-1.7.0-openjdk/bin/servertool
  slave servertool.1.gz: /usr/share/man/man1/servertool-java-1.7.0-openjdk.1.gz
  slave tnameserv: /usr/lib64/jvm/jre-1.7.0-openjdk/bin/tnameserv
  slave tnameserv.1.gz: /usr/share/man/man1/tnameserv-java-1.7.0-openjdk.1.gz
/usr/lib64/jvm/jre-1.8.0-openjdk/bin/java - priority 1805
  slave java.1.gz: /usr/share/man/man1/java-java-1.8.0-openjdk.1.gz
  slave jre: /usr/lib64/jvm/jre-1.8.0-openjdk
  slave jre_exports: /usr/lib64/jvm-exports/jre-1.8.0-openjdk
  slave keytool: /usr/lib64/jvm/jre-1.8.0-openjdk/bin/keytool
  slave keytool.1.gz: /usr/share/man/man1/keytool-java-1.8.0-openjdk.1.gz
  slave orbd: /usr/lib64/jvm/jre-1.8.0-openjdk/bin/orbd
  slave orbd.1.gz: /usr/share/man/man1/orbd-java-1.8.0-openjdk.1.gz
  slave policytool: /usr/lib64/jvm/jre-1.8.0-openjdk/bin/policytool
  slave policytool.1.gz: /usr/share/man/man1/policytool-java-1.8.0-openjdk.1.gz
  slave policytool.desktop: /usr/lib64/jvm/java-1.8.0-openjdk-1.8.0/jre/lib/desktop/policytool.desktop
  slave rmid: /usr/lib64/jvm/jre-1.8.0-openjdk/bin/rmid
  slave rmid.1.gz: /usr/share/man/man1/rmid-java-1.8.0-openjdk.1.gz
  slave rmiregistry: /usr/lib64/jvm/jre-1.8.0-openjdk/bin/rmiregistry
  slave rmiregistry.1.gz: /usr/share/man/man1/rmiregistry-java-1.8.0-openjdk.1.gz
  slave servertool: /usr/lib64/jvm/jre-1.8.0-openjdk/bin/servertool
  slave servertool.1.gz: /usr/share/man/man1/servertool-java-1.8.0-openjdk.1.gz
  slave tnameserv: /usr/lib64/jvm/jre-1.8.0-openjdk/bin/tnameserv
  slave tnameserv.1.gz: /usr/share/man/man1/tnameserv-java-1.8.0-openjdk.1.gz
linux-o020:~ # 

Unfortunately, on openSUSE Leap 42.2 RC2, “update-alternatives --get-selections” doesn’t mention any GCC alternatives: I’ll have to add them by hand.

Leap 4.2. RC2: some GCC 6 versus GCC 4.8 tests:


test001@linux-o020:~/Projekte/LinuxSystem> l -h GCC-*/
GCC-4.8/:
insgesamt 56K
drwxr-xr-x 2 test001 users  68 14. Nov 17:08 ./
drwxrwx--- 7 test001 users  99 14. Nov 17:07 ../
-rwxr-xr-x 1 test001 users 14K 14. Nov 17:06 posix_perror*
-rwxr-xr-x 1 test001 users 19K 14. Nov 17:06 posix_strerror*
-rwxr-xr-x 1 test001 users 18K 14. Nov 17:06 posix_syslog*

GCC-6/:
insgesamt 56K
drwxr-xr-x 2 test001 users  68 14. Nov 17:01 ./
drwxrwx--- 7 test001 users  99 14. Nov 17:07 ../
-rwxr-xr-x 1 test001 users 15K 14. Nov 16:55 posix_perror*
-rwxr-xr-x 1 test001 users 20K 14. Nov 16:55 posix_strerror*
-rwxr-xr-x 1 test001 users 20K 14. Nov 16:55 posix_syslog*
test001@linux-o020:~/Projekte/LinuxSystem> 

Yes, the GCC 6 executables have about 1K more data that the GCC 4.8 executables compiled from the same “C” code.

KDevelop5 – CMake report with GCC 6 active:


/home/test001/Projekte/LinuxSystem/ErrorHandling/build> /usr/bin/cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug /home/test001/Projekte/LinuxSystem/ErrorHandling
-- CMake Version: 3.5.2
-- Default C Compiler: 
-- Default C++ Compiler: 
-- Project C Compiler: /usr/bin/gcc-6
-- Project C++ Compiler: /usr/bin/g++-6
-- Host System: Linux-4.4.27-2-default x86_64
-- Top Level Project Name: ErrorHandling
-- Binaries Directory: /home/test001/Projekte/LinuxSystem/ErrorHandling/build
-- Source Directory: /home/test001/Projekte/LinuxSystem/ErrorHandling
-- Build type: Debug
-- C Compiler Debug Flags: -g
-- C++ Compiler Debug Flags: -g
-- Linker Debug Flags: 

[HR][/HR]But, neither “od -a” nor “vi” reveal any C-source header text in the ELF 64-bit executables noted below:


test001@linux-o020:~/Projekte/LinuxSystem> file GCC-4.8/posix_perror GCC-6/posix_perror 
GCC-4.8/posix_perror: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.0.0, BuildID[sha1]=8eec8f556ae444943ea1a10bad8d24fe3473483e, not stripped
GCC-6/posix_perror:   ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.0.0, BuildID[sha1]=9832ccac1a8ff23e005564f56241deafe294d48a, not stripped
test001@linux-o020:~/Projekte/LinuxSystem> 

[HR][/HR]Conclusion: yes, given the same compiler options, GCC 6 seems to generate marginally larger ELF executable files than those generated by GCC 4.8.
Why, no idea – it does – it’s a feature!!!
[HR][/HR]As far as I can see, there’s also nothing here: <https://gcc.gnu.org/gcc-6/changes.html>

I can provide a tar file with the libraries.

On Fedora 24, I compile with

gcc version 6.2.1 20160916 (Red Hat 6.2.1-2) (GCC)

On Suse, it is as pasted above, my initial complaint.
My system is x64, with 8gigs ram.

Presumeably the compiler update is 2016 09 16

Next question… Reinstall tumbleweed (nothing buggy with my use of it)

@lsatenstein:
If executable code size is an issue for you then, the following GCC documentation is relevant: <https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html>

  • Using either the “-Os” or “-O2” compiler options are the default methods for producing the smallest executable code size.

[HR][/HR]Please be aware that, even a compiler such as GCC cannot perform “magic” – it only a performs (a rather complicated) “best effort” to produce the best possibly runtime executable image from the code supplied by the programmers.
The golden rule is:

“First compile, debug and analyse the runtime behaviour without any compiler optimisations; only when it has been demonstrated that, the code base performs well and behaves as expected, enable the compiler optimisations and check for possible improvements.”

The current Tumbleweed versions of GCC-6 are as follows:

  • openSUSE Factory: 6.2.1 (r239849) – committed 2 months ago.
  • devel:gcc: 6.2.1 (r241818) – committed 12 days ago.

One could switch to the “devel:gcc” repository, which is, as the name suggests, a preview of a future Factory Release. But, in doing so there is no guarantee that, unexpected pre-release issues will occur.
[HR][/HR]BTW: have you taken a look at the following GCC page? <https://gcc.gnu.org/gcc-6/porting_to.html&gt;