Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
615 views
in Technique[技术] by (71.8m points)

c - Is there a gcc flag to initialise local variable storage?

The IBM AIX xlc compiler offers a flag that generates code to initialise local variable storage:

      initauto=<hh>
                  Initialialize automatic storage to <hh>. <hh> is a
                  hexadecimal value.  This generates extra code and
                  should only be used for error determination.

I think the MSVC compiler does something similar for debug builds, but my memory may be hazy on this point.

Is there an equivalent option for GCC?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

OK, Best answer I can offer.

http://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html says "no," by omission. There's no documentation of anything to inject stack-wiping code into the output.

As near as I could guess, the only way this could work, is to inject some memset-like code (perhaps as simple as a few mov operations, but nonetheless) into the beginning of each embedded lexical frame in which an automatic variable is created. As near as I can tell -- and I am far from an expert on the internals of GCC, but -- there seems to be nothing documented that would do so.

In further following this, the PDF gccint.pdf of GCC Internals (http://gcc.gnu.org/onlinedocs/gccint.pdf) on page 361 defines that the GCC name for the frame pointer adjustment call step on entry to a function is prologue. (I don't really know/understand whether this applies to other lexical scopes within a function, however.) Since that should occur in a Machine Definition (md) file, any such option would seem to have to be defined for a CPU architecture. I poked at their online ViewCVS at http://gcc.gnu.org/viewcvs/trunk/gcc/config/i386/ and found (at least one) copy of prologue around line 11,893 of i386.md, which after playing search-for-the-function-expansion a few hops, doesn't seem to have anything to emit conditional code like that.

But this under-GCC's-hood stuff is kinda neat...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...