Commit 7eba885b authored by Henning Schmiedehausen's avatar Henning Schmiedehausen Committed by Ian Lance Taylor

cmd/dist: goc2c ignores GOROOT_FINAL

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.

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 and as a net result, the debugger now complains that
the script is outside its load path (it has the install location
configured).

See https://code.google.com/p/go/issues/detail?id=8524 for the full
description.

Fixes #8524.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/128230046
parent 40182102
...@@ -109,7 +109,7 @@ void mkzexperiment(char*, char*); ...@@ -109,7 +109,7 @@ void mkzexperiment(char*, char*);
void mkzdefaultcc(char*, char*); void mkzdefaultcc(char*, char*);
// goc2c.c // goc2c.c
void goc2c(char*, char*); void goc2c(char*, char*, char*);
// main.c // main.c
extern int vflag; extern int vflag;
......
...@@ -640,7 +640,7 @@ install(char *dir) ...@@ -640,7 +640,7 @@ install(char *dir)
{ {
char *name, *p, *elem, *prefix, *exe; char *name, *p, *elem, *prefix, *exe;
bool islib, ispkg, isgo, stale, ispackcmd; bool islib, ispkg, isgo, stale, ispackcmd;
Buf b, b1, path; Buf b, b1, path, final_path, final_name;
Vec compile, files, link, go, missing, clean, lib, extra; Vec compile, files, link, go, missing, clean, lib, extra;
Time ttarg, t; Time ttarg, t;
int i, j, k, n, doclean, targ; int i, j, k, n, doclean, targ;
...@@ -655,6 +655,8 @@ install(char *dir) ...@@ -655,6 +655,8 @@ install(char *dir)
binit(&b); binit(&b);
binit(&b1); binit(&b1);
binit(&path); binit(&path);
binit(&final_path);
binit(&final_name);
vinit(&compile); vinit(&compile);
vinit(&files); vinit(&files);
vinit(&link); vinit(&link);
...@@ -667,6 +669,7 @@ install(char *dir) ...@@ -667,6 +669,7 @@ install(char *dir)
// path = full path to dir. // path = full path to dir.
bpathf(&path, "%s/src/%s", goroot, dir); bpathf(&path, "%s/src/%s", goroot, dir);
bpathf(&final_path, "%s/src/%s", goroot_final, dir);
name = lastelem(dir); name = lastelem(dir);
// For misc/prof, copy into the tool directory and we're done. // For misc/prof, copy into the tool directory and we're done.
...@@ -939,9 +942,10 @@ install(char *dir) ...@@ -939,9 +942,10 @@ install(char *dir)
continue; continue;
// b = path/zp but with _goos_goarch.c instead of .goc // b = path/zp but with _goos_goarch.c instead of .goc
bprintf(&b, "%s%sz%s", bstr(&path), slash, lastelem(p)); bprintf(&b, "%s%sz%s", bstr(&path), slash, lastelem(p));
bprintf(&final_name, "%s%s%s", bstr(&final_path), slash, lastelem(p));
b.len -= 4; b.len -= 4;
bwritef(&b, "_%s_%s.c", goos, goarch); bwritef(&b, "_%s_%s.c", goos, goarch);
goc2c(p, bstr(&b)); goc2c(p, bstr(&final_name), bstr(&b));
vadd(&files, bstr(&b)); vadd(&files, bstr(&b));
} }
vuniq(&files); vuniq(&files);
......
...@@ -66,6 +66,7 @@ static int gcc; ...@@ -66,6 +66,7 @@ static int gcc;
/* File and line number */ /* File and line number */
static const char *file; static const char *file;
static const char *final_file;
static unsigned int lineno; static unsigned int lineno;
/* List of names and types. */ /* List of names and types. */
...@@ -474,7 +475,7 @@ read_func_header(char **name, struct params **params, int *paramwid, struct para ...@@ -474,7 +475,7 @@ read_func_header(char **name, struct params **params, int *paramwid, struct para
if (lastline == lineno-1) if (lastline == lineno-1)
bwritef(output, "\n"); bwritef(output, "\n");
else else
bwritef(output, "\n#line %d \"%s\"\n", lineno, file); bwritef(output, "\n#line %d \"%s\"\n", lineno, final_file);
lastline = lineno; lastline = lineno;
} }
bwritef(output, "%s ", token); bwritef(output, "%s ", token);
...@@ -658,7 +659,7 @@ write_func_header(char *package, char *name, ...@@ -658,7 +659,7 @@ write_func_header(char *package, char *name,
write_gcc_func_header(package, name, params, rets); write_gcc_func_header(package, name, params, rets);
else else
write_6g_func_header(package, name, params, paramwid, rets); write_6g_func_header(package, name, params, paramwid, rets);
bwritef(output, "#line %d \"%s\"\n", lineno, file); bwritef(output, "#line %d \"%s\"\n", lineno, final_file);
} }
/* Write out a function trailer. */ /* Write out a function trailer. */
...@@ -772,7 +773,7 @@ process_file(void) ...@@ -772,7 +773,7 @@ process_file(void)
} }
void void
goc2c(char *goc, char *c) goc2c(char *goc, char *goc_final, char *c)
{ {
int i; int i;
Buf in, out; Buf in, out;
...@@ -781,6 +782,7 @@ goc2c(char *goc, char *c) ...@@ -781,6 +782,7 @@ goc2c(char *goc, char *c)
binit(&out); binit(&out);
file = goc; file = goc;
final_file = goc_final;
readfile(&in, goc); readfile(&in, goc);
// TODO: set gcc=1 when using gcc // TODO: set gcc=1 when using gcc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment