by henning@schmiedehausen.org:
When building golang, the environment variable GOROOT_FINAL can be set to indicate a
different installation location from the build location. This works fine, except that
the goc2c build step embeds line numbers in the resulting c source files that refer to
the build location, no the install location:
// auto generated by go tool dist
// goos=linux goarch=amd64
#include "runtime.h"
#include "type.h"
#include "../../cmd/ld/textflag.h"
#define M0 (sizeof(uintptr)==4 ? 2860486313UL : 33054211828000289ULL)
#define M1 (sizeof(uintptr)==4 ? 3267000013UL : 23344194077549503ULL)
#line 13 "/home/hschmiedehausen/rpmbuild/BUILD/go/src/pkg/runtime/alg.goc"
This is the start of zalg_linux_amd64.c The path
"/home/hschmiedehausen/rpmbuild/BUILD/go" is the build location of the tree,
not the install location.
This would not be a big deal, except that in turn the linker uses the location of
runtime/string.goc to embed the gdb script in the resulting binary:
readelf -p41 ~/code/docker/bundles/1.1.3-dev/dynbinary/docker
String dump of section '.debug_gdb_scripts':
[ 1] /home/hschmiedehausen/rpmbuild/BUILD/go/src/pkg/runtime/runtime-gdb.py
and as a net result, the debugger now complains that the script is outside its load path
(it has the install location configured).
With the attached patch and GOROOT_FINAL set to the install location, the generated
sources look like this:
// auto generated by go tool dist
// goos=linux goarch=amd64
#include "runtime.h"
#include "type.h"
#include "../../cmd/ld/textflag.h"
#define M0 (sizeof(uintptr)==4 ? 2860486313UL : 33054211828000289ULL)
#define M1 (sizeof(uintptr)==4 ? 3267000013UL : 23344194077549503ULL)
#line 13 "/usr/lib/golang/src/pkg/runtime/alg.goc"
...
So the #line references use the correct installation path.
And the resulting binaries contain the correct script:
readelf -p41 ~/code/docker/bundles/1.1.3-dev/dynbinary/docker
String dump of section '.debug_gdb_scripts':
[ 1] /usr/lib/golang/src/pkg/runtime/runtime-gdb.py
and the debugger is happy.
Run "go version" and compare against
http://golang.org/doc/devel/release.html If a newer version of Go exists,
install it and retry what you did to reproduce the problem.
What does 'go version' print?
go version go1.3 linux/amd64
What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.
1. Build the golang from source with a different install location from the build
location (GOROOT != GOROOT_FINAL)
2. look at the output of e.g. go/src/pkg/zalg_*.c
3. verify that the #line statements contain the build, not the install location.
What happened?
Build a binary (I used docker). Use the readelf program (on linux) to dump the
.debug_gdb_scripts section. It contains the build location for the script, not the
install location.
What should have happened instead?
The generated source files should contain the install location. The resulting
.debug_gdb_scripts section should contain the install location.
Please provide any additional information below.
Repeat the steps with the attached path. Now the information is correct. And I can debug
with my RPM installed golang on Fedora. ;-)
Attachments:
- go-1.3-goc2c.patch (2126 bytes)
by henning@schmiedehausen.org:
Attachments: