x86-64

gdb behaves differently for symbols in the .bss, vs. symbols in .data

杀马特。学长 韩版系。学妹 提交于 2020-02-15 08:33:31
问题 I recently started learning assembly language for the Intel x86-64 architecture using YASM. While solving one of the tasks suggested in a book (by Ray Seyfarth) I came to following problem: When I place some characters into a buffer in the .bss section, I still see an empty string while debugging it in gdb. Placing characters into a buffer in the .data section shows up as expected in gdb. segment .bss result resb 75 buf resw 100 usage resq 1 segment .data str_test db 0, 0, 0, 0 segment .text

【Hardware】i386、x86和x64的故事

牧云@^-^@ 提交于 2020-02-09 09:38:50
(1)x86的由来 x86架构 首度出现在1978年推出的Intel 8086中央处理器,它是从Intel 8008处理器中发展而来的,而8008则是发展自Intel 4004的。在8086之后,Intel又推出了包括80186、80286、80386以及80486。 在设计上,这些后续的处理器使用的指令集都是在 8086 的基础上添加新支持的指令进行改进的,因此可以说都是 向下兼容(backward compatibility) 的,即能在8086上运行的程序在80486上也一定能运行。 向下兼容(Downward Compatibility) ,又称作 向后兼容(Backward Compatibility) ,指在 一个程序或者类库更新到较新的版本后,用旧的版本程序创建的文档或系统仍能被正常操作或使用 ,或在旧版本的类库的基础上开发的程序仍能正常编译运行的情况。例如较高档的计算机或较高版本的软件平台可以运行较为低档计算机或早期的软件平台所开发的程序 由于都是以86结尾(不过8088也是x86),所以把这一系列的指令集,称之为 x86指令集(架构) 。准确的来讲, x86 这一术语并不是指的某一个(具体CPU使用的)具体的指令集,而是在8086(的指令集)基础上发展而来的所有指令集的泛称 。 x86与CPU的位数无关,包括16位、32位、64位的CPU。 实际上

Why is default operand size 32 bits in 64 mode?

烂漫一生 提交于 2020-02-06 07:55:36
问题 I am reading Intel doc, vol. 1 and There is a chapter of 3.6.1 Operand Size and Address Size in 64-Bit Mode . There are three prefixes REX.W , operand-size 66 and address-size 67 prefix. And there is mentioned that operand are defaulted to be 32 bit in size. And is only possible to change it with REX.W instruction prefix (after other prefixes) to make it 64 bits long. I do not know why so, why cannot I used the full 64 bit space for example for int operand? Does it have something to do with

Most efficient way of writing a single producer/single consumer queue

感情迁移 提交于 2020-02-05 04:37:04
问题 What is the most efficient way of writing a producer/consumer queue where one thread is the producer and the other is a consumer. In one paper, the author said that it requires one atomic operation to insert an element into his queue, but he didn't explain how. Also his queue is a circular queue and the consumer waits if queue is empty while the producer waits if queue is full. How could he have implemented such a queue. By atomic operation, did he mean some kind of mutex or just an atomic

Why are segfaults called faults (and not aborts) if they are not recoverable?

微笑、不失礼 提交于 2020-02-04 01:20:13
问题 My following understanding of the terminology is this 1) An interrupt is "a notification" that is initiated by the hardware to call the OS to run its handlers 2) A trap is "a notification" that is initiated by the software to call the OS to run its handlers 3) A fault is an exception that is raised by the processor if an error has occurred but it is recoverable 4) An abort is an exception that is raised by the processor if an error has occurred but it is non-recoverable Why do we call it a

How does this program know the exact location where this string is stored?

断了今生、忘了曾经 提交于 2020-02-03 04:28:07
问题 I have disassembled a C program with Radare2. Inside this program there are many calls to scanf like the following: 0x000011fe 488d4594 lea rax, [var_6ch] 0x00001202 4889c6 mov rsi, rax 0x00001205 488d3df35603. lea rdi, [0x000368ff] ; "%d" ; const char *format 0x0000120c b800000000 mov eax, 0 0x00001211 e86afeffff call sym.imp.__isoc99_scanf ; int scanf(const char *format) 0x00001216 8b4594 mov eax, dword [var_6ch] 0x00001219 83f801 cmp eax, 1 ; rsi ; "ELF\x02\x01\x01" 0x0000121c 740a je

Linux X86-64 assembly and printf

不打扰是莪最后的温柔 提交于 2020-02-01 05:04:25
问题 I am reading some linux assembly manuals and found idea about using printf() function. I need it to output register values for debugging reasons in binary form to terminal, but now I am tried simply to test that function with text. I am stuck, because of segfault when I am using pushq instead of pushl. How can I change this program to output strings and binary form of registers? .data input_prompt: .string "Hello, world!" printf_format: .string "%5d " printf_newline: .string "\n" size: .long

Understanding gcc -S output

陌路散爱 提交于 2020-01-30 14:35:08
问题 I did gcc -S on the very complex program below on x86_64: int main() { int x = 3; x = 5; return 0; } And what I got was: .file "main.c" .text .globl main .type main, @function main: .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl $3, -4(%rbp) movl $5, -4(%rbp) movl $0, %eax leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE0: .size main, .-main .ident "GCC: (GNU) 4.4.7 20120313 (Red Hat 4.4.7-3)" .section .note.GNU-stack,"",

Is garbage allowed in high bits of parameter and return value registers in x86-64 SysV ABI?

爷,独闯天下 提交于 2020-01-27 04:26:19
问题 The x86-64 SysV ABI specifies, among other things, how function parameters are passed in registers (first argument in rdi , then rsi and so on), and how integer return values are passed back (in rax and then rdx for really big values). What I can't find, however, is what the high bits of parameter or return value registers should be when passing types smaller than 64-bits. For example, for the following function: void foo(unsigned x, unsigned y); ... x will be passed in rdi and y in rsi , but

Is garbage allowed in high bits of parameter and return value registers in x86-64 SysV ABI?

那年仲夏 提交于 2020-01-27 04:26:07
问题 The x86-64 SysV ABI specifies, among other things, how function parameters are passed in registers (first argument in rdi , then rsi and so on), and how integer return values are passed back (in rax and then rdx for really big values). What I can't find, however, is what the high bits of parameter or return value registers should be when passing types smaller than 64-bits. For example, for the following function: void foo(unsigned x, unsigned y); ... x will be passed in rdi and y in rsi , but