C compiler problem with linking/binding objects

I wrote an application that creates a cross reference to the entries within a /etc/fstab.
This application has two linked in modules as shown below. The compiler is gcc 6.2.1

Module                Tumbleweed                         Fedora 
strtrim.o               1632                                 1608  
dictionary.o            14072                               14048

The differences in sizes are acceptable. (I browsed the respective object files and the Fedora 6.2.1 appears trivially more efficient.

But the problem arises when I link them together with the program containing main.

Module                 Tumbleweed                       Fedora
fstabxref               **40968                           32872   **                 


**The tumbleweed executable size is 8k larger than the Fedora executable

What I am demonstrating with the above table is that the something is wrong, not with the compiler, but with the binding of the objects together to create the program.

By the way, the output file from the Tumbleweed and Fedora program versions are identical.
**

#<file system>                              <mount>     <type>  <options>         <dmpPass>  <xref>      <label> 
UUID=7a383a4d-3fd0-4860-b89a-85c3a2be2171   swap        swap    defaults            0  0     #/dev/sdb1  sdb1SUSEswap 
UUID=30b63967-99d9-47e3-a8fd-82684b70343a   swap        swap    defaults            0  0     #/dev/sdb7  sdb7SuseSwap 
UUID=282c6874-1242-401d-8a95-b842b28b86b0   /           xfs     defaults            1  1     #/dev/sdb5   
UUID=cf25cfe7-0a76-4732-8ad7-5cd38337a906   /home       xfs     defaults            1  2     #/dev/sdb6   
UUID=6e488205-8791-41c2-8043-5051f8d0b185   /scratch    ext4    defaults,noatime    1  2     #/dev/sdb2  sdb2scratch


If you would like a complete copy of the sources and executables just post a request, All you will need is gcc and make (sudo zypper install gcc make)

Wouldn’t you think that a thread like this will find other programmers looking at it when it was in the Development > Programming/Scripting forum sooner then here?

When you want me to move this there, please ask so.

Until this thread is moved (I think it should be),

  • You might run your app in an IDE where you can insert breakpoints
  • You can instrument your application to write to stdout at significant places.

Although your application might be very simple, it’s possible that there are significant differences how your app runs when compiled differently, the differences you think are insignificant may not be.

Also,
I expect the two compilers are not <exactly> identical, so switch compilers (likely just copy the compiler from one platform to the other) to see if there is any difference, particularly if your application is not <only> your source but also calls libraries from the distro.

TSU

As the OP does not seem to be very eager to see if people try to help him, I will take the decision. This will be moved to Programming/Scripting and is CLOSED for the moment.

Move from Applications and open again.

Hi Henke

Thank you for relocating the posting.
I have tested my gcc compiled differences with another program

-rwxrwxr-x. 1 leslie leslie 51784 Dec 24 16:38 rijndael-test-fst Fedora
-rwxr-xr-x 1 leslie leslie 55792 Dec 26 12:07 rijndael-test-fst Tumbleweed

-rw-rw-r–1 leslie leslie 27008 Dec 24 16:38 rijndael-alg-fst.o Fedora
-rw-r–r-- 1 leslie leslie 27032 Dec 26 12:07 rijndael-alg-fst.o Tumbleweed

Given the past week, the announcement of a more recent gcc compiler package, perhaps it would be great if that package was made available as a pre-tumbleweed test version.

The compiler itself is producing code that is differing by 24 bytes between the two version. Could that 24 bytes be a call to an external reference?

The makefile for rijendael’s aes follows

# Example Makefile for the optimised ANSI C Rijndael code
# v3.0 
vpath %c ./src
vpath %h ./src

.PHONY: clean all test

CFLAGS=-Wall -O3  -DTRACE_KAT_MCT -DINTERMEDIATE_VALUE_KAT -Wextra
CC=gcc
all:    rijndael-test-fst

rijndael-test-fst: rijndael-test-fst.c obj/rijndael-api-fst.o obj/rijndael-alg-fst.o
    ${CC} ${CFLAGS}  $< -o $@ obj/rijndael-api-fst.o obj/rijndael-alg-fst.o

obj/rijndael-api-fst.o: rijndael-api-fst.c rijndael-alg-fst.h  rijndael-api-fst.c  rijndael-api-fst.h 
    ${CC} ${CFLAGS} -c $< -o $@ 

obj/rijndael-alg-fst.o: rijndael-alg-fst.c rijndael-alg-fst.h rijndael-api-fst.h 
    ${CC} ${CFLAGS} -c $< -o $@ 

clean:
    @rm -rf *.o rijndael-test-fst obj/*

test:    
    ./rijndael-test-fst


The makefile for the fstabxref program follows:

#########################################################################
# makefile for fstab formatter                                          #
# includes new data dictionary                                          #
# Warning. VPATH should not have any *.o files from this makefile       #
# Reminder $< input file   $@ output file                               #
# The lib/libdictionary.a is created only if necessary                  #
#########################################################################
#
#AR          = ar
#ARFLAGS = rscv
CC=gcc      
CFLAGS=  -O3  -Wall  -Wextra -fPIC # -DNDEBUG
LIBDIR=lib
LIB = lib/libdictionary.a
vpath %c ./src
vpath %h ./src
OBJDIR=obj
OBJS=obj/dictionary.o obj/strtrim.o

PROGS=    fstabxref lsblkexperimental #
     
all    : dirs ${PROGS} $(LIB) 
default : dirs ${PROGS} $(LIB) 
#dict    :  $(LIB) 
.PHONY : clean all install tar cleantest
clean: 
    @rm -rf ${PROGS} *.o $(OBJDIR) *CHECKSUM fstabxref.tar $(LIBDIR)

cleantest:
    @rm -rf fstabxref.tar *CHECKSUM lib obj

install:
    @cp fstabxref   ~/bin 
    @sudo cp fstabxref /usr/bin
    @echo "Installed to /usr/bin and to ~/bin "

fstabxref: fstabxref.c $(LIB) dictionary.h   
    ${CC} ${CFLAGS} $< $(LIB) -o $@

lsblkexperimental : lsblkexperimental.c  $(LIB) dictionary.h
    ${CC} ${CFLAGS} $< $(LIB) -o $@


.PHONY: dirs
dirs:   lib obj
obj:    
    mkdir -p obj
lib:
     mkdir -p lib

$(LIB) : $(OBJS) $(LIBDIR)  
    @ar rscv $(LIB)  $(OBJS)   >/dev/null

obj/dictionary.o: dictionary.c dictionary.h obj/strtrim.o
    $(CC) $(CFLAGS) src/dictionary.c -c -o obj/dictionary.o 

obj/strtrim.o: strtrim.c strtrim.h
    $(CC) $(CFLAGS) $< -c -o  $@
    
tar:
    @sha256sum fstabxref README*  >fstabxref.sha256sum.CHECKSUM 
    @tar -cjvf fstabxref.tar  fstabxref README* *CHECKSUM 

# end #

UBUNTU executables were not similar to Tumbleweed’s.

My personal view is that the libraries to printf, file-io, etc, are pulling in code that is not part of my executable, and which does not show in the debug output.

An observation.
Tumbleweed is the openSUSE’ rolling release that introduces bleeding edge features.
So, unless you’re running Fedora Rawhide, you’re almost certainly using very different compilers.

Recommend you compare compiler versions and their release notes if this makes much difference to you, otherwise I’d recommend you make a choice to either experiment with bleeding edge tools or stable, tested tools endorsed for general use… Don’t mix the two, compare and expect to get similar results.

Same thing with Ubuntu (I think their Developmental version is Zesty Zapus), unless you stick with stable vs. unstable, you need to understand what tools you are using.

TSU

Are you looking for something like this?: https://reproducible-builds.org/
Not many distros are working on that.

Hendrik

Good morning Hendrik (Montreal time)
All I am trying to do is remove code bloat.
Yesterday, Fedora25 upgraded the C compiler to 6.3. from the same 6.2 version used with Tumbleweed.
After a recompile there, the same output size was created.
I did compare object file sizes and they are the same for Tumbleweed and for Fedora.

So, what is pulled in to create the executable? Extra that should not be included?

I guess you want to examine the executable in detail. There are several tools for this, like:
ldd, objdump, readelf, …

I’m no expert in this kind of examining. So I can only recommend to read the manuals of these tools; and maybe search for more.

Hendrik

The gcc 6.3-1 compiler has been out for a while. Is there a target date for it’s arrival in Tumbleweed?

I just want to clarify one point

If I create an object file with Tumbleweed’s gcc 6.2 compiler, and that from another distribution, the object modules are identical in size.
a Diff on the modules just shows the difference as “date compiled”.

I ran with gcc -v to produce reams of logging info. It generates many many lines, I decided to just compile my programs on another system and bring them over to tumbleweed.