why the binary generated by go test has no symbol table

157 views
Skip to first unread message

buaa...@gmail.com

unread,
Sep 7, 2020, 10:05:33 PM9/7/20
to golang-nuts
And only on Linux, there is no symbol section in test binary unless I generate it by go test -c

buaa...@gmail.com

unread,
Sep 7, 2020, 10:06:31 PM9/7/20
to golang-nuts
There is no ldflags provided, so why the symbol table is stripped

Ian Lance Taylor

unread,
Sep 8, 2020, 6:01:18 PM9/8/20
to buaa...@gmail.com, golang-nuts
On Mon, Sep 7, 2020 at 7:07 PM buaa...@gmail.com <buaa...@gmail.com> wrote:
>
> There is no ldflags provided, so why the symbol table is stripped

Because if you run "go test" without the -c option, the executable is
built, run, and then thrown away. There no reason to spend time
generating debugging information that nobody will ever use.

Which leads to the question: how did you notice? What is the real problem here?

Ian


> 在2020年9月8日星期二 UTC+8 上午10:05:33<buaa...@gmail.com> 写道:
>>
>> And only on Linux, there is no symbol section in test binary unless I generate it by go test -c
>
> --
> 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.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d8840e17-63c6-4f32-af1d-5d73d12dfbd4n%40googlegroups.com.

buaa...@gmail.com

unread,
Sep 8, 2020, 10:03:54 PM9/8/20
to golang-nuts
I wrote a tool to get binary file's symbol table during initialization, and do some special tests, but it fails on Linux, so I get the log like:

$ go test
2020/09/09 10:02:44 reading /tmp/go-build334351549/b001/xxx.test: no symbol section
2020/09/09 10:02:44 reading /tmp/go-build334351549/b001/xxx.test: no symbols

Ian Lance Taylor

unread,
Sep 8, 2020, 10:09:18 PM9/8/20
to buaa...@gmail.com, golang-nuts
On Tue, Sep 8, 2020 at 7:04 PM buaa...@gmail.com <buaa...@gmail.com> wrote:
>
> I wrote a tool to get binary file's symbol table during initialization, and do some special tests, but it fails on Linux, so I get the log like:
>
> $ go test
> 2020/09/09 10:02:44 reading /tmp/go-build334351549/b001/xxx.test: no symbol section
> 2020/09/09 10:02:44 reading /tmp/go-build334351549/b001/xxx.test: no symbols

One approach you can use is to have the test build a program using "go build".

Or you can run your tests using "go test -c".

Ian


> 在2020年9月9日星期三 UTC+8 上午6:01:18<Ian Lance Taylor> 写道:
>>
>> On Mon, Sep 7, 2020 at 7:07 PM buaa...@gmail.com <buaa...@gmail.com> wrote:
>> >
>> > There is no ldflags provided, so why the symbol table is stripped
>>
>> Because if you run "go test" without the -c option, the executable is
>> built, run, and then thrown away. There no reason to spend time
>> generating debugging information that nobody will ever use.
>>
>> Which leads to the question: how did you notice? What is the real problem here?
>>
>> Ian
>>
>>
>> > 在2020年9月8日星期二 UTC+8 上午10:05:33<buaa...@gmail.com> 写道:
>> >>
>> >> And only on Linux, there is no symbol section in test binary unless I generate it by go test -c
>> >
>> > --
>> > 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.
>> > To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d8840e17-63c6-4f32-af1d-5d73d12dfbd4n%40googlegroups.com.
>
> --
> 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.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/93fd8c75-6e2d-4449-8912-a86fc70dee06n%40googlegroups.com.

buaa...@gmail.com

unread,
Sep 9, 2020, 2:54:52 AM9/9/20
to golang-nuts
it seems  ldfags="-s=false" -gcflags="-l" can work
Reply all
Reply to author
Forward
0 new messages