Is there a way not to optimize out "static const" at -Os?

David Kang dkang@isi.edu
Thu Oct 22 20:58:00 GMT 2015


 What a magic word it is!
It works!!
Thanks a lot!!!

 David

----- Original Message -----
> From: "Jonathan Wakely" <jwakely.gcc@gmail.com>
> To: "David Kang" <dkang@isi.edu>
> Cc: "gcc-help" <gcc-help@gcc.gnu.org>
> Sent: Thursday, October 22, 2015 4:44:15 PM
> Subject: Re: Is there a way not to optimize out "static const" at -Os?
> On 22 October 2015 at 21:12, David Kang wrote:
> >
> >  Hi,
> > I want to let the gcc leave the following static const at the
> > optimization -Os.
> > The functions "A_exec0", "A_initialize" are static function.
> > I tried a few compiler options such as "-fkeep-static-consts".
> > But gcc optimizes it out at -Os.
> > My compiler is gcc-4.7.3.
> > "-fkeep-static-functions" doesn't seem to be supported by my
> > compiler.
> >
> > static const __attribute__((unused, section(".driver_table")))
> > driver_t driver = {
> >   .type = "A_driver",
> >   .initialize = A_initialize,
> >   .executors = {A_exec0 }
> > };
> >
> >  Any idea about how to keep the static const and keep the section
> >  ".driver_table"?
> 
> Did you try __attribute__((used)) ?

-- 
----------------------
Dr. Dong-In "David" Kang
Computer Scientist
USC/ISI



More information about the Gcc-help mailing list