Page 1 of 1

GCC giving `invalid instruction suffix for `push'`

Posted: Wed Apr 08, 2015 1:45 pm
by nv
Last night I was trying to setup my i686-elf-gcc cross compiler. After spending like an hour trying to figure out what was wrong with my current installation (I had the binaries from the debian repository, which I had assumed would work but seemed to be broken for me) and eventually decided to compile it myself. When I was finally done, I tried compiling something and it worked just fine. However, after closing out of that shell and opening a new one it no longer worked properly and kept giving a variety of different errors. I figured out that I forgot to export some of my environment variables in my zshrc, but after fixing that (I think) it still seems broken. Here are the relevant files/errors:

Makefile:

Code: Select all

CC = /home/nv/opt/cross/bin/i686-elf-gcc
AS = nasm
AFLAGS = -f elf32
CFLAGS = -c -std=gnu99 -ffreestanding -O -Wall -w -g -I ../../include
LD = /home/nv/opt/cross/bin/i686-elf-gcc
LDFLAGS = -T linker.ld -ffreestanding -O2 -nostdlib -gcc

TARGET = bin/infinity.bin

OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c) $(shell find ./src -name "*.c")) $(patsubst %.asm, %.o, $(wildcard *.asm) $(shell find ./src -name "*.asm"))

all: $(TARGET)


$(TARGET): $(OBJECTS)
        $(LD) -r -o $@  $^

%.o: %.c
        $(CC) $(CFLAGS) $^ -o $@
%.o: %.asm
        $(AS) $(AFLAGS) $^ -o $@
clean:
        rm $(TARGET) $(OBJECTS)
src/hello.c:

Code: Select all

#include <infinity/kernel.h>

int mod_init()
{
        printk(KERN_INFO "Hello, infinity kernel!\n");
        return 0;
}

int mod_uninit()
{
        printk(KERN_INFO "Goodbye infinity kernel :(\n");
        return 0;
}
error:

Code: Select all

/tmp/ccdUfcT0.s: Assembler messages:
/tmp/ccdUfcT0.s:18: Error: invalid instruction suffix for `push'
/tmp/ccdUfcT0.s:44: Error: invalid instruction suffix for `push'
makefile:19: recipe for target 'src/hello.o' failed
make: *** [src/hello.o] Error 1
This is using the code from here, by the way (with some modifications to makefiles and other parts of the code unrelated to this), and I was able to compile the kernel as of last night... I'm now unable to compile both modules and the kernel but for simplicity I am just posting the test module: https://github.com/GruntTheDivine/infin ... ules/hello

Thanks very much, nv

Re: GCC giving `invalid instruction suffix for `push'`

Posted: Wed Apr 08, 2015 2:14 pm
by iansjack
Can we assume that you have also built the appropriate binutils?

That error often occurs when you try to assemble 32-bit code with a 64-bit assembler.

Re: GCC giving `invalid instruction suffix for `push'`

Posted: Wed Apr 08, 2015 2:33 pm
by nv
iansjack wrote:Can we assume that you have also built the appropriate binutils?

That error often occurs when you try to assemble 32-bit code with a 64-bit assembler.
No, I didn't do that. I assumed I didn't have to since I had the old binutils from the debian package and the first time I tried compiling the ISO it worked fine. I just tried compiling it with the guide on the wiki and got this error:

Code: Select all

make[1]: Entering directory '/home/nv/git/infinity/binutils-2.9.1/libiberty'
test -z "" || \
  gcc -c -g -O2 -I. -I./../include   strerror.c -o pic/strerror.o
gcc -c -g -O2 -I. -I./../include  strerror.c
strerror.c:460:12: error: static declaration of ‘sys_nerr’ follows non-static declaration
 static int sys_nerr;
            ^
In file included from /usr/include/stdio.h:853:0,
                 from strerror.c:19:
/usr/include/x86_64-linux-gnu/bits/sys_errlist.h:26:12: note: previous declaration of ‘sys_nerr’ was here
 extern int sys_nerr;
            ^
strerror.c:461:21: error: conflicting types for ‘sys_errlist’
 static const char **sys_errlist;
                     ^
In file included from /usr/include/stdio.h:853:0,
                 from strerror.c:19:
/usr/include/x86_64-linux-gnu/bits/sys_errlist.h:27:26: note: previous declaration of ‘sys_errlist’ was here
 extern const char *const sys_errlist[];
                          ^
make[1]: *** [strerror.o] Error 1
Makefile:158: recipe for target 'strerror.o' failed
make[1]: Leaving directory '/home/nv/git/infinity/binutils-2.9.1/libiberty'
make: *** [all-libiberty] Error 2
Makefile:1084: recipe for target 'all-libiberty' failed
I did have to use i686-pc-linux-gnu as my host even though I am running an x86_64 kernel. Otherwise it would return

Code: Select all

Invalid configuration `x86_64-unknown-linux-gnu': machine `x86_64-unknown' not recognized

Re: GCC giving `invalid instruction suffix for `push'`

Posted: Wed Apr 08, 2015 2:39 pm
by iansjack
Is your old binutils (presumably a 32-bit binutils?) installed in the same place as your cross-compiler?

I'm still pretty sure that you are mixing 32-bit assembly code with a 64-bit assembler.

Re: GCC giving `invalid instruction suffix for `push'`

Posted: Wed Apr 08, 2015 2:51 pm
by nv
I'm honestly not even sure what I was using for the binutils before. I am assuming they were the ones included in cross-gcc-dev but I really have no clue. I do have 64-bit binutils on the system. Any clue how I can fix the errors during compilation?

Re: GCC giving `invalid instruction suffix for `push'`

Posted: Wed Apr 08, 2015 2:53 pm
by iansjack
nv wrote:Any clue how I can fix the errors during compilation?
I'd have another go at building binutils. I can't help but think that you must have done something wrong as it is normally a very straightforward procedure. You did use a separate build directory, didn't you, rather than building in the source directory?

Edit: It looks as if your problem with binutils may have been that you were using a very old version. Which versions of binutils and gcc did you try to build?

Re: GCC giving `invalid instruction suffix for `push'`

Posted: Wed Apr 08, 2015 3:02 pm
by nv
I tried building binutils-2.9.1 and gcc-4.9.2. GCC built correctly.

Re: GCC giving `invalid instruction suffix for `push'`

Posted: Wed Apr 08, 2015 3:25 pm
by nv
nv wrote:I tried building binutils-2.9.1 and gcc-4.9.2. GCC built correctly.
****, I'm stupid. That is an ancient version of binutils. I don't know why I thought that was the most recent... gonna try building a modern version now.

Re: GCC giving `invalid instruction suffix for `push'`

Posted: Wed Apr 08, 2015 3:30 pm
by iansjack
nv wrote:
nv wrote:I tried building binutils-2.9.1 and gcc-4.9.2. GCC built correctly.
****, I'm stupid. That is an ancient version of binutils. I don't know why I thought that was the most recent... gonna try building a modern version now.
That really is old! Try 2.24 or 2.25.

Re: GCC giving `invalid instruction suffix for `push'`

Posted: Wed Apr 08, 2015 3:42 pm
by nv
Yay, it seemed to work. Testing the ISO now. Thanks so much

Re: GCC giving `invalid instruction suffix for `push'`

Posted: Wed Apr 08, 2015 11:58 pm
by Candy
nv wrote:That is an ancient version of binutils. I don't know why I thought that was the most recent...
I usually think of it as Windows User Syndrome - where people assume that 1.9 will be followed by 2.0.