how to delete source file path informatin in panic‘s stack trace

982 views
Skip to first unread message

flhs...@gmail.com

unread,
Nov 22, 2013, 12:11:42 AM11/22/13
to golan...@googlegroups.com
I used  -ldflags "-s -w“  to compile program.  but filepath still showed up.

like this:

panic: test

goroutine 1 [running]:
runtime.panic(0x5378a0, 0x134a6670)
        C:/data/gosrc/go/src/pkg/runtime/panic.c:266 +0xa6
main.makeDB(0xc8741e00, 0xe, 0x0, 0x6544c0, 0xcc353380, ...)
        C:/data/hg-repo/src/go/sf2db/main.go:58 +0x403
main.main()
        C:/data/hg-repo/src/go/sf2db/main.go:25 +0xd9

goroutine 3 [syscall]:
runtime.goexit()
        C:/data/gosrc/go/src/pkg/runtime/proc.c:1394


How can I delete the source filepath info from the exe file.

System:windows7 64 bit
go version: compiled from go source 2013-11-20

Dave Cheney

unread,
Nov 22, 2013, 12:31:53 AM11/22/13
to flhs...@gmail.com, golang-nuts
This is currently not possible. The filename information stored in the
Go binary cannot current be stripped safely.
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

flhs...@gmail.com

unread,
Nov 22, 2013, 1:06:23 AM11/22/13
to golan...@googlegroups.com, flhs...@gmail.com
but, if I use the release version go, like go 1.1.2,
the filename information can deleted by -ldflags "-s -w“ 
what is the different between  release version and dev version go.
how can I fix it?

flhs...@gmail.com

unread,
Nov 22, 2013, 1:07:31 AM11/22/13
to golan...@googlegroups.com, flhs...@gmail.com
but, if I use the release version go, like go 1.1.2,
the filename information can deleted by -ldflags "-s -w“ 
what is the different between  release version and dev version go.
how can I fix it?

On Friday, November 22, 2013 1:31:53 PM UTC+8, Dave Cheney wrote:

Dave Cheney

unread,
Nov 22, 2013, 1:10:52 AM11/22/13
to flhs...@gmail.com, golang-nuts
I believe ldflags -s -w was found to produce broken executables during
the 1.2 development cycle and now those flags have no effect.

minux

unread,
Nov 22, 2013, 1:50:14 AM11/22/13
to Dave Cheney, flhs...@gmail.com, golang-nuts
On Fri, Nov 22, 2013 at 1:10 AM, Dave Cheney <da...@cheney.net> wrote:
I believe ldflags -s -w was found to produce broken executables during
the 1.2 development cycle and now those flags have no effect.
ldflags -s is fixed for Go 1.2 (see https://codereview.appspot.com/13751045).

ldflags -w isn't touched for Go 1.2, so it will continue to work (remove DWARF
debugging info)

But due to the fact that runtime now needs the ability to walk stack frames,
ldflags -s won't be as effective for Go 1.2 as it's for Go 1.1 (we don't drop
pclntab anymore, because it's required by the runtime, and the filename info
is contained in this table).

Perhaps we can address this problem in Go 1.3.

flhs...@gmail.com

unread,
Nov 22, 2013, 3:38:47 AM11/22/13
to golan...@googlegroups.com, Dave Cheney, flhs...@gmail.com
seems my only option is waiting.....
thank you very much

Dave Cheney

unread,
Nov 22, 2013, 3:41:09 AM11/22/13
to flhs...@gmail.com, golang-nuts
I am not aware of any open issue or plans to (re)implement this feature.

If you need this I recommend raising an issue, golang.org/issue.

flhs...@gmail.com

unread,
Nov 22, 2013, 3:44:29 AM11/22/13
to golan...@googlegroups.com, flhs...@gmail.com
 you're right, I should  raising an issue.

flhs...@gmail.com

unread,
Nov 22, 2013, 7:16:19 AM11/22/13
to golan...@googlegroups.com, flhs...@gmail.com

flhs...@gmail.com

unread,
Nov 22, 2013, 7:16:51 AM11/22/13
to golan...@googlegroups.com, flhs...@gmail.com

Yandong Zhang

unread,
Apr 30, 2021, 12:25:37 PMApr 30
to golang-nuts

Hello Gents,

It seems that this is still a quite annoying issue. The ldflags -s -w did not work at all for this purpose.
Would anyone recommend a way to remove or hide the file path resulted from the panic?

Thank you!

Ian Lance Taylor

unread,
Apr 30, 2021, 12:45:58 PMApr 30
to Yandong Zhang, golang-nuts
On Fri, Apr 30, 2021 at 9:25 AM Yandong Zhang <zydsc...@gmail.com> wrote:
>
> It seems that this is still a quite annoying issue. The ldflags -s -w did not work at all for this purpose.
> Would anyone recommend a way to remove or hide the file path resulted from the panic?

See the "go build" -trimpath option.

Ian
Reply all
Reply to author
Forward
0 new messages