Arikania
Posts: 17
Joined: Tue Sep 11, 2018 6:44 am

GCC frustrations

Sat Aug 31, 2019 3:22 pm

Hi there,
I do a lot of assembly programming, and I prefer to use the GNU assembler for it. That works great.

But when I try to compile a C / C++ program, it never ever happens without errors. Even listings that should be working out of the box, never do, giving errors at run-time that are nowhere on internet to be retrieved. One program doesn't work because the log( ) function generates errors about libraries that don't exist, and now I have another that doesn't work. I have the feeling that it is totally mis-configured, but dpkg-reconfigure doesn't solve it, and neither did a complete re-installation.

I am getting pretty frustrated with it that, whenever I try to compile even the simplest of programs on my ARMv7-A, I spend days figuring out why it won't work.

I would like to know if I am the only one who has this?

The listing of gettype.c:

Code: Select all

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>


#define showsize(name, pos)		ShowSize(name, (char *) &S.pos)


struct stat S;


void ShowSize(const char *fieldname, char *fieldptr) {
  static char *currentpos = (char *) &S;


  printf("%s\t: %u\n", fieldname, fieldptr - currentpos);
  currentpos = fieldptr;
}


int main( ) {
  showsize("dev_t", st_dev);
  return 0;
}
compiled with the commands:

Code: Select all

gcc gettypes.c -Warch=armv7-a -Wfpu=vfp
ld gettype.out -o gettype
And the error that I get at run-time: Inconsistency detected by ld.so: dl-lookup.c: 971: _dl_setup_hash: Assertion `(bitmask_nwords & (bitmask_nwords - 1)) == 0' failed!.

The output of gcc -v

Code: Select all

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/6/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Raspbian 6.3.0-18+rpi1+deb9u1' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=arm-linux-gnueabihf- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --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-6-armhf/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-armhf --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-armhf --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --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 6.3.0 20170516 (Raspbian 6.3.0-18+rpi1+deb9u1) 

How do I get it configured right for my ARMv7-A?


Kindly,


A.

User avatar
PeterO
Posts: 5025
Joined: Sun Jul 22, 2012 4:14 pm

Re: GCC frustrations

Sat Aug 31, 2019 3:36 pm

Code: Select all

petero@HP-Pavilion-dv6-Notebook-PC:/tmp$ gcc -o types types.c 
petero@HP-Pavilion-dv6-Notebook-PC:/tmp$ ./types 
dev_t	: 0
petero@HP-Pavilion-dv6-Notebook-PC:/tmp$
Admittedly compiled and run on an x86 laptop, but compiled with gcc.

Not sure why you are trying to do a separate link stage, but I think your final "executable" will be missing some bits as a consequence.

Try doing it all in one step with gcc -o executable source-file
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Arikania
Posts: 17
Joined: Tue Sep 11, 2018 6:44 am

Re: GCC frustrations

Sat Aug 31, 2019 3:55 pm

EUREKA!! :D

Your swift reply (my gratitude implied included) cracked the case!

GCC doesn't return a library file, it returns the actual executable!

Never thought that Santa would ever be my knight in shiny armor! ;)


Love,


Arikania

User avatar
Paeryn
Posts: 2678
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: GCC frustrations

Sat Aug 31, 2019 4:16 pm

Slightly late reply, had to stop mid writing whilst I got off the bus.
Arikania wrote:
Sat Aug 31, 2019 3:22 pm
compiled with the commands:

Code: Select all

gcc gettypes.c -Warch=armv7-a -Wfpu=vfp
ld gettype.out -o gettype
And the error that I get at run-time: Inconsistency detected by ld.so: dl-lookup.c: 971: _dl_setup_hash: Assertion `(bitmask_nwords & (bitmask_nwords - 1)) == 0' failed!.
I would have thought gcc would have given an error as -Warch=armv7-a -Wfpu=vfp aren't valid warning options, both of those options are for the -m flag not -W.

Code: Select all

-march=armv7-a -mfpu=vfp
The gcc line will generate an executable as it is unless you tell it to stop at an earlier stage. I don't know where you are getting gettype.out from.
She who travels light — forgot something.

jahboater
Posts: 4690
Joined: Wed Feb 04, 2015 6:38 pm

Re: GCC frustrations

Wed Sep 11, 2019 10:35 am

Arikania wrote:
Sat Aug 31, 2019 3:22 pm
One program doesn't work because the log( ) function generates errors about libraries that don't exist,
For that, you need the math library which is included by adding -lm to the gcc command line.

gcc hello.c -o hello -lm

If you type:

Code: Select all

man log
it gives you all the details.
You will need to include math.h of course.
As for any C compiler.

Return to “C/C++”