x86-64

Why is tailcall optimization not performed for types of class MEMORY?

南笙酒味 提交于 2021-02-07 05:20:24
问题 I'm trying to understand the implication of System V AMD64 - ABI for returning by value from a function. For the following data type struct Vec3{ double x, y, z; }; the type Vec3 is of class MEMORY and thus the following is specified by the ABI concerning "Returning of Values": If the type has class MEMORY, then the caller provides space for the return value and passes the address of this storage in %rdi as if it were the first argument to the function. In effect, this address becomes a

Re-export Shared Library Symbols from Other Library (OS X / POSIX)

会有一股神秘感。 提交于 2021-02-05 20:33:13
问题 My question is fairly OS X on x86-64 specific but a universal solution that works on other POSIX OSes is even more appreciated. Given a list of symbol names of some shared library (called original library in the following) and I want my shared library to re-export these symbols. Re-export as in if someone tries to resolve the symbol against my library I either provide my version of this symbol or (if my library doesn't have this symbol) forward to the original library's symbol. I don't know

Re-export Shared Library Symbols from Other Library (OS X / POSIX)

人走茶凉 提交于 2021-02-05 20:32:15
问题 My question is fairly OS X on x86-64 specific but a universal solution that works on other POSIX OSes is even more appreciated. Given a list of symbol names of some shared library (called original library in the following) and I want my shared library to re-export these symbols. Re-export as in if someone tries to resolve the symbol against my library I either provide my version of this symbol or (if my library doesn't have this symbol) forward to the original library's symbol. I don't know

Moving a value of a lesser size into a register

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-05 11:38:22
问题 I have stored a one-byte value of 8 and I'd like to move that into the rax register. I'm currently doing this with movzx to zero-extend the byte: .globl main main: push %rbp mov %rsp, %rbp movb $8, -1(%rbp) movzx -1(%rbp), %rax <-- here ... How does the movzx instruction 'know' that the value at -1(%rbp) is only one byte long? From here is says, if I'm reading it properly, that it can work on both a byte and a word , but how would it know? For example, if I added a two-byte value at -2(%rbp)

Calling the C-function _printf from NASM causes a Segmentation Fault

北城余情 提交于 2021-02-05 11:35:31
问题 I've been trying to learn 64-bit assembly on both Mac-OS and Windows using NASM. My code is extern _printf section .data msg db "Hello World!", 10, 0 section .text global _main _main: mov rax, 0 mov rdi, msg call _printf mov rax, 0x2000001 mov rdi, 0 syscall and I compile it with nasm -f macho64 -o main.o main.asm gcc -o main main.o While trying to call _printf , I got the error Segmentation fault: 11 When I remove the call to _printf , my code runs fine. Why does the call to _printf cause a

Why do my results different following along the tiny asm example?

荒凉一梦 提交于 2021-02-05 09:15:30
问题 I'm reading this page https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html This is one of the example ; tiny.asm BITS 32 GLOBAL _start SECTION .text _start: mov eax, 1 mov ebx, 42 int 0x80 Here we go: $ nasm -f elf tiny.asm $ gcc -Wall -s -nostdlib tiny.o $ ./a.out ; echo $? 42 Ta-da! And the size? $ wc -c a.out 372 a.out However I don't get the same results. I tried nasm -f elf64 and then tried -m32 on gcc (then again on clang). No matter what I try I can not get it to be the tiny

Why do my results different following along the tiny asm example?

梦想的初衷 提交于 2021-02-05 09:15:06
问题 I'm reading this page https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html This is one of the example ; tiny.asm BITS 32 GLOBAL _start SECTION .text _start: mov eax, 1 mov ebx, 42 int 0x80 Here we go: $ nasm -f elf tiny.asm $ gcc -Wall -s -nostdlib tiny.o $ ./a.out ; echo $? 42 Ta-da! And the size? $ wc -c a.out 372 a.out However I don't get the same results. I tried nasm -f elf64 and then tried -m32 on gcc (then again on clang). No matter what I try I can not get it to be the tiny

What does it mean that “registers are preserved across function calls”?

自闭症网瘾萝莉.ら 提交于 2021-02-05 09:03:38
问题 From this question, What registers are preserved through a linux x86-64 function call, it says that the following registers are saved across function calls: r12, r13, r14, r15, rbx, rsp, rbp So, I went ahead and did a test with the following: .globl _start _start: mov $5, %r12 mov $5, %r13 mov $5, %r14 mov $5, %r15 call get_array_size mov $60, %eax syscall get_array_size: mov $0, %r12 mov $0, %r13 mov $0, %r14 mov $0, %r15 ret And, I was thinking that after the call get_array_size that my

Matching the intel codes to disassembly output

試著忘記壹切 提交于 2021-02-05 08:18:52
问题 I'm starting to use the Intel reference page to look up and learn about the op codes (instead of asking everything on SO). I'd like to make sure that my understanding is OK and ask a few questions on the output between a basic asm program and the intel instruction codes. Here is the program I have to compare various mov instructions into the rax -ish register (is there a better way to say "rax" and its 32- 16- and 8- bit components?): .globl _start _start: movq $1, %rax # move immediate into

Matching the intel codes to disassembly output

大兔子大兔子 提交于 2021-02-05 08:18:49
问题 I'm starting to use the Intel reference page to look up and learn about the op codes (instead of asking everything on SO). I'd like to make sure that my understanding is OK and ask a few questions on the output between a basic asm program and the intel instruction codes. Here is the program I have to compare various mov instructions into the rax -ish register (is there a better way to say "rax" and its 32- 16- and 8- bit components?): .globl _start _start: movq $1, %rax # move immediate into