What does the GCC error message, Error: unsupported for `mov', mean?
You are attempting to compile 32-bit assembly code on a 64-bit machine. The inline assembly you list compiles to:
movl -24(%rbp), %ebx
movl %rsi, %ecx <--- error here
movl -28(%rbp), %edx
movl $103, %eax
int $128
movl %eax, %r12d
As you can see, you're attempting to store a 64-bit register in a 32-bit register, which is illegal. More importantly, this isn't the 64-bit ABI system call protocol either.
Try compiling with -m32
to force 32-bit ABI.
unsupported instruction 'mov' in inline asm moving control register to uint32_t
The syntax is correct, but the error is more than likely because you're compiling for a 64-bit target, in which case the mov
needs to be 64 bits. Just change faulting_address
to a uint64_t
and it will compile.
Alternatively, if you want it to be 32 bits, you'll need to use -m32
or other similar option to compile for a 32-bit target.
Error in simple g++ inline assembler
Your assembly code is not valid. Please carefully read on Extended Asm. Here's another good overview.
Here is a CPUID example code from here:
static inline void cpuid(int code, uint32_t* a, uint32_t* d)
{
asm volatile ( "cpuid" : "=a"(*a), "=d"(*d) : "0"(code) : "ebx", "ecx" );
}
Note the format:
- first
:
followed by output operands:: "=a"(*a), "=d"(*d)
;"=a"
iseax
and"=b
isebx
- second
:
followed by input operands:: "0"(code)
;"0"
means thatcode
should occupy the same location as output operand0
(eax
in this case) - third
:
followed by clobbered registers list:: "ebx", "ecx"
Assembly error when compiling with GCC
I think the following code will compile ("gcc" can compile .s and .S files and link them with C library by default but "as" do the same and don't link code with C library)
as :
.section .text
.global _start
_start:
mov $4,%eax
mov $1,%ebx
mov $message,%ecx
mov msglength,%edx
int $0x80
mov $1, %eax
mov $0, %ebx
int $0x80
.section .data
message: .ascii "Hello world!"
msglength: .word 12
gcc:
.section .text
.global main
main:
mov $4,%eax
mov $1,%ebx
mov $message,%ecx
mov msglength,%edx
int $0x80
mov $1, %eax
mov $0, %ebx
int $0x80
.section .data
message: .ascii "Hello world!"
msglength: .word 12
warnings while trying to compile old linux kernel with gcc 12.1.0
To compile older version of kernel I needed older compiler ("Linux kernel sources are in general not forward-compatible with new compilers"). In my case the kernel version was 5.16.0 and I could compile it with gcc 11. If you have gcc 11 specific warnings then try gcc 10 and so on.
Except CC flags, I also needed set to HOSTCC flags to use gcc-11 compiler:
make HOSTCC=gcc-11 CC=gcc-11
What is this GCC error on Linux, and how do I solve it? gcc: internal compiler error: Illegal instruction (program as)
Got it! I uninstalled gcc, installed gcc-4.7, and ... nothing.
I cleared out the end of gcc-4.6 and re-ran sudo apt-get install gcc-4.7
and ... nothing.
I updated binutils and ... it worked!
So, as
didn't appear to be affected by updating GCC, but updating it more directly did it for me.
(It was from 2.22-7.1 to 2.22-8, if that helps anyone.)
Related Topics
Linux Find Out Hyper-Threaded Core Id
How to Trace Per-File Io Operations in Linux
How to Get Eclipse Swt Browser Component Running on Ubuntu 11.04 (Natty Narwhal) with Webkit
"Cd" Does Not Work in Shell Script
Extract List of File Names in a Zip Archive When 'Unzip -L'
How to Read the Second-To-Last Line in a File Using Bash
Adding Users to Sudoers Through Shell Script
Pass Private Key Password to Openvpn Command Directly in Ubuntu 10.10
How to Compile Linux Kernel with Something Other Than Gcc
How to Remove Warning About Storing Unencrypted Password After Committing File in Svn
Can't Run Uwsgi as Root, "Bind(): Permission Denied"
Creating a Raw Printer Queue in Cups (Host) and Adding Them Through Cups (Client)
Changing the PHPmyadmin Default Url
Running R Scripts or Commands with Interpretor in Unix for Unix-Layman