Optimasation和seg错误 [英] Optimasation and seg faults

查看:87
本文介绍了Optimasation和seg错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



很多次我观察到一些功能正常的程序没有优化或者调试选项的
似乎无法正常工作

optimasation处于或处于较高水平。偶尔会导致

段违规错误。


代码的哪一部分'' s / constructs最有可能造成这种问题?
这类问题?如果从您的经验中获得任何

提示,请分享。


~

Hi,
Many times I have observed that some program which functions properly
without optimisation or with debug option dosn''t seem to work when
optimasation is on or at a higer level.And occasionally it results in a
segment violation error.

Which part of the code''s/constructs are the most likely things to cause
this kind of issues ? If from your experience you have gained any
hints,please share.

~

推荐答案

grid写道:
grid wrote:
很多时候我观察到一些功能正常的程序没有优化或者没有调试选项似乎无法正常工作<优化级别处于或处于较高级别。偶尔会导致段违规错误。

代码的/构造的哪一部分是最可能发生的事情。导致这类问题?如果从您的经验中获得了任何提示,请分享。
Many times I have observed that some program which functions properly
without optimisation or with debug option dosn''t seem to work when
optimasation is on or at a higer level.And occasionally it results in a
segment violation error.

Which part of the code''s/constructs are the most likely things to cause
this kind of issues ? If from your experience you have gained any
hints,please share.




您是否有这样一个程序的(小)例子?


我会启用额外的警告,看看编译器是否抱怨。


例如gcc -O1 -Wall -Wextra



Do you have a (small) example of such a program?

I would enable extra warnings, and see if the compiler complains.

e.g. gcc -O1 -Wall -Wextra


#代码'/构造的哪一部分是最可能引起的事情

#this那种问题?如果根据您的经验,您已获得任何

#提示,请分享。


任何您忽略语言定义并获得
尽管......到目前为止仍然有效。稳定编译器中的优化器很少会突破;他们所做的是将你的程序重写成一个新的程序,根据语言定义相当于原来的



例如,假设你''我们知道你可以释放一个块然后

获取内容直到下一个malloc。这违反了界面;

优化者可能会觉得通过在您认为安全的参考前面移动malloc

来获得更好的代码。


有很多情况,例如不正确的反应,陈旧的价值,

被覆盖等等。


-

SM Ryan http://www.rawbw.com/~wyrmwif/

我不知道你刚刚说了什么。

我得到了很多。
# Which part of the code''s/constructs are the most likely things to cause
# this kind of issues ? If from your experience you have gained any
# hints,please share.

Any place you''ve ignored the language definition and gotten by with
"it works so far despite..." Optimisers in stable compilers rarely
break; what they do is rewrite your program into a new one that
according to the language definition is equivalent to the original.

For example, suppose you''ve learned you can free a block and still
get the contents until the next malloc. That violates the interface;
an optimiser might feel it can get better code by moving the malloc
forward, in front of the reference you thought safe.

There are many cases, like improper aliassing, stale values that
get overwritten, etc.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
I have no idea what you just said.
I get that alot.





grid写道:


grid wrote:

很多次我观察到一些功能正常的程序没有优化或者带有调试选项dosn'当
optimasation开启或处于较高水平时似乎工作。偶尔会导致
段违规错误。

代码的哪一部分/构造是最容易引起这种问题的事情吗?如果从您的经验中获得了任何提示,请分享。

Hi,
Many times I have observed that some program which functions properly
without optimisation or with debug option dosn''t seem to work when
optimasation is on or at a higer level.And occasionally it results in a
segment violation error.

Which part of the code''s/constructs are the most likely things to cause
this kind of issues ? If from your experience you have gained any
hints,please share.

~




IME,这总是归结为糟糕指针和/或内存管理。

大多数情况是由于解除引用一个单位指针;

一些是由于缓冲区溢出或其他一些内存可能导致的/>
或者可能不会破坏一些重要的东西,具体取决于项目如何安排在内存中,这取决于调试模式或优化

设置。



IME, this always comes down to bad pointer and/or memory management.
Most of those cases are due to dereferencing an unitialized pointer;
some are due to buffer overruns or some other memory stompage that may
or may not clobber something important depending on how items are
arranged in memory, which depends on debug mode or optimization
settings.


这篇关于Optimasation和seg错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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