【问题标题】:Segmentation Fault when compiling in Red hat but working fine with ubuntu在 Red hat 中编译但在 ubuntu 上工作正常时出现分段错误
【发布时间】:2011-09-27 05:59:36
【问题描述】:

这是我正在执行的代码。它使用 NASM 2.08 在 ubuntu 上提供所需的输出,但在使用运行 NASM 0.98.22 的 Red Hat 7.3 编译时会出现分段错误 有人可以告诉我如何确保它在 red hat 上也能正常运行。

section .data

section .text
    global _start
_start:

xor eax,eax
cdq
push eax
push long 0x68732f2f
push long 0x6e69622f
mov ebx,esp
push eax
push eax
mov ecx,esp
mov al,0xb
push eax
int 0x80

【问题讨论】:

  • 一个平台是 64 位,另一个平台是 32 位吗?您是否尝试过在调试器(例如 gdb)下运行?
  • 是的。我的 ubuntu 是 64 位的,而红帽是 32 位的,这会是个问题吗?我该如何解决?
  • 请添加您用于构建可执行文件的命令行
  • $nasm -f elf test3.s $ld -m elf_i386 -s -o test3 test3.o

标签: linux x86 intel nasm redhat


【解决方案1】:

您的代码是 32 位的,因此在构建它时,您需要确保构建的是 32 位可执行文件。这将在您的 32 位操作系统上默认发生,但您可能需要像 -m32 这样的开关才能在 64 位操作系统上实现此目的。

【讨论】:

  • 我将其构建为 $nasm -f elf test3.s $ld -m elf_i386 -s -o test3 test3.o
  • 红帽是 32 位操作系统,但在红帽操作系统上仍然会出现分段错误,但在 64 位 ubuntu 上运行良好
  • OK - 在 gdb 下运行它:gdb test3.o 然后run 看看它在哪一行崩溃
猜你喜欢
  • 2011-12-21
  • 1970-01-01
  • 1970-01-01
  • 2021-04-20
  • 1970-01-01
  • 2019-12-31
  • 2016-04-28
  • 1970-01-01
  • 2021-07-10
相关资源
最近更新 更多