golang disable compiler optimizations

2,699 views
Skip to first unread message

Sankar

unread,
Sep 30, 2012, 3:06:12 AM9/30/12
to golan...@googlegroups.com
Hi,

I have a few go programs which I want to execute without any compiler optimizations at all. How do I achieve this ?

I execute the programs using:

go run <filename>

I can't find any helpful parameter in the `go help build` page. Is it possible to disable the compiler optimizations at all ?

I am using the go binaries on a mac machine if it matters.

Please help.

Thanks.

Sankar

Sankar P

unread,
Sep 30, 2012, 3:10:15 AM9/30/12
to golan...@googlegroups.com
Okay. Found it myself. I just could not get the man pages of gc easily. So, for the benefit of anyone searching for this, the way is:

go run -gcflags -N <filename>

More arguments for gcflags can be found on: http://golang.org/cmd/gc/

Thanks.

Sankar


Sankar

--
 
 



--
Sankar P
http://psankar.blogspot.com

minux

unread,
Sep 30, 2012, 3:21:25 AM9/30/12
to Sankar P, golan...@googlegroups.com


On Sep 30, 2012 3:10 PM, "Sankar P" <sankar.c...@gmail.com> wrote:
>
> Okay. Found it myself. I just could not get the man pages of gc easily. So, for the benefit of anyone searching for this, the way is:
>
> go run -gcflags -N <filename>

you'd also need -l here to disable inlining.

go run -gcflags "-N -l" <filenames>

Johann Höchtl

unread,
Sep 30, 2012, 2:16:04 PM9/30/12
to golan...@googlegroups.com


Am Sonntag, 30. September 2012 09:10:22 UTC+2 schrieb Sankar:
Okay. Found it myself. I just could not get the man pages of gc easily. So, for the benefit of anyone searching for this, the way is:

go run -gcflags -N <filename>

More arguments for gcflags can be found on: http://golang.org/cmd/gc/

And the documentation on debugging is lacking this info as well. It's issue 3363

minux

unread,
Oct 1, 2012, 5:19:04 AM10/1/12
to Johann Höchtl, golan...@googlegroups.com

On Mon, Oct 1, 2012 at 2:16 AM, Johann Höchtl <johann....@gmail.com> wrote:
Am Sonntag, 30. September 2012 09:10:22 UTC+2 schrieb Sankar:
Okay. Found it myself. I just could not get the man pages of gc easily. So, for the benefit of anyone searching for this, the way is:

go run -gcflags -N <filename>

More arguments for gcflags can be found on: http://golang.org/cmd/gc/

And the documentation on debugging is lacking this info as well. It's issue 3363
I think golang.org/doc/gdb contains such info:
The code generated by the gc compiler includes inlining of function invocations and registerization of variables. These optimizations can sometimes make debugging with gdb harder. To disable them when debugging, pass the flags -gcflags "-N -l" to the go command used to build the code being debugged.
Reply all
Reply to author
Forward
0 new messages