引用静态对象 - 在 ARM 进程上触发对齐陷阱
我有一堂课:
class A {
public:
static A& instance();
...
void setValue(int val){ _value = val; }
private:
int _value;
}
A& A::instance(){
static A _Instance;
return _Instance;
}
我正在 ARM 处理器上运行它。我遇到的问题是,当我从特定类(例如 B 类)调用 instance() 方法时,应用程序会触发内核中的对齐陷阱。如果我从其他地方调用instance(),我不会遇到对齐陷阱。
对齐陷阱:不处理 [<0001b588>] 处的指令 e28fc609
我可以看到如果我将指针强制转换为未对齐的值会如何发生,但我只是引用一个静态对象。人们会假设访问将被正确对齐。
请注意,该类已被大大简化。它包含很多成员变量和方法(不是我的设计!)。
有人对我可能出错的地方或者去哪里有什么建议吗?
I have a class:
class A {
public:
static A& instance();
...
void setValue(int val){ _value = val; }
private:
int _value;
}
A& A::instance(){
static A _Instance;
return _Instance;
}
I am running this on an ARM processor. The issue I am encountering is that the application is triggering an alignment trap in the kernel when I call the instance() method from a particular class (say class B). If I call instance() from anywhere else, I do not encounter the alignment trap.
Alignment trap: not handling instruction e28fc609 at [<0001b588>]
I can see how this would happen if I were casting pointers to mis-aligned values, but I am simply referencing a static object. One would assume that the access would be correctly aligned.
Note the class is grossly simplified. It contains a lot of member variables and methods (not my design!).
Does anyone have any suggestions on where I may be going wrong, or where to look?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢大家的意见。事实证明,这个问题的根本原因是分段错误。反汇编表明对齐陷阱指向故障信号处理程序子例程。我正在调查为什么会发生这种情况,但我最初提出的问题已不再相关。
Thanks for the input guys. It turns out the root cause of this problem was a segmentation fault. The disassembly showed that the alignment trap pointed to the fault signal handler subroutine. I'm looking into why this happened now, but the question I originally asked is no longer relevant.