简体   繁体   English

X64组件:由信号SIGBUS终止(地址未对准错误)

[英]X64 assembly: terminated by signal SIGBUS (Misaligned address error)

I am writing a simple x64 program which calls a C program to print a string. 我正在编写一个简单的x64程序,该程序调用C程序来打印字符串。 I am using Mac OS X 我正在使用Mac OS X

X64: X64:

.data

hello_world: .asciz "hello world!\n"

.globl _print_string
.globl _main

_main:

    pushq %rbp
    movq %rsp, %rbp
    leaq hello_world(%rip), %rdi
    callq _print_string

    movq %rbp, %rsp
    popq %rbp

C program: C程序:

#include <stdio.h>

void 
print_string(char *str) 
{
    printf("%s\n", str);
}

But why am i getting './output' terminated by signal SIGBUS (Misaligned address error) . 但是,为什么我要通过信号SIGBUS终止“ ./output”(地址未对准错误) Can anyone please explain to me? 有人可以向我解释吗?

The first line of your .s file switches to the data segment, and never switches back. .s文件的第一行切换到数据段,再也不会切换回该数据段。 This leaves the main function in the data segment, which is not executable. 这会将main功能留在数据段中,该段不可执行。

Switch back to the text segment using .text before you start writing any code. 开始编写任何代码之前,请使用.text切换回文本段。 (Or switch to the data segment and define your string constant after main .) (或切换到数据段并在main之后定义您的字符串常量。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM