gas

internal relocation not fixed up

十年热恋 提交于 2019-12-05 13:36:18
问题 i recently started assembler programming for arm cores. My first little demos, only with the .text section, ran without any problems. As a logical extension i wanted to structure the assembler code into the usual sections: .text, .data, .bss . So i wrote the following simple program: .globl _start .section .text _start: b main b . b . b . b . b . b . b . main: ldr r0, x nop .section .data x: .word 0xf0f0f0f0 .end But /opt/arm/bin/arm-as -ggdb -mcpu=arm7tdmi demo.s -o demo.o exits with the

How many byes is each instruction compiled to in x86 assembly?

£可爱£侵袭症+ 提交于 2019-12-05 05:43:24
0x004012d0 <main+0>: push %ebp 0x004012d1 <main+1>: mov %esp,%ebp 0x004012d3 <main+3>: sub $0x28,%esp If the address is not available , can we calculate it ourselves? I mean we only have this: push %ebp mov %esp,%ebp sub $0x28,%esp amount of bytes is difference of addresses between adjacent instructions: 0x004012d0 <main+0>: push %ebp ;1 byte 0x004012d1 <main+1>: mov %esp,%ebp ;2 bytes 0x004012d3 <main+3>: sub $0x28,%esp if you have only text then go here: http://www.swansontec.com/sintel.html and here: http://faydoc.tripod.com/cpu/conventions.htm and calculate for each instruction, prefix and

1b and 1f in GNU assembly

左心房为你撑大大i 提交于 2019-12-04 10:48:29
问题 I am analyzing a linux exception code. By the way I can't understand gnu assembly syntax. svc_preempt: mov r8, lr 1: bl preempt_schedule_irq @ irq en/disable is done inside ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS tst r0, #_TIF_NEED_RESCHED moveq pc, r8 @ go again b 1b In this code, I can see "b 1b", but I can't find "1b" label anywhere. And, #ifdef CONFIG_NEON adr r6, .LCneon_thumb_opcodes b 2f #endif call_fpe: #ifdef CONFIG_NEON adr r6, .LCneon_arm_opcodes 2: ldr r7, [r6], #4 @

How do I debug jonesforth with GDB?

不打扰是莪最后的温柔 提交于 2019-12-04 05:34:48
问题 jonesforth is typically started as follows: cat jonesforth.f - | ./jonesforth What's a good way to debug jonesforth ? 回答1: On Ubuntu? If you're on Ubuntu, allow gdb to attach to running processes: echo 0 > /proc/sys/kernel/yama/ptrace_scope If you'd like that setting to remain across reboots: vim /etc/sysctl.d/10-ptrace.conf Update Makefile Add the g flag to your jonesforth Makefile recipe: jonesforth: jonesforth.S gcc -g -m32 -nostdlib -static $(BUILD_ID_NONE) -o $@ $< Starting gdb Then,

Defining “variables” in assembly language

六眼飞鱼酱① 提交于 2019-12-04 04:42:06
问题 I underdstand that this is extremely stupid quiestion, but I can't figure an answer for some time How do I correctly declare and define "variables" in GAS AT&T assembly language? For example, I want buffer for 5 bytes, two 1-byte variables (initially with 0 value), 2-byte variable with 0 and 2-byte variable with 10. This code doesn't work correctly, at least debugger says (on the first line of the program, after these declarations, just nop instruction) that b and c are big numbers instead of

Position independent addressing in GNU assembler with Intel syntax

若如初见. 提交于 2019-12-04 04:18:58
问题 On x86-64, how do I load an address from the .data section in a position independent manner (PIC and PIE compatible) when using the GNU assembler with intel syntax . For example, using AT&T syntax, you can do this: leaq mystring(%rip), %rdi Is there an equivalent for Intel syntax? I can't seem to find the answer using search engines... I am actually using the noprefix version of intel syntax, in case that makes a difference. Thanks 回答1: An easy way to answer this is to assemble the

How come _exit(0) (exiting by syscall) prevents me from receiving any stdout content?

六月ゝ 毕业季﹏ 提交于 2019-12-04 03:31:55
问题 I have a Linux x86-32 GAS assembly program terminating like this: movl $1, %eax movl $0, %ebx # argument for _exit int $0x80 When I exit like this, the program functions like normally, but if I try to read the stdout output, I get nothing (using i.e. less or wc). I tried compiling a minimal C program and comparing the strace outputs. The only difference I found was, that GCC made the C program ( int main() { printf("donkey\n"); } ) implicitely exit with exit_group(0) in the strace output. I

What does 0x4 do in “movl $0x2d, 0x4(%esp)”?

和自甴很熟 提交于 2019-12-04 02:16:44
I am looking into assembly code generated by GCC. But I don't understand: movl $0x2d, 0x4(%esp) In the second operand, what does 0x4 stands for? offset address? And what the use of register EAX? movl $0x2d, 0x4(%esp) means to take the current value of the stack pointer ( %esp ), add 4 ( 0x4 ) then store the long (32-bit) value 0x2d into that location. The eax register is one of the general purpose 32-bit registers. x86 architecture specifies the following 32-bit registers: eax Accumulator Register ebx Base Register ecx Counter Register edx Data Register esi Source Index edi Destination Index

internal relocation not fixed up

梦想的初衷 提交于 2019-12-04 00:19:08
i recently started assembler programming for arm cores. My first little demos, only with the .text section, ran without any problems. As a logical extension i wanted to structure the assembler code into the usual sections: .text, .data, .bss . So i wrote the following simple program: .globl _start .section .text _start: b main b . b . b . b . b . b . b . main: ldr r0, x nop .section .data x: .word 0xf0f0f0f0 .end But /opt/arm/bin/arm-as -ggdb -mcpu=arm7tdmi demo.s -o demo.o exits with the error prog.s: Assembler messages: prog.s:17: Error: internal_relocation (type: OFFSET_IMM) not fixed up

How to compile an assembly file to a raw binary (like DOS .com) format with GNU assembler (as)? [duplicate]

你。 提交于 2019-12-03 15:30:49
This question already has an answer here: How to generate plain binaries like nasm -f bin with the GNU GAS assembler? 2 answers I want to compile this source code in Windows (It just an example): start: NOP NOP When I compile it with NASM or FASM, output file length is 2 bytes. But when I compile it with GNU assembler (as) the output file length is 292 bytes! How to compile an assembly file to a raw binary (like DOS .com) format with GNU assembler (as)? Why I do this? I want to write my own simple OS, I write my codes with C (without using any C standard libraries even stdio.h or math.h) and