x86-64

x86-64 ELF initial stack layout when calling glibc

人走茶凉 提交于 2019-12-11 07:06:29
问题 Basically, I read through parts of http://www.nasm.us/links/unix64abi and at page 29, it shows the initial process stack of a C program. My question is: I'm trying to interface with glibc from x86-64 nasm and based on what the above shows, argc should be at rsp. So the following code should print argc: [SECTION .data] PrintStr: db "You just entered %d arguments.", 10, 0 [SECTION .bss] [SECTION .text] extern printf global main main: mov rax, 0 ; Required for functions taking in variable no. of

How to compile a 64-bit dll written in C?

∥☆過路亽.° 提交于 2019-12-11 06:39:14
问题 I have a Java program which makes use of some native function calls to speed up video encoding. It requires a DLL, which I will write in C (I have just a test one right now). When I compile the DLL with cl /I "java-path/include" /"java-path/include/win32" -DL -ML Main.c -FeTest.dll it compiles, but I get a 32-bit DLL. After I did some research on the internet, I found out that I would need a 64-bit DLL instead. After more research, I have found this post which is the only one for C (even C++

Why do I get a zombie when I link assembly code without stdlib?

送分小仙女□ 提交于 2019-12-11 06:36:16
问题 I was experimenting with assembly code and the GTK+ 3 libraries when I discovered that my application turns into a zombie if I don't link the object file with gcc against the standard library. Here is my code for the stdlib -free application %include "gtk.inc" %include "glib.inc" global _start SECTION .data destroy db "destroy", 0 ; const gchar* strWindow db "Window", 0 ; const gchar* SECTION .bss window resq 1 ; GtkWindow * SECTION .text _start: ; gtk_init (&argc, &argv); xor rdi, rdi xor

Where do I starting to find the memory leak after porting from i386 to x86_64?

♀尐吖头ヾ 提交于 2019-12-11 06:29:25
问题 I successfully compiled and run Borealis under Fedora core 12 i386 Pentium dual core and g++ 4.1.1, Now I hope it can run under FC20 x86_64 i7 dual core. After modifying some codes( I think these modifications are nothing with its performation ) and installing several additional packages Borealis needs, I successfully compiled Borealis under FC20 x86_64 and it was able to run. But when running, I found that there was severe memory leakage , gnome-system-monitor displayed using memory changed

How to direct gas use a specified encoding form of instructions, for example, MOV?

£可爱£侵袭症+ 提交于 2019-12-11 06:28:37
问题 The MOV have the two form to move an imm to r64: | Opcode | Instruction | Op/En | 64-Bit Mode | Compat/Leg Mode | Description | | REX.W + B8+ rd | MOV r64, imm64 | E | Valid | N.E. | Move imm64 to r64. | | REX.W + C7 /0 | MOV r/m64,imm32 | F | Valid | N.E. | Move imm32 sign extended to 64-bits to r/m64. | In the example bellow, Line 6(Line 5,7 are not so important, we ignore it.) use the 2nd form. So the problem is, if we link the object file with '-Ttext=' to specify a address that can be

How to invoke a system call via sysenter in inline assembly?

和自甴很熟 提交于 2019-12-11 06:24:28
问题 How can we implement the system call using sysenter/syscall directly in x86 Linux? Can anybody provide help? It would be even better if you can also show the code for amd64 platform. I know in x86, we can use __asm__( " movl $1, %eax \n" " movl $0, %ebx \n" " call *%gs:0x10 \n" ); to route to sysenter indirectly. But how can we code using sysenter/syscall directly to issue a system call? I find some material http://damocles.blogbus.com/tag/sysenter/ . But still find it difficult to figure out

Strange gcc6.1 -O2 compiling behaviour

▼魔方 西西 提交于 2019-12-11 05:47:22
问题 I am compiling the same benchmark using gcc -O2 -march=native flags. However, Interesting thing is when I look at the objdump , it actually produce some instructions like vxorpd , etc, which I think should only appear when -ftree-vectorize is enabled (and -O2 should not enable this by default?) If I add -m32 flag to compile in 32 bit instruction, these packed instructions disappeared. Anyone met similar situations could give some explanations? Thanks. 回答1: XORPD is the classic SSE2

Modifying a character array, the modified part shows up backwards

 ̄綄美尐妖づ 提交于 2019-12-11 05:46:15
问题 I have just started learning assembly, and I am trying to modify a character array. This is my assembly code: .data data byte 'Five', 0 .code Asm proc lea rax, data mov dword ptr[rax], 'Four' ret Asm endp end And my C++ code: #include <stdio.h> #include <conio.h> // external function extern "C" char* Asm(); // main function int main() { printf(Asm()); _getch(); } When I comment out mov dword ptr[rax], 'Four' , the result is that the console prints: "Five" . But, with the above code

How to get length of long strings in x86 assembly to print on assertion

隐身守侯 提交于 2019-12-11 05:39:57
问题 I am trying to build an x86 program that reads a file into memory. It uses a few different syscalls, and messes with memory and such. There's a lot in there to figure out. To simplify debugging and figuring this out, I wanted to add assert statements which, if there's a mismatch, it prints out a nice error message. This is the first step in learning assembly so I can print the numbers and strings that get placed on different registers and such after operations. Then I can print them out and

Running x86-64 ASM on a x86-32 processor

狂风中的少年 提交于 2019-12-11 05:33:20
问题 I'm taking an assembly language course and it's taught targeting x86-64 platforms. My laptop is pretty antiquated and still running a 32 bit x86 processor, specifically an Intel Core Duo T2500. Is there a way to run a virtual machine that supports 64bit addressing on my machine? 回答1: QEMU should be able to emulate x86_64: Features 回答2: Bochs is another x86_64 emulator. But you should think of using an emulator since everything is emulated and it's too slow to run a full operating system.