gas

GAS: Explanation of .cfi_def_cfa_offset

时光毁灭记忆、已成空白 提交于 2019-11-29 19:51:52
I would like an explanation for the values used with the .cfi_def_cfa_offset directives in assembly generated by GCC. I know vaguely that the .cfi directives are involved in call frames and stack unwinding, but I would like a more detailed explanation of why, for example, the values 16 and 8 are used in the assembly outputted by GCC in compiling the following C program on my 64-bit Ubuntu machine. The C program: #include <stdio.h> int main(int argc, char** argv) { printf("%d", 0); return 0; } I invoked GCC on the source file test.c as follows: gcc -S -O3 test.c . I know that -O3 enables

Why does switching from AT&T to Intel syntax make this tutorial segfault using GAS?

為{幸葍}努か 提交于 2019-11-29 19:00:45
问题 I'm working through some of the tutorials on http://www.ibm.com/developerworks/linux/library/l-gas-nasm/index.html to familiarize myself with x86/x64. This tutorial code compiles and runs without a hiccup using the provided code, which uses AT&T syntax: .global main .text main: # This is called by C library's startup code mov $message, %rdi # First integer (or pointer) parameter in %edi call puts # puts("Hello, World") ret # Return to C library code message: .asciz "Hello, World" # asciz puts

How to link a C object file with a Assembly Language object file?

只谈情不闲聊 提交于 2019-11-29 18:19:36
问题 I am having trouble linking 2 object files one of which was generated from an Assembly Language Source File and another that was generated from a C Source file. C source code: //main2.c extern int strlength(char *); int main(){ char * test = "hello"; int num = strlength(test); return num; } Assembly source code: #strlength.s .include "Linux32.s" .section .text .globl strlength .type strlength, @function strlength: pushl %ebp movl %esp, %ebp movl $0, %ecx movl 8(%ebp), %edx read_next_byte:

Gas altmacro macro with a percent sign in a default parameter fails with “% operator needs absolute expression”

主宰稳场 提交于 2019-11-29 16:49:34
I want to create a macro like the following: .altmacro .macro assert_eq a, b=%eax LOCAL ok #... .endm To be used as: assert_eq $1 assert_eq $1, %eax I want .altmacro for LOCAL (I see the other possibility of using \@ , but I want LOCAL ). But when I try to compile this I get: Error: % operator needs absolute expression I am guessing that this problem is created by the fact that b=%eax is attempting to use another feature enabled by .altmacro : Expression results as strings , since without .altmacro I could write this without problem. If this is true, how do I escape that for my macro to work?

GCC not saving/restoring reserved registers on function calls

白昼怎懂夜的黑 提交于 2019-11-29 16:12:47
I have a scenario in GCC causing me problems. The behaviour I get is not the behaviour I expect. To summarise the situation, I am proposing several new instructions for x86-64 which are implemented in a hardware simulator. In order to test these instructions I am taking existing C source code and handcoding the new instructions using hexidecimal. Because these instructions interact with the existing x86-64 registers, I use the input/output/clobber lists to declare dependencies for GCC. What's happening is that if I call a function e.g. printf, the dependent registers aren't saved and restored.

Bootloader works in emulators but not on real hardware

主宰稳场 提交于 2019-11-29 12:30:56
I am writing a bootloader in assembly and it seems to work fine on qemu, bochs and virtualbox. However, it is not loading the kernel on real hardware (it seems). The bootloader starts off by writing a character to the video memory (for debugging), it then reads sector 2 off the drive and far jumps to the kernel. The kernel is then writing some characters to video memory. On a real machine, I see the character from the bootloader on the screen, and there it hangs (blinking caret). I have tried to set DS, ES, SI to zero, and I am also setting up a stack segment. I am reading sector 2 off of the

Generating assembly code from C# code?

人走茶凉 提交于 2019-11-29 10:39:56
Is there any way to generate assembly code from C# code? I know that it is possible with C code with GAS, but does anybody know if it's possible with C#? C# is normally compiled to the .NET bytecode (called CIL or MSIL ) and then JIT ("Just In Time") compiled to native code when the program is actually run. There exist ahead of time compilers for C# like Mono's AOT , so you could possibly compile a C# program through one of those and then disassemble it. The result is likely to be very difficult to follow. More likely, you may want to look at the bytecodes which are somewhat higher level than

When are GAS ELF the directives .type, .thumb, .size and .section needed?

二次信任 提交于 2019-11-28 22:53:48
问题 I'm working on an assembly program for an ARM Cortex-M3 based microcontroller (Thumb 2 instruction set), using GNU as. In some example code I find directives like .size , .section and .type which I understand are ELF directives. As an example: .section .text.Reset_Handler .weak Reset_Handler .type Reset_Handler, %function Reset_Handler: bl main b Infinite_Loop .size Reset_Handler, .-Reset_Handler The .type directive is said to set the type of a symbol - usually either to %object (meaning data

How to link a gas assembly program that uses the C standard library with ld without using gcc?

自作多情 提交于 2019-11-28 16:52:39
问题 As an exercise to learn more precisely how c programs work and what minimum level of content must exist for a program to be able to use libc, I've taken it upon myself to attempt to program primarily in x86 assembly using gas and ld. As a fun little challenge, I've successfully assembled and linked several programs linked to different self-made dynamic libraries, but I have failed to be able to code a program from scratch to use libc function calls without directly using gcc. I understand the

NASM Vs GAS (Practical differences)

戏子无情 提交于 2019-11-28 16:16:02
问题 I'm not trying to prompt an Intel vs AT&T war (moot point anyway, now that they both support Intel syntax) or ask which one is "better" per se, I just want to know the practical differences in choosing one or the other. Basically, when I was picking up some basic x86 assembly a few years back, I used NASM for no reason other than the book I was reading did too -- which put me firmly but involuntarily in the NASM camp. Since then, I've had very few causes to use assembly so I haven't had the