无法使用.bss节内存 [英] Unable to use .bss section memory

查看:120
本文介绍了无法使用.bss节内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在.bss内存中存储文件描述符,用于基本的Linux程序,该程序可读取一个文件并写入另一个文件.我一直无法使它正常工作.

I'm trying to store a file descriptor in .bss memory for a basic Linux program that reads from one file and writes to another. I've been unable to get it to work.

该程序未返回错误,但无法正常运行.将文件描述符存储在堆栈中时,它可以正常工作.当我尝试在gdb中运行程序时,得到以下输出:During startup program exited normally.

The program does not return an error, but does not work correctly. It works correctly when storing the file descriptors on the stack. When I try to run the program in gdb, I get the following output: During startup program exited normally.

这是代码的简化版本:

.section .data

.equ SYS_EXIT,  1
.equ LINUX_SYSCALL, 0x80


.section .bss

.equ BUFFER_SIZE, 500
.equ DESCR_SIZE, 4
.lcomm BUFFER_DATA, BUFFER_SIZE
.lcomm BUFFER_IN_DESCR, DESCR_SIZE
.lcomm BUFFER_OUT_DESCR, DESCR_SIZE


.section .text


.globl _start
    _start:
    movl $7, BUFFER_IN_DESCR
    movl $SYS_EXIT, %eax
    movl $BUFFER_IN_DESCR, %ebx
    int $LINUX_SYSCALL

任何帮助,不胜感激!

如彼得在评论中所提到的,对问题进行了编辑,使其最小,完整和可验证.

Question edited to be Minimal, Complete, and Verifiable as mentioned by Peter in the comments.

推荐答案

进一步研究之后,问题出在彼得在评论中提到的不正确使用立即寻址.我仍然不确定为什么这完全阻止了我运行该程序,并且只能假定这是由某种操作系统内存保护引起的.

After working on this further, the problem was the incorrect use of immediate addressing mentioned by Peter in the comments. I'm still unsure why this prevented me from running the program at all, and can only assume that this was caused by some sort of OS memory protection.

这篇关于无法使用.bss节内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆